00001
00002 #include "PackScores.h"
00003 #include "moses/FF/StatefulFeatureFunction.h"
00004 #include "moses/FF/StatelessFeatureFunction.h"
00005 #include <boost/foreach.hpp>
00006 namespace Moses {
00007
00008 void
00009 PackScores(FeatureFunction const& ff, FVector const& S,
00010 std::map<std::string, xmlrpc_c::value>& M)
00011 {
00012 std::vector<xmlrpc_c::value> v;
00013 size_t N = ff.GetNumScoreComponents();
00014
00015 std::vector<xmlrpc_c::value> dense;
00016 dense.reserve(N);
00017 size_t o = ff.GetIndex();
00018 for (size_t i = 0; i < N; ++i)
00019 if (ff.IsTuneableComponent(i))
00020 dense.push_back(xmlrpc_c::value_double(S[o+i]));
00021 v.push_back(xmlrpc_c::value_array(dense));
00022
00023 std::map<std::string,xmlrpc_c::value> sparse;
00024 typedef FVector::FNVmap::const_iterator iter;
00025 for(iter m = S.cbegin(); m != S.cend(); ++m)
00026 sparse[m->first.name()] = xmlrpc_c::value_double(m->second);
00027 v.push_back(xmlrpc_c::value_struct(sparse));
00028 M[ff.GetScoreProducerDescription()] = xmlrpc_c::value_array(v);
00029 }
00030
00031 xmlrpc_c::value
00032 PackScores(ScoreComponentCollection const& S)
00033 {
00034 std::map<std::string, xmlrpc_c::value> M;
00035 typedef StatefulFeatureFunction SFFF;
00036 typedef StatelessFeatureFunction SLFF;
00037 BOOST_FOREACH(SFFF const* ff, SFFF::GetStatefulFeatureFunctions())
00038 if (ff->IsTuneable())
00039 PackScores(*ff, S.GetScoresVector(), M);
00040 BOOST_FOREACH(SLFF const* ff, SLFF::GetStatelessFeatureFunctions())
00041 if (ff->IsTuneable())
00042 PackScores(*ff, S.GetScoresVector(), M);
00043 return xmlrpc_c::value_struct(M);
00044 }
00045 }