From 3c7271220d45248e75727b60a1ae0510ebbd29ca Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Wed, 8 Feb 2012 13:29:16 -0500 Subject: [PATCH] Compile ORLM. The existing code should to be refactored. --- contrib/server/mosesserver.cpp | 17 +++-------------- moses/src/DynSAInclude/Jamfile | 1 + moses/src/LM/Factory.cpp | 10 +++++----- moses/src/LM/Implementation.h | 2 ++ moses/src/LM/Jamfile | 6 ++++-- 5 files changed, 15 insertions(+), 21 deletions(-) create mode 100644 moses/src/DynSAInclude/Jamfile diff --git a/contrib/server/mosesserver.cpp b/contrib/server/mosesserver.cpp index c3459a59e..2775a058f 100644 --- a/contrib/server/mosesserver.cpp +++ b/contrib/server/mosesserver.cpp @@ -12,9 +12,7 @@ #include "PhraseDictionaryDynSuffixArray.h" #include "TranslationSystem.h" #include "LMList.h" -#ifdef LM_ORLM -# include "LanguageModelORLM.h" -#endif +#include "LM/ORLM.h" using namespace Moses; using namespace std; @@ -67,20 +65,12 @@ public: string source_, target_, alignment_; bool bounded_, add2ORLM_; void updateORLM() { -#ifdef LM_ORLM + // TODO(level101): this belongs in the language model, not in moseserver.cpp vector vl; map, int> ngSet; LMList lms = StaticData::Instance().GetLMList(); // get LM LMList::const_iterator lmIter = lms.begin(); - const LanguageModel* lm = *lmIter; - /* currently assumes a single LM that is a ORLM */ -#ifdef WITH_THREADS - boost::shared_ptr orlm; - orlm = boost::dynamic_pointer_cast(lm->GetLMImplementation()); -#else - LanguageModelORLM* orlm; - orlm = (LanguageModelORLM*)lm->GetLMImplementation(); -#endif + LanguageModelORLM* orlm = static_cast(static_cast(*lmIter)->MosesServerCppShouldNotHaveLMCode()); if(orlm == 0) { cerr << "WARNING: Unable to add target sentence to ORLM\n"; return; @@ -113,7 +103,6 @@ public: orlm->UpdateORLM(it->first, it->second); } } -#endif } void breakOutParams(const params_t& params) { params_t::const_iterator si = params.find("source"); diff --git a/moses/src/DynSAInclude/Jamfile b/moses/src/DynSAInclude/Jamfile new file mode 100644 index 000000000..ff4bd6f76 --- /dev/null +++ b/moses/src/DynSAInclude/Jamfile @@ -0,0 +1 @@ +lib dynsa : [ glob *.cpp ] ../../../util//kenutil : : : . ; diff --git a/moses/src/LM/Factory.cpp b/moses/src/LM/Factory.cpp index 13cc0fdba..68dc06e4a 100644 --- a/moses/src/LM/Factory.cpp +++ b/moses/src/LM/Factory.cpp @@ -37,13 +37,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifdef LM_RAND # include "LM/Rand.h" #endif -#ifdef LM_ORLM -# include "LM/ORLM.h" -#endif + +#include "LM/ORLM.h" + #ifdef LM_REMOTE # include "LM/Remote.h" #endif + #include "LM/Ken.h" + #ifdef LM_DMAP # include "LM/DMapLM.h" #endif @@ -77,9 +79,7 @@ LanguageModel* CreateLanguageModel(LMImplementation lmImplementation #endif break; case ORLM: -#ifdef LM_ORLM lm = new LanguageModelORLM(); -#endif break; case Remote: #ifdef LM_REMOTE diff --git a/moses/src/LM/Implementation.h b/moses/src/LM/Implementation.h index 1ea59b6b3..66e41712f 100644 --- a/moses/src/LM/Implementation.h +++ b/moses/src/LM/Implementation.h @@ -168,6 +168,8 @@ class LMRefCount : public LanguageModel { return m_impl->GetScoreProducerDescription(param); } + LanguageModelImplementation *MosesServerCppShouldNotHaveLMCode() { return m_impl.get(); } + private: LMRefCount(ScoreIndexManager &scoreIndexManager, const LMRefCount ©_from) : m_impl(copy_from.m_impl) { Init(scoreIndexManager); diff --git a/moses/src/LM/Jamfile b/moses/src/LM/Jamfile index b7d7312fd..372bb79f3 100644 --- a/moses/src/LM/Jamfile +++ b/moses/src/LM/Jamfile @@ -44,9 +44,11 @@ if $(with-randlm) { dependencies += rand ; } -obj Factory.o : Factory.cpp ..//headers $(dependencies) ; +obj ORLM.o : ORLM.cpp ..//headers ../DynSAInclude//dynsa : : : ../DynSAInclude ; -lib LM : Base.cpp Factory.o Implementation.cpp Joint.cpp Ken.cpp MultiFactor.cpp Remote.cpp SingleFactor.cpp +obj Factory.o : Factory.cpp ..//headers $(dependencies) : ../DynSAInclude ; + +lib LM : Base.cpp Factory.o Implementation.cpp Joint.cpp Ken.cpp MultiFactor.cpp Remote.cpp SingleFactor.cpp ORLM.o ../../../lm//kenlm ..//headers $(dependencies) ; #Huge kludge to force building if different --with options are passed.