Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Germann <Ulrich.Germann@gmail.com>2015-11-01 17:51:33 +0300
committerUlrich Germann <Ulrich.Germann@gmail.com>2015-11-01 17:53:16 +0300
commite9b1c6019ba6ebce3bb4e090a1a6877b1c3d0e18 (patch)
treef6ee040be30c0bb5593cc01176bf32eff432c29d /moses/server
parentff1977c29ecbca44f0420b4d22c7ebbc6335c197 (diff)
Improved reporting of nbest scores via server interface.
Diffstat (limited to 'moses/server')
-rw-r--r--moses/server/PackScores.cpp48
-rw-r--r--moses/server/PackScores.h16
-rw-r--r--moses/server/TranslationRequest.cpp3
3 files changed, 67 insertions, 0 deletions
diff --git a/moses/server/PackScores.cpp b/moses/server/PackScores.cpp
new file mode 100644
index 000000000..db5710132
--- /dev/null
+++ b/moses/server/PackScores.cpp
@@ -0,0 +1,48 @@
+// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
+#ifdef HAVE_XMLRPC_C
+#include "PackScores.h"
+#include "moses/FF/StatefulFeatureFunction.h"
+#include "moses/FF/StatelessFeatureFunction.h"
+#include <boost/foreach.hpp>
+namespace Moses {
+
+void
+PackScores(FeatureFunction const& ff, FVector const& S,
+ std::map<std::string, xmlrpc_c::value>& M)
+{
+ std::vector<xmlrpc_c::value> v;
+ size_t N = ff.GetNumScoreComponents();
+
+ std::vector<xmlrpc_c::value> dense;
+ dense.reserve(N);
+ size_t o = ff.GetIndex();
+ for (size_t i = 0; i < N; ++i)
+ if (ff.IsTuneableComponent(i))
+ dense.push_back(xmlrpc_c::value_double(S[o+i]));
+ v.push_back(xmlrpc_c::value_array(dense));
+
+ std::map<std::string,xmlrpc_c::value> sparse;
+ typedef FVector::FNVmap::const_iterator iter;
+ for(iter m = S.cbegin(); m != S.cend(); ++m)
+ sparse[m->first.name()] = xmlrpc_c::value_double(m->second);
+ v.push_back(xmlrpc_c::value_struct(sparse));
+ M[ff.GetScoreProducerDescription()] = xmlrpc_c::value_array(v);
+}
+
+xmlrpc_c::value
+PackScores(ScoreComponentCollection const& S)
+{
+ std::map<std::string, xmlrpc_c::value> M;
+ typedef StatefulFeatureFunction SFFF;
+ typedef StatelessFeatureFunction SLFF;
+ BOOST_FOREACH(SFFF const* ff, SFFF::GetStatefulFeatureFunctions())
+ if (ff->IsTuneable())
+ PackScores(*ff, S.GetScoresVector(), M);
+ BOOST_FOREACH(SLFF const* ff, SLFF::GetStatelessFeatureFunctions())
+ if (ff->IsTuneable())
+ PackScores(*ff, S.GetScoresVector(), M);
+ return xmlrpc_c::value_struct(M);
+}
+}
+#endif
+
diff --git a/moses/server/PackScores.h b/moses/server/PackScores.h
new file mode 100644
index 000000000..98c57059d
--- /dev/null
+++ b/moses/server/PackScores.h
@@ -0,0 +1,16 @@
+// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
+#ifdef HAVE_XMLRPC_C
+#pragma once
+#include <xmlrpc-c/base.hpp>
+#include "moses/FF/FeatureFunction.h"
+#include "moses/ScoreComponentCollection.h"
+
+namespace Moses {
+
+xmlrpc_c::value
+PackScores(ScoreComponentCollection const& S);
+
+}
+
+
+#endif
diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp
index 085d16622..5f7841ce0 100644
--- a/moses/server/TranslationRequest.cpp
+++ b/moses/server/TranslationRequest.cpp
@@ -1,4 +1,5 @@
#include "TranslationRequest.h"
+#include "PackScores.h"
#include "moses/ContextScope.h"
#include <boost/foreach.hpp>
#include "moses/Util.h"
@@ -188,6 +189,8 @@ outputNBest(const Manager& manager, map<string, xmlrpc_c::value>& retData)
bool with_labels = m_options.nbest.include_feature_labels;
path->GetScoreBreakdown()->OutputAllFeatureScores(buf, with_labels);
nBestXmlItem["fvals"] = xmlrpc_c::value_string(buf.str());
+
+ nBestXmlItem["scores"] = PackScores(*path->GetScoreBreakdown());
}
// weighted score