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:
authorEvgeny Matusov <ematusov@ebay.com>2015-11-17 17:06:48 +0300
committerEvgeny Matusov <ematusov@ebay.com>2015-11-17 17:06:48 +0300
commit66928f682f55cb6e6b105dd71a358354963e91d3 (patch)
tree7234581d0b07f2ba5742c223442ad0f6af39762a /moses/server
parent7c088c9a95ee6fdbd211f2b2ae9606ecf1ccba3c (diff)
second commit of moses server placeholder fix
Diffstat (limited to 'moses/server')
-rw-r--r--moses/server/TranslationRequest.cpp47
-rw-r--r--moses/server/TranslationRequest.h8
2 files changed, 15 insertions, 40 deletions
diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp
index f23b378f6..433e37a27 100644
--- a/moses/server/TranslationRequest.cpp
+++ b/moses/server/TranslationRequest.cpp
@@ -3,6 +3,8 @@
#include "moses/ContextScope.h"
#include <boost/foreach.hpp>
#include "moses/Util.h"
+#include "moses/Hypothesis.h"
+
namespace MosesServer
{
using namespace std;
@@ -11,8 +13,6 @@ using Moses::StaticData;
using Moses::Range;
using Moses::ChartHypothesis;
using Moses::Phrase;
-using Moses::Factor;
-using Moses::FactorType;
using Moses::Manager;
using Moses::SearchGraphNode;
using Moses::TrellisPathList;
@@ -175,33 +175,6 @@ insertGraphInfo(Manager& manager, map<string, xmlrpc_c::value>& retData)
// out << *phrase.GetFactor(i, 0) << " ";
// } else out << phrase;
// }
-
-void
-TranslationRequest::
-output_phrase(ostream& out, const Hypothesis* hypo) const
-{
- Phrase phrase = hypo->GetCurrTargetPhrase();
-
- if (!m_options.output.ReportAllFactors) {
- FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor();
- std::map<size_t, const Factor*> placeholders;
- if (placeholderFactor != NOT_FOUND) {
- // creates map of target position -> factor for placeholders
- placeholders = GetPlaceholders(*hypo, placeholderFactor);
- }
- for (size_t i = 0 ; i < phrase.GetSize(); ++i) {
- const Factor *factor = phrase.GetFactor(i, 0);
- if (placeholders.size()) {
- // do placeholders
- std::map<size_t, const Factor*>::const_iterator iter = placeholders.find(i);
- if (iter != placeholders.end()) {
- factor = iter->second;
- }
- }
- out << *factor << " ";
- }
- } else out << phrase;
-}
void
TranslationRequest::
@@ -222,7 +195,7 @@ outputNBest(const Manager& manager, map<string, xmlrpc_c::value>& retData)
vector<const Hypothesis *> const& E = path->GetEdges();
if (!E.size()) continue;
std::map<std::string, xmlrpc_c::value> nBestXmlItem;
- pack_hypothesis(E, "hyp", nBestXmlItem);
+ pack_hypothesis(manager, E, "hyp", nBestXmlItem);
if (m_withScoreBreakdown) {
// should the score breakdown be reported in a more structured manner?
ostringstream buf;
@@ -396,13 +369,15 @@ run_chart_decoder()
void
TranslationRequest::
-pack_hypothesis(vector<Hypothesis const* > const& edges, string const& key,
+pack_hypothesis(Moses::Manager& manager, vector<Hypothesis const* > const& edges, string const& key,
map<string, xmlrpc_c::value> & dest) const
{
// target string
ostringstream target;
- BOOST_REVERSE_FOREACH(Hypothesis const* e, edges)
- output_phrase(target, e->GetCurrTargetPhrase());
+ BOOST_REVERSE_FOREACH(Hypothesis const* e, edges)
+ manager.OutputSurface(target, *e, StaticData::Instance().GetOutputFactorOrder(),
+ options().output.ReportSegmentation, m_options.output.ReportAllFactors);
+// output_phrase(target, e->GetTargetPhrase());
XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl);
dest[key] = xmlrpc_c::value_string(target.str());
@@ -427,7 +402,7 @@ pack_hypothesis(vector<Hypothesis const* > const& edges, string const& key,
void
TranslationRequest::
-pack_hypothesis(Hypothesis const* h, string const& key,
+pack_hypothesis(Moses::Manager& manager, Hypothesis const* h, string const& key,
map<string, xmlrpc_c::value>& dest) const
{
using namespace std;
@@ -450,8 +425,8 @@ run_phrase_decoder()
manager.Decode();
-
- pack_hypothesis(manager.GetBestHypothesis(), "text", m_retData);
+
+ pack_hypothesis(manager, manager.GetBestHypothesis(), "text", m_retData);
if (m_session_id)
m_retData["session-id"] = xmlrpc_c::value_int(m_session_id);
diff --git a/moses/server/TranslationRequest.h b/moses/server/TranslationRequest.h
index 24adb7888..f3984d35a 100644
--- a/moses/server/TranslationRequest.h
+++ b/moses/server/TranslationRequest.h
@@ -58,17 +58,17 @@ TranslationRequest : public virtual Moses::TranslationTask
run_phrase_decoder();
void
- pack_hypothesis(std::vector<Moses::Hypothesis const* > const& edges,
+ pack_hypothesis(Moses::Manager& manager, std::vector<Moses::Hypothesis const* > const& edges,
std::string const& key,
std::map<std::string, xmlrpc_c::value> & dest) const;
void
- pack_hypothesis(Moses::Hypothesis const* h, std::string const& key,
+ pack_hypothesis(Moses::Manager& manager, Moses::Hypothesis const* h, std::string const& key,
std::map<std::string, xmlrpc_c::value> & dest) const;
- void
- output_phrase(std::ostream& out, const Moses::Hypothesis* hypo) const;
+// void
+// output_phrase(std::ostream& out, Moses::Phrase const& phrase) const;
void
add_phrase_aln_info(Moses::Hypothesis const& h,