diff options
Diffstat (limited to 'moses/server')
-rw-r--r-- | moses/server/Optimizer.cpp | 24 | ||||
-rw-r--r-- | moses/server/Optimizer.h | 4 | ||||
-rw-r--r-- | moses/server/TranslationRequest.cpp | 148 | ||||
-rw-r--r-- | moses/server/TranslationRequest.h | 72 | ||||
-rw-r--r-- | moses/server/Translator.cpp | 16 | ||||
-rw-r--r-- | moses/server/Translator.h | 6 | ||||
-rw-r--r-- | moses/server/Updater.cpp | 16 | ||||
-rw-r--r-- | moses/server/Updater.h | 8 |
8 files changed, 147 insertions, 147 deletions
diff --git a/moses/server/Optimizer.cpp b/moses/server/Optimizer.cpp index d7d5f939c..d28d7f085 100644 --- a/moses/server/Optimizer.cpp +++ b/moses/server/Optimizer.cpp @@ -18,47 +18,47 @@ namespace MosesServer void Optimizer:: execute(xmlrpc_c::paramList const& paramList, - xmlrpc_c::value * const retvalP) + xmlrpc_c::value * const retvalP) { #ifdef WITH_DLIB const params_t params = paramList.getStruct(0); params_t::const_iterator si; - if ((si = params.find("model_name")) == params.end()) + if ((si = params.find("model_name")) == params.end()) { string msg = "Missing name of model to be optimized"; msg += " (e.g. PhraseDictionaryMultiModelCounts0)"; throw xmlrpc_c::fault(msg, xmlrpc_c::fault::CODE_PARSE); } const string model_name = xmlrpc_c::value_string(si->second); - - if ((si = params.find("phrase_pairs")) == params.end()) + + if ((si = params.find("phrase_pairs")) == params.end()) { throw xmlrpc_c::fault("Missing list of phrase pairs", xmlrpc_c::fault::CODE_PARSE); } - + vector<pair<string, string> > phrase_pairs; - + xmlrpc_c::value_array pp_array = xmlrpc_c::value_array(si->second); vector<xmlrpc_c::value> ppValVec(pp_array.vectorValueValue()); - for (size_t i = 0; i < ppValVec.size(); ++i) + for (size_t i = 0; i < ppValVec.size(); ++i) { - xmlrpc_c::value_array pp_array + xmlrpc_c::value_array pp_array = xmlrpc_c::value_array(ppValVec[i]); vector<xmlrpc_c::value> pp(pp_array.vectorValueValue()); string L1 = xmlrpc_c::value_string(pp[0]); string L2 = xmlrpc_c::value_string(pp[1]); phrase_pairs.push_back(make_pair(L1,L2)); } - - // PhraseDictionaryMultiModel* pdmm + + // PhraseDictionaryMultiModel* pdmm // = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name); PhraseDictionaryMultiModel* pdmm = FindPhraseDictionary(model_name); vector<float> weight_vector = pdmm->MinimizePerplexity(phrase_pairs); - + vector<xmlrpc_c::value> weight_vector_ret; - for (size_t i=0;i < weight_vector.size();i++) + for (size_t i=0;i < weight_vector.size();i++) weight_vector_ret.push_back(xmlrpc_c::value_double(weight_vector[i])); *retvalP = xmlrpc_c::value_array(weight_vector_ret); diff --git a/moses/server/Optimizer.h b/moses/server/Optimizer.h index 5e2302d09..8911b089f 100644 --- a/moses/server/Optimizer.h +++ b/moses/server/Optimizer.h @@ -6,11 +6,11 @@ namespace MosesServer { - class + class Optimizer : public xmlrpc_c::method { public: - Optimizer(); + Optimizer(); void execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value * const retvalP); }; diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index aab8867b5..62e3031fa 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -4,9 +4,9 @@ namespace MosesServer { using namespace std; - using Moses::Hypothesis; - using Moses::StaticData; - using Moses::WordsRange; + using Moses::Hypothesis; + using Moses::StaticData; + using Moses::WordsRange; using Moses::ChartHypothesis; using Moses::Phrase; using Moses::Manager; @@ -23,8 +23,8 @@ namespace MosesServer boost::shared_ptr<TranslationRequest> TranslationRequest:: - create(xmlrpc_c::paramList const& paramList, - boost::condition_variable& cond, + create(xmlrpc_c::paramList const& paramList, + boost::condition_variable& cond, boost::mutex& mut) { boost::shared_ptr<TranslationRequest> ret; @@ -33,75 +33,75 @@ namespace MosesServer return ret; } - void + void TranslationRequest:: - Run() + Run() { parse_request(m_paramList.getStruct(0)); - + Moses::StaticData const& SD = Moses::StaticData::Instance(); - + //Make sure alternative paths are retained, if necessary - if (m_withGraphInfo || m_nbestSize>0) + if (m_withGraphInfo || m_nbestSize>0) // why on earth is this a global variable? Is this even thread-safe???? UG (const_cast<Moses::StaticData&>(SD)).SetOutputSearchGraph(true); - + std::stringstream out, graphInfo, transCollOpts; - - if (SD.IsSyntax()) + + if (SD.IsSyntax()) run_chart_decoder(); - else + else run_phrase_decoder(); - + XVERBOSE(1,"Output: " << out.str() << endl); { boost::lock_guard<boost::mutex> lock(m_mutex); m_done = true; } m_cond.notify_one(); - + } - + /// add phrase alignment information from a Hypothesis - void + void TranslationRequest:: add_phrase_aln_info(Hypothesis const& h, vector<xmlrpc_c::value>& aInfo) const { if (!m_withAlignInfo) return; WordsRange const& trg = h.GetCurrTargetWordsRange(); WordsRange const& src = h.GetCurrSourceWordsRange(); - + std::map<std::string, xmlrpc_c::value> pAlnInfo; pAlnInfo["tgt-start"] = xmlrpc_c::value_int(trg.GetStartPos()); pAlnInfo["src-start"] = xmlrpc_c::value_int(src.GetStartPos()); pAlnInfo["src-end"] = xmlrpc_c::value_int(src.GetEndPos()); aInfo.push_back(xmlrpc_c::value_struct(pAlnInfo)); } - - void + + void TranslationRequest:: - outputChartHypo(ostream& out, const ChartHypothesis* hypo) + outputChartHypo(ostream& out, const ChartHypothesis* hypo) { Phrase outPhrase(20); hypo->GetOutputPhrase(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++) + for (size_t pos = 0 ; pos < outPhrase.GetSize() ; pos++) out << *outPhrase.GetFactor(pos, 0) << " "; } - bool + bool TranslationRequest:: - compareSearchGraphNode(const Moses::SearchGraphNode& a, - const Moses::SearchGraphNode& b) + compareSearchGraphNode(const Moses::SearchGraphNode& a, + const Moses::SearchGraphNode& b) { return a.hypo->GetId() < b.hypo->GetId(); } - void + void TranslationRequest:: - insertGraphInfo(Manager& manager, map<string, xmlrpc_c::value>& retData) + insertGraphInfo(Manager& manager, map<string, xmlrpc_c::value>& retData) { using xmlrpc_c::value_int; using xmlrpc_c::value_double; @@ -119,13 +119,13 @@ namespace MosesServer const Hypothesis* hypo = n.hypo; x["hyp"] = value_int(hypo->GetId()); x["stack"] = value_int(hypo->GetWordsBitmap().GetNumWordsCovered()); - if (hypo->GetId() != 0) + if (hypo->GetId() != 0) { const Hypothesis *prevHypo = hypo->GetPrevHypo(); x["back"] = value_int(prevHypo->GetId()); x["score"] = value_double(hypo->GetScore()); x["transition"] = value_double(hypo->GetScore() - prevHypo->GetScore()); - if (n.recombinationHypo) + if (n.recombinationHypo) x["recombined"] = value_int(n.recombinationHypo->GetId()); x["cover-start"] = value_int(hypo->GetCurrSourceWordsRange().GetStartPos()); x["cover-end"] = value_int(hypo->GetCurrSourceWordsRange().GetEndPos()); @@ -136,26 +136,26 @@ namespace MosesServer retData["sg"] = xmlrpc_c::value_array(searchGraphXml); } - void + void TranslationRequest:: output_phrase(ostream& out, Phrase const& phrase) const { - if (!m_reportAllFactors) + if (!m_reportAllFactors) { - for (size_t i = 0 ; i < phrase.GetSize(); ++i) + for (size_t i = 0 ; i < phrase.GetSize(); ++i) out << *phrase.GetFactor(i, 0) << " "; } else out << phrase; } - - void + + void TranslationRequest:: outputNBest(const Manager& manager, map<string, xmlrpc_c::value>& retData) { TrellisPathList nBestList; vector<xmlrpc_c::value> nBestXml; manager.CalcNBest(m_nbestSize, nBestList, m_nbestDistinct); - + BOOST_FOREACH(Moses::TrellisPath const* path, nBestList) { vector<const Hypothesis *> const& E = path->GetEdges(); @@ -169,27 +169,27 @@ namespace MosesServer path->GetScoreBreakdown()->OutputAllFeatureScores(buf); nBestXmlItem["fvals"] = xmlrpc_c::value_string(buf.str()); } - + // weighted score nBestXmlItem["totalScore"] = xmlrpc_c::value_double(path->GetTotalScore()); nBestXml.push_back(xmlrpc_c::value_struct(nBestXmlItem)); } retData["nbest"] = xmlrpc_c::value_array(nBestXml); } - - void + + void TranslationRequest:: - insertTranslationOptions(Moses::Manager& manager, - std::map<std::string, xmlrpc_c::value>& retData) + insertTranslationOptions(Moses::Manager& manager, + std::map<std::string, xmlrpc_c::value>& retData) { - const TranslationOptionCollection* toptsColl + const TranslationOptionCollection* toptsColl = manager.getSntTranslationOptions(); vector<xmlrpc_c::value> toptsXml; size_t const stop = toptsColl->GetSource().GetSize(); TranslationOptionList const* tol; - for (size_t s = 0 ; s < stop ; ++s) + for (size_t s = 0 ; s < stop ; ++s) { - for (size_t e = s; + for (size_t e = s; (tol = toptsColl->GetTranslationOptionList(s,e)) != NULL; ++e) { @@ -204,11 +204,11 @@ namespace MosesServer toptXml["start"] = xmlrpc_c::value_int(s); toptXml["end"] = xmlrpc_c::value_int(e); vector<xmlrpc_c::value> scoresXml; - const std::valarray<FValue> &scores + const std::valarray<FValue> &scores = topt->GetScoreBreakdown().getCoreFeatures(); - for (size_t j = 0; j < scores.size(); ++j) + for (size_t j = 0; j < scores.size(); ++j) scoresXml.push_back(xmlrpc_c::value_double(scores[j])); - + toptXml["scores"] = xmlrpc_c::value_array(scoresXml); toptsXml.push_back(xmlrpc_c::value_struct(toptXml)); } @@ -217,13 +217,13 @@ namespace MosesServer retData["topt"] = xmlrpc_c::value_array(toptsXml); } - bool + bool check(std::map<std::string, xmlrpc_c::value> const& params, std::string const key) { std::map<std::string, xmlrpc_c::value>::const_iterator m; return (params.find(key) != params.end()); } - + TranslationRequest:: TranslationRequest(xmlrpc_c::paramList const& paramList, boost::condition_variable& cond, boost::mutex& mut) @@ -236,15 +236,15 @@ namespace MosesServer { // parse XMLRPC request // params_t const params = m_paramList.getStruct(0); m_paramList.verifyEnd(1); // ??? UG - + // source text must be given, or we don't know what to translate typedef std::map<std::string, xmlrpc_c::value> params_t; params_t::const_iterator si = params.find("text"); - if (si == params.end()) + if (si == params.end()) throw xmlrpc_c::fault("Missing source text", xmlrpc_c::fault::CODE_PARSE); m_source_string = xmlrpc_c::value_string(si->second); XVERBOSE(1,"Input: " << m_source_string << endl); - + m_withAlignInfo = check(params, "align"); m_withWordAlignInfo = check(params, "word-align"); m_withGraphInfo = check(params, "sg"); @@ -252,31 +252,31 @@ namespace MosesServer m_reportAllFactors = check(params, "report-all-factors"); m_nbestDistinct = check(params, "nbest-distinct"); m_withScoreBreakdown = check(params, "add-score-breakdown"); - m_source.reset(new Sentence(0,m_source_string)); + m_source.reset(new Sentence(0,m_source_string)); si = params.find("lambda"); - if (si != params.end()) + if (si != params.end()) { // muMo = multiModel xmlrpc_c::value_array muMoArray = xmlrpc_c::value_array(si->second); vector<xmlrpc_c::value> muMoValVec(muMoArray.vectorValueValue()); vector<float> w(muMoValVec.size()); - for (size_t i = 0; i < muMoValVec.size(); ++i) + for (size_t i = 0; i < muMoValVec.size(); ++i) w[i] = xmlrpc_c::value_double(muMoValVec[i]); if (w.size() && (si = params.find("model_name")) != params.end()) { string const model_name = xmlrpc_c::value_string(si->second); - PhraseDictionaryMultiModel* pdmm + PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name); - // Moses::PhraseDictionaryMultiModel* pdmm + // Moses::PhraseDictionaryMultiModel* pdmm // = FindPhraseDictionary(model_name); pdmm->SetTemporaryMultiModelWeightsVector(w); } } - + // // biased sampling for suffix-array-based sampling phrase table? // if ((si = params.find("bias")) != params.end()) - // { - // std::vector<xmlrpc_c::value> tmp + // { + // std::vector<xmlrpc_c::value> tmp // = xmlrpc_c::value_array(si->second).cvalue(); // for (size_t i = 1; i < tmp.size(); i += 2) // m_bias[xmlrpc_c::value_int(tmp[i-1])] = xmlrpc_c::value_double(tmp[i]); @@ -288,28 +288,28 @@ namespace MosesServer TranslationRequest:: run_chart_decoder() { - Moses::TreeInput tinput; + Moses::TreeInput tinput; istringstream buf(m_source_string + "\n"); tinput.Read(buf, StaticData::Instance().GetInputFactorOrder()); - + Moses::ChartManager manager(this->self()); manager.Decode(); - + const Moses::ChartHypothesis *hypo = manager.GetBestHypothesis(); ostringstream out; outputChartHypo(out,hypo); - + m_target_string = out.str(); m_retData["text"] = xmlrpc_c::value_string(m_target_string); - - if (m_withGraphInfo) + + if (m_withGraphInfo) { std::ostringstream sgstream; manager.OutputSearchGraphMoses(sgstream); m_retData["sg"] = xmlrpc_c::value_string(sgstream.str()); } } // end of TranslationRequest::run_chart_decoder() - + void TranslationRequest:: pack_hypothesis(vector<Hypothesis const* > const& edges, string const& key, @@ -320,7 +320,7 @@ namespace MosesServer BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) output_phrase(target, e->GetCurrTargetPhrase()); dest[key] = xmlrpc_c::value_string(target.str()); - + if (m_withAlignInfo) { // phrase alignment, if requested @@ -359,16 +359,16 @@ namespace MosesServer Manager manager(this->self()); // if (m_bias.size()) manager.SetBias(&m_bias); manager.Decode(); - + pack_hypothesis(manager.GetBestHypothesis(), "text", m_retData); - + if (m_withGraphInfo) insertGraphInfo(manager,m_retData); if (m_withTopts) insertTranslationOptions(manager,m_retData); if (m_nbestSize) outputNBest(manager, m_retData); - + (const_cast<StaticData&>(Moses::StaticData::Instance())) - .SetOutputSearchGraph(false); + .SetOutputSearchGraph(false); // WTF? one more reason not to have this as global variable! --- UG - + } } diff --git a/moses/server/TranslationRequest.h b/moses/server/TranslationRequest.h index 89b3c5097..6c7cd7275 100644 --- a/moses/server/TranslationRequest.h +++ b/moses/server/TranslationRequest.h @@ -23,7 +23,7 @@ #include <xmlrpc-c/base.hpp> namespace MosesServer { - class + class TranslationRequest : public virtual Moses::TranslationTask { boost::condition_variable& m_cond; @@ -33,7 +33,7 @@ namespace MosesServer xmlrpc_c::paramList const& m_paramList; std::map<std::string, xmlrpc_c::value> m_retData; std::map<uint32_t,float> m_bias; // for biased sampling - + std::string m_source_string, m_target_string; bool m_withAlignInfo; bool m_withWordAlignInfo; @@ -44,21 +44,21 @@ namespace MosesServer bool m_withScoreBreakdown; size_t m_nbestSize; - void + void parse_request(); void parse_request(std::map<std::string, xmlrpc_c::value> const& req); - + virtual void run_chart_decoder(); virtual void run_phrase_decoder(); - - void - pack_hypothesis(std::vector<Moses::Hypothesis const* > const& edges, - std::string const& key, + + void + pack_hypothesis(std::vector<Moses::Hypothesis const* > const& edges, + std::string const& key, std::map<std::string, xmlrpc_c::value> & dest) const; void @@ -66,57 +66,57 @@ namespace MosesServer std::map<std::string, xmlrpc_c::value> & dest) const; - void + void output_phrase(std::ostream& out, Moses::Phrase const& phrase) const; - void - add_phrase_aln_info(Moses::Hypothesis const& h, + void + add_phrase_aln_info(Moses::Hypothesis const& h, std::vector<xmlrpc_c::value>& aInfo) const; - void + void outputChartHypo(std::ostream& out, const Moses::ChartHypothesis* hypo); - bool - compareSearchGraphNode(const Moses::SearchGraphNode& a, + bool + compareSearchGraphNode(const Moses::SearchGraphNode& a, const Moses::SearchGraphNode& b); - void - insertGraphInfo(Moses::Manager& manager, - std::map<std::string, xmlrpc_c::value>& retData); - void - outputNBest(Moses::Manager const& manager, + void + insertGraphInfo(Moses::Manager& manager, + std::map<std::string, xmlrpc_c::value>& retData); + void + outputNBest(Moses::Manager const& manager, std::map<std::string, xmlrpc_c::value>& retData); - void - insertTranslationOptions(Moses::Manager& manager, + void + insertTranslationOptions(Moses::Manager& manager, std::map<std::string, xmlrpc_c::value>& retData); protected: - TranslationRequest(xmlrpc_c::paramList const& paramList, - boost::condition_variable& cond, + TranslationRequest(xmlrpc_c::paramList const& paramList, + boost::condition_variable& cond, boost::mutex& mut); public: static boost::shared_ptr<TranslationRequest> - create(xmlrpc_c::paramList const& paramList, - boost::condition_variable& cond, + create(xmlrpc_c::paramList const& paramList, + boost::condition_variable& cond, boost::mutex& mut); - - - virtual bool + + + virtual bool DeleteAfterExecution() { return false; } - - bool + + bool IsDone() const { return m_done; } - - std::map<std::string, xmlrpc_c::value> const& + + std::map<std::string, xmlrpc_c::value> const& GetRetData() { return m_retData; } - - void + + void Run(); - - + + }; } diff --git a/moses/server/Translator.cpp b/moses/server/Translator.cpp index 51f863c4b..d4cff99df 100644 --- a/moses/server/Translator.cpp +++ b/moses/server/Translator.cpp @@ -8,8 +8,8 @@ namespace MosesServer using namespace Moses; Translator:: - Translator(size_t numThreads) - : m_threadPool(numThreads) + Translator(size_t numThreads) + : m_threadPool(numThreads) { // signature and help strings are documentation -- the client // can query this information with a system.methodSignature and @@ -17,21 +17,21 @@ namespace MosesServer this->_signature = "S:S"; this->_help = "Does translation"; } - - void + + void Translator:: execute(xmlrpc_c::paramList const& paramList, - xmlrpc_c::value * const retvalP) + xmlrpc_c::value * const retvalP) { boost::condition_variable cond; boost::mutex mut; - boost::shared_ptr<TranslationRequest> task + boost::shared_ptr<TranslationRequest> task = TranslationRequest::create(paramList,cond,mut); m_threadPool.Submit(task); boost::unique_lock<boost::mutex> lock(mut); - while (!task->IsDone()) + while (!task->IsDone()) cond.wait(lock); *retvalP = xmlrpc_c::value_struct(task->GetRetData()); } - + } diff --git a/moses/server/Translator.h b/moses/server/Translator.h index 062080545..e3117c290 100644 --- a/moses/server/Translator.h +++ b/moses/server/Translator.h @@ -10,17 +10,17 @@ #endif namespace MosesServer { - class + class // MosesServer:: Translator : public xmlrpc_c::method { public: Translator(size_t numThreads = 10); - + void execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value * const retvalP); private: Moses::ThreadPool m_threadPool; }; - + } diff --git a/moses/server/Updater.cpp b/moses/server/Updater.cpp index 95cafd71a..818f374a5 100644 --- a/moses/server/Updater.cpp +++ b/moses/server/Updater.cpp @@ -6,7 +6,7 @@ namespace MosesServer using namespace std; Updater:: - Updater() + Updater() { // signature and help strings are documentation -- the client // can query this information with a system.methodSignature and @@ -18,7 +18,7 @@ namespace MosesServer void Updater:: execute(xmlrpc_c::paramList const& paramList, - xmlrpc_c::value * const retvalP) + xmlrpc_c::value * const retvalP) { #if PT_UG const params_t params = paramList.getStruct(0); @@ -29,20 +29,20 @@ namespace MosesServer *retvalP = xmlrpc_c::value_string("Phrase table updated"); #endif }; - - void + + void Updater:: - breakOutParams(const params_t& params) + breakOutParams(const params_t& params) { params_t::const_iterator si = params.find("source"); if(si == params.end()) - throw xmlrpc_c::fault("Missing source sentence", + throw xmlrpc_c::fault("Missing source sentence", xmlrpc_c::fault::CODE_PARSE); m_src = xmlrpc_c::value_string(si->second); XVERBOSE(1,"source = " << m_src << endl); si = params.find("target"); if(si == params.end()) - throw xmlrpc_c::fault("Missing target sentence", + throw xmlrpc_c::fault("Missing target sentence", xmlrpc_c::fault::CODE_PARSE); m_trg = xmlrpc_c::value_string(si->second); XVERBOSE(1,"target = " << m_trg << endl); @@ -53,5 +53,5 @@ namespace MosesServer m_bounded = ((si = params.find("bounded")) != params.end()); m_add2ORLM = ((si = params.find("updateORLM")) != params.end()); }; - + } diff --git a/moses/server/Updater.h b/moses/server/Updater.h index c3c72da50..9bb20b775 100644 --- a/moses/server/Updater.h +++ b/moses/server/Updater.h @@ -19,7 +19,7 @@ namespace MosesServer { - class + class Updater: public xmlrpc_c::method { @@ -31,14 +31,14 @@ namespace MosesServer public: Updater(); - + void execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value * const retvalP); - void + void breakOutParams(const params_t& params); - + }; } |