diff options
author | Barry Haddow <barry.haddow@gmail.com> | 2012-04-13 20:27:48 +0400 |
---|---|---|
committer | Barry Haddow <barry.haddow@gmail.com> | 2012-04-13 20:27:48 +0400 |
commit | 02ddca96ed4f4fc65af2d4975d85b349febbd21c (patch) | |
tree | abddef292e893f6cbe787c79b0a13b6ed4982b9a /contrib | |
parent | 1a6e8dc6fd850e182aba67a03aa833aa7d65a9ba (diff) |
Add support for chart-based models to server
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/server/mosesserver.cpp | 79 |
1 files changed, 54 insertions, 25 deletions
diff --git a/contrib/server/mosesserver.cpp b/contrib/server/mosesserver.cpp index 2775a058f..0091ee2de 100644 --- a/contrib/server/mosesserver.cpp +++ b/contrib/server/mosesserver.cpp @@ -6,11 +6,13 @@ #include <xmlrpc-c/registry.hpp> #include <xmlrpc-c/server_abyss.hpp> +#include "ChartManager.h" #include "Hypothesis.h" #include "Manager.h" #include "StaticData.h" #include "PhraseDictionaryDynSuffixArray.h" #include "TranslationSystem.h" +#include "TreeInput.h" #include "LMList.h" #include "LM/ORLM.h" @@ -170,36 +172,48 @@ public: } const TranslationSystem& system = getTranslationSystem(params); - - Sentence sentence; - const vector<FactorType> &inputFactorOrder = - staticData.GetInputFactorOrder(); - stringstream in(source + "\n"); - sentence.Read(in,inputFactorOrder); - Manager manager(sentence,staticData.GetSearchAlgorithm(), &system); - manager.ProcessSentence(); - const Hypothesis* hypo = manager.GetBestHypothesis(); - - vector<xmlrpc_c::value> alignInfo; stringstream out, graphInfo, transCollOpts; - outputHypo(out,hypo,addAlignInfo,alignInfo,reportAllFactors); - map<string, xmlrpc_c::value> retData; + + SearchAlgorithm searchAlgorithm = staticData.GetSearchAlgorithm(); + if (searchAlgorithm == ChartDecoding) { + TreeInput tinput; + const vector<FactorType> &inputFactorOrder = + staticData.GetInputFactorOrder(); + stringstream in(source + "\n"); + tinput.Read(in,inputFactorOrder); + ChartManager manager(tinput, &system); + manager.ProcessSentence(); + const ChartHypothesis *hypo = manager.GetBestHypothesis(); + outputChartHypo(out,hypo); + } else { + Sentence sentence; + const vector<FactorType> &inputFactorOrder = + staticData.GetInputFactorOrder(); + stringstream in(source + "\n"); + sentence.Read(in,inputFactorOrder); + Manager manager(sentence,staticData.GetSearchAlgorithm(), &system); + manager.ProcessSentence(); + const Hypothesis* hypo = manager.GetBestHypothesis(); + + vector<xmlrpc_c::value> alignInfo; + outputHypo(out,hypo,addAlignInfo,alignInfo,reportAllFactors); + if (addAlignInfo) { + retData.insert(pair<string, xmlrpc_c::value>("align", xmlrpc_c::value_array(alignInfo))); + } + + if(addGraphInfo) { + insertGraphInfo(manager,retData); + (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(false); + } + if (addTopts) { + insertTranslationOptions(manager,retData); + } + } pair<string, xmlrpc_c::value> text("text", xmlrpc_c::value_string(out.str())); - cerr << "Output: " << out.str() << endl; - if (addAlignInfo) { - retData.insert(pair<string, xmlrpc_c::value>("align", xmlrpc_c::value_array(alignInfo))); - } retData.insert(text); - - if(addGraphInfo) { - insertGraphInfo(manager,retData); - (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(false); - } - if (addTopts) { - insertTranslationOptions(manager,retData); - } + cerr << "Output: " << out.str() << endl; *retvalP = xmlrpc_c::value_struct(retData); } @@ -230,6 +244,21 @@ public: } } + void outputChartHypo(ostream& out, const ChartHypothesis* hypo) { + Phrase outPhrase(20); + hypo->CreateOutputPhrase(outPhrase); + + // delete 1st & last + assert(outPhrase.GetSize() >= 2); + outPhrase.RemoveWord(0); + outPhrase.RemoveWord(outPhrase.GetSize() - 1); + for (size_t pos = 0 ; pos < outPhrase.GetSize() ; pos++) { + const Factor *factor = outPhrase.GetFactor(pos, 0); + out << *factor << " "; + } + + } + void insertGraphInfo(Manager& manager, map<string, xmlrpc_c::value>& retData) { vector<xmlrpc_c::value> searchGraphXml; vector<SearchGraphNode> searchGraph; |