diff options
author | Sid Jain <sija@microsoft.com> | 2020-10-16 08:00:47 +0300 |
---|---|---|
committer | Sid Jain <sija@microsoft.com> | 2020-10-16 08:00:47 +0300 |
commit | 48fa90931b40523143738a7aaf0a9b36be310a3e (patch) | |
tree | 91a0458369cccb149714156e684302f4d6ec99b2 | |
parent | 84fb13c57c446d30903a21426bea345979f5efa2 (diff) |
adding preprocessor for xmlrpc server , renaming MSPT to DynamicPT
-rw-r--r-- | moses2/FF/FeatureRegistry.cpp | 4 | ||||
-rw-r--r-- | moses2/Main.cpp | 76 | ||||
-rw-r--r-- | moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp (renamed from moses2/TranslationModel/MSPT/MSPT.cpp) | 27 | ||||
-rw-r--r-- | moses2/TranslationModel/Dynamic/DynamicPhraseTable.h (renamed from moses2/TranslationModel/MSPT/MSPT.h) | 18 | ||||
-rw-r--r-- | moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h (renamed from moses2/TranslationModel/MSPT/MSNode.h) | 2 | ||||
-rw-r--r-- | moses2/parameters/AllOptions.cpp | 4 | ||||
-rw-r--r-- | moses2/parameters/AllOptions.h | 6 | ||||
-rw-r--r-- | moses2/parameters/ServerOptions.cpp | 2 | ||||
-rw-r--r-- | moses2/parameters/ServerOptions.h | 5 | ||||
-rw-r--r-- | moses2/server/Server.cpp | 2 | ||||
-rw-r--r-- | moses2/server/TranslationRequest.cpp | 2 | ||||
-rw-r--r-- | moses2/server/Translator.cpp | 2 |
12 files changed, 91 insertions, 59 deletions
diff --git a/moses2/FF/FeatureRegistry.cpp b/moses2/FF/FeatureRegistry.cpp index 0ea56e6ce..8e457d371 100644 --- a/moses2/FF/FeatureRegistry.cpp +++ b/moses2/FF/FeatureRegistry.cpp @@ -4,7 +4,7 @@ #include "../TranslationModel/ProbingPT.h" #include "../TranslationModel/UnknownWordPenalty.h" #include "../TranslationModel/Transliteration.h" -#include "../TranslationModel/MSPT/MSPT.h" +#include "../TranslationModel/Dynamic/DynamicPhraseTable.h" #include "../LM/KENLM.h" #include "../LM/KENLMBatch.h" @@ -57,7 +57,7 @@ FeatureRegistry::FeatureRegistry() MOSES_FNAME(ProbingPT); MOSES_FNAME2("PhraseDictionaryTransliteration", Transliteration); MOSES_FNAME(UnknownWordPenalty); - MOSES_FNAME(MSPT); + MOSES_FNAME(DynamicPhraseTable); Add("KENLM", new KenFactory()); diff --git a/moses2/Main.cpp b/moses2/Main.cpp index 7054ec4ce..626255566 100644 --- a/moses2/Main.cpp +++ b/moses2/Main.cpp @@ -6,7 +6,10 @@ #include "Phrase.h" #include "TranslationTask.h" #include "MemPoolAllocator.h" -//#include "server/Server.h" +#ifdef HAVE_SERVER + #include "server/Server.h" +#endif // HAVE_SERVER + #include "legacy/InputFileStream.h" #include "legacy/Parameter.h" #include "legacy/ThreadPool.h" @@ -38,17 +41,26 @@ int main(int argc, char** argv) } //cerr << "system.numThreads=" << system.options.server.numThreads << endl; - +#ifdef HAVE_SERVER Moses2::ThreadPool pool(system.options.server.numThreads, system.cpuAffinityOffset, system.cpuAffinityOffsetIncr); //cerr << "CREATED POOL" << endl; if (params.GetParam("server")) { std::cerr << "RUN SERVER" << std::endl; run_as_server(system); - } else { - std::cerr << "RUN BATCH" << std::endl; - batch_run(params, system, pool); } + else { + std::cerr << "RUN BATCH" << std::endl; + batch_run(params, system, pool); + } +#endif // +#ifndef HAVE_SERVER + Moses2::ThreadPool pool(15, system.cpuAffinityOffset, system.cpuAffinityOffsetIncr); + //cerr << "CREATED POOL" << endl; + + std::cerr << "RUN BATCH" << std::endl; + batch_run(params, system, pool); +#endif // !HAVE_SERVER cerr << "Decoding took " << timer.get_elapsed_time() << endl; // cerr << "g_numHypos=" << g_numHypos << endl; @@ -57,12 +69,14 @@ int main(int argc, char** argv) } //////////////////////////////////////////////////////////////////////////////////////////////// -void run_as_server(Moses2::System &system) -{ - //Moses2::Server server(system.options.server, system); - //server.run(system); // actually: don't return. see Server::run() -} - +#ifdef HAVE_SERVER + void run_as_server(Moses2::System& system) + { + Moses2::Server server(system.options.server, system); + server.run(system); // actually: don't return. see Server::run() + } + +#endif // HAVE_SERVER //////////////////////////////////////////////////////////////////////////////////////////////// istream &GetInputStream(Moses2::Parameter ¶ms) { @@ -76,31 +90,33 @@ istream &GetInputStream(Moses2::Parameter ¶ms) } //////////////////////////////////////////////////////////////////////////////////////////////// -void batch_run(Moses2::Parameter ¶ms, Moses2::System &system, Moses2::ThreadPool &pool) + +void batch_run(Moses2::Parameter& params, Moses2::System& system, Moses2::ThreadPool& pool) { - istream &inStream = GetInputStream(params); - - long translationId = 0; - string line; - while (getline(inStream, line)) { - //cerr << "line=" << line << endl; - boost::shared_ptr<Moses2::TranslationTask> task(new Moses2::TranslationTask(system, line, translationId)); - - //cerr << "START pool.Submit()" << endl; - pool.Submit(task); - //task->Run(); - ++translationId; - } + istream& inStream = GetInputStream(params); - pool.Stop(true); + long translationId = 0; + string line; + while (getline(inStream, line)) { + //cerr << "line=" << line << endl; + boost::shared_ptr<Moses2::TranslationTask> task(new Moses2::TranslationTask(system, line, translationId)); - if (&inStream != &cin) { - delete &inStream; - } + //cerr << "START pool.Submit()" << endl; + pool.Submit(task); + //task->Run(); + ++translationId; + } - //util::PrintUsage(std::cerr); + pool.Stop(true); + + if (&inStream != &cin) { + delete& inStream; + } + + //util::PrintUsage(std::cerr); } + //////////////////////////////////////////////////////////////////////////////////////////////// void Temp() { diff --git a/moses2/TranslationModel/MSPT/MSPT.cpp b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp index a30169f29..0a74fcaa3 100644 --- a/moses2/TranslationModel/MSPT/MSPT.cpp +++ b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp @@ -1,5 +1,5 @@ /* - * MSPT.cpp + * DynamicPhraseTable.cpp * * Created on: 28 Oct 2015 * Author: hieu @@ -8,7 +8,7 @@ #include <cassert> #include <sstream> #include <boost/foreach.hpp> -#include "MSPT.h" +#include "DynamicPhraseTable.h" #include "../../PhraseBased/PhraseImpl.h" #include "../../Phrase.h" #include "../../System.h" @@ -36,22 +36,22 @@ using namespace std; namespace Moses2 { -thread_local MSPT::PBNODE *MSPT::m_rootPb; +thread_local DynamicPhraseTable::PBNODE * DynamicPhraseTable::m_rootPb; //////////////////////////////////////////////////////////////////////// -MSPT::MSPT(size_t startInd, const std::string &line) +DynamicPhraseTable::DynamicPhraseTable(size_t startInd, const std::string &line) :PhraseTable(startInd, line) { ReadParameters(); } -MSPT::~MSPT() +DynamicPhraseTable::~DynamicPhraseTable() { delete m_rootPb; } -void MSPT::CreatePTForInput(const ManagerBase &mgr, string phraseTableString) +void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseTableString) { //cerr << "In CreatePTForInput" << endl << flush; const System &system = mgr.system; @@ -128,29 +128,26 @@ void MSPT::CreatePTForInput(const ManagerBase &mgr, string phraseTableString) } -void MSPT::InitializeForInput(const ManagerBase &mgr, const InputType &input) +void DynamicPhraseTable::InitializeForInput(const ManagerBase &mgr, const InputType &input) { // downcast to SentenceWithCandidates const SentenceWithCandidates &inputObj = static_cast<const SentenceWithCandidates&>(input); CreatePTForInput(mgr, inputObj.getPhraseTableString()); } -TargetPhrases* MSPT::Lookup(const Manager &mgr, MemPool &pool, +TargetPhrases* DynamicPhraseTable::Lookup(const Manager &mgr, MemPool &pool, InputPath &inputPath) const { - //cerr << "MSPT::Lookup inputPath:" << inputPath.Debug(mgr.system) << endl; const SubPhrase<Moses2::Word> &phrase = inputPath.subPhrase; TargetPhrases *tps = m_rootPb->Find(m_input, phrase); - //cerr << "MSPT::Lookup tps:" << tps->Debug(mgr.system) << endl; - //cerr << "MSPT::Lookup done" << endl; return tps; } -void MSPT::CleanUpAfterSentenceProcessing(const System &system, const InputType &input) const { +void DynamicPhraseTable::CleanUpAfterSentenceProcessing(const System &system, const InputType &input) const { delete m_rootPb; } -void MSPT::InitActiveChart( +void DynamicPhraseTable::InitActiveChart( MemPool &pool, const SCFG::Manager &mgr, SCFG::InputPath &path) const @@ -158,7 +155,7 @@ void MSPT::InitActiveChart( abort(); } -void MSPT::Lookup(MemPool &pool, +void DynamicPhraseTable::Lookup(MemPool &pool, const SCFG::Manager &mgr, size_t maxChartSpan, const SCFG::Stacks &stacks, @@ -167,7 +164,7 @@ void MSPT::Lookup(MemPool &pool, abort(); } -void MSPT::LookupGivenNode( +void DynamicPhraseTable::LookupGivenNode( MemPool &pool, const SCFG::Manager &mgr, const SCFG::ActiveChartEntry &prevEntry, diff --git a/moses2/TranslationModel/MSPT/MSPT.h b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.h index fe37e34b9..7fd467700 100644 --- a/moses2/TranslationModel/MSPT/MSPT.h +++ b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.h @@ -9,7 +9,7 @@ #include "../PhraseTable.h" #include "../../legacy/Util2.h" #include "../../SCFG/InputPath.h" -#include "MSNode.h" +#include "DynamicPhraseTableNode.h" #include "../../PhraseBased/PhraseImpl.h" #include "../../PhraseBased/TargetPhraseImpl.h" #include "../../PhraseBased/TargetPhrases.h" @@ -20,26 +20,26 @@ namespace Moses2 { -class MSPT: public PhraseTable +class DynamicPhraseTable: public PhraseTable { - typedef MSPTNS::Node<Word, Phrase<Word>, TargetPhraseImpl, TargetPhrases> PBNODE; - typedef MSPTNS::Node<SCFG::Word, Phrase<SCFG::Word>, SCFG::TargetPhraseImpl, SCFG::TargetPhrases> SCFGNODE; + typedef DynamicPhraseTableNS::Node<Word, Phrase<Word>, TargetPhraseImpl, TargetPhrases> PBNODE; + typedef DynamicPhraseTableNS::Node<SCFG::Word, Phrase<SCFG::Word>, SCFG::TargetPhraseImpl, SCFG::TargetPhrases> SCFGNODE; ////////////////////////////////////// class ActiveChartEntryMem : public SCFG::ActiveChartEntry { typedef SCFG::ActiveChartEntry Parent; public: - const MSPT::SCFGNODE &node; + const DynamicPhraseTable::SCFGNODE &node; - ActiveChartEntryMem(MemPool &pool, const MSPT::SCFGNODE &vnode) + ActiveChartEntryMem(MemPool &pool, const DynamicPhraseTable::SCFGNODE &vnode) :Parent(pool) ,node(vnode) {} ActiveChartEntryMem( MemPool &pool, - const MSPT::SCFGNODE &vnode, + const DynamicPhraseTable::SCFGNODE &vnode, const ActiveChartEntry &prevEntry) :Parent(prevEntry) ,node(vnode) @@ -48,8 +48,8 @@ class MSPT: public PhraseTable ////////////////////////////////////// public: - MSPT(size_t startInd, const std::string &line); - virtual ~MSPT(); + DynamicPhraseTable(size_t startInd, const std::string &line); + virtual ~DynamicPhraseTable(); virtual TargetPhrases *Lookup(const Manager &mgr, MemPool &pool, InputPath &inputPath) const; diff --git a/moses2/TranslationModel/MSPT/MSNode.h b/moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h index b02422aa5..b10e4e161 100644 --- a/moses2/TranslationModel/MSPT/MSNode.h +++ b/moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h @@ -15,7 +15,7 @@ namespace Moses2 { class System; -namespace MSPTNS +namespace DynamicPhraseTableNS { template<class WORD, class SP, class TP, class TPS> diff --git a/moses2/parameters/AllOptions.cpp b/moses2/parameters/AllOptions.cpp index 954d7e8e7..595f6b415 100644 --- a/moses2/parameters/AllOptions.cpp +++ b/moses2/parameters/AllOptions.cpp @@ -31,7 +31,9 @@ init(Parameter const& param) if (!lmbr.init(param)) return false; if (!output.init(param)) return false; if (!unk.init(param)) return false; +#if HAVE_SERVER if (!server.init(param)) return false; +#endif // HAVE_SERVER if (!syntax.init(param)) return false; param.SetParameter(mira, "mira", false); @@ -95,7 +97,7 @@ update(std::map<std::string,xmlrpc_c::value>const& param) if (!lmbr.update(param)) return false; if (!output.update(param)) return false; if (!unk.update(param)) return false; - if (!server.update(param)) return false; + //if (!server.update(param)) return false; //if (!syntax.update(param)) return false; return sanity_check(); } diff --git a/moses2/parameters/AllOptions.h b/moses2/parameters/AllOptions.h index 2f09cd385..187ddb7bb 100644 --- a/moses2/parameters/AllOptions.h +++ b/moses2/parameters/AllOptions.h @@ -13,7 +13,9 @@ #include "LMBR_Options.h" #include "ReportingOptions.h" #include "OOVHandlingOptions.h" -#include "ServerOptions.h" +#ifdef HAVE_SERVER + #include "ServerOptions.h" +#endif // HAVE_SERVER #include "SyntaxOptions.h" namespace Moses2 @@ -31,7 +33,9 @@ struct LMBR_Options lmbr; ReportingOptions output; OOVHandlingOptions unk; +#ifdef HAVE_SERVER ServerOptions server; +#endif // HAVE_SERVER SyntaxOptions syntax; bool mira; bool use_legacy_pt; diff --git a/moses2/parameters/ServerOptions.cpp b/moses2/parameters/ServerOptions.cpp index 3a21c1891..c00a43d26 100644 --- a/moses2/parameters/ServerOptions.cpp +++ b/moses2/parameters/ServerOptions.cpp @@ -1,4 +1,5 @@ // -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*- +#ifdef HAVE_SERVER #include <boost/foreach.hpp> #include <string> #include "../legacy/Parameter.h" @@ -81,3 +82,4 @@ init(Parameter const& P) return true; } } // namespace Moses +#endif diff --git a/moses2/parameters/ServerOptions.h b/moses2/parameters/ServerOptions.h index 377b4d31b..39b109674 100644 --- a/moses2/parameters/ServerOptions.h +++ b/moses2/parameters/ServerOptions.h @@ -1,5 +1,9 @@ // -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*- #pragma once +#ifdef HAVE_SERVER + + + #include <string> #include <map> #include <stdint.h> @@ -39,3 +43,4 @@ struct }; } +#endif // HAVE_SERVER diff --git a/moses2/server/Server.cpp b/moses2/server/Server.cpp index 2da72270a..e8baeadb3 100644 --- a/moses2/server/Server.cpp +++ b/moses2/server/Server.cpp @@ -4,6 +4,7 @@ * Created on: 1 Apr 2016 * Author: hieu */ +#ifdef HAVE_SERVER #include <iostream> #include "../System.h" #include "Server.h" @@ -70,3 +71,4 @@ ServerOptions const&Server::options() const } /* namespace Moses2 */ +#endif // HAVE_SERVER diff --git a/moses2/server/TranslationRequest.cpp b/moses2/server/TranslationRequest.cpp index 2d50835a6..91ae3357f 100644 --- a/moses2/server/TranslationRequest.cpp +++ b/moses2/server/TranslationRequest.cpp @@ -1,3 +1,4 @@ +#ifdef HAVE_SERVER #include <boost/foreach.hpp> #include "TranslationRequest.h" #include "../ManagerBase.h" @@ -66,3 +67,4 @@ void TranslationRequest::pack_hypothesis(const Manager& manager, Hypothesis cons } } +#endif // HAVE_SERVER diff --git a/moses2/server/Translator.cpp b/moses2/server/Translator.cpp index 6f6212323..9d6dcbc85 100644 --- a/moses2/server/Translator.cpp +++ b/moses2/server/Translator.cpp @@ -4,6 +4,7 @@ * Created on: 1 Apr 2016 * Author: hieu */ +#ifdef HAVE_SERVER #include <boost/shared_ptr.hpp> #include "Translator.h" #include "TranslationRequest.h" @@ -66,3 +67,4 @@ void Translator::execute(xmlrpc_c::paramList const& paramList, } } /* namespace Moses2 */ +#endif // HAVE_SERVER |