From 1a1634a3913ffbfca16e8e3bd56b5f079e7866e1 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 20 Feb 2013 22:44:11 +0000 Subject: [PATCH] make LanguageModelImplementation have new format constructor --- moses/LM/IRST.cpp | 6 +----- moses/LM/IRST.h | 1 - moses/LM/Implementation.h | 3 +++ moses/LM/Joint.h | 4 +++- moses/LM/MultiFactor.h | 4 +++- moses/LM/ORLM.h | 6 ++++-- moses/LM/ParallelBackoff.cpp | 7 ++++--- moses/LM/ParallelBackoff.h | 5 ----- moses/LM/SRI.cpp | 7 ++++--- moses/LM/SRI.h | 2 +- moses/LM/SingleFactor.cpp | 3 ++- moses/LM/SingleFactor.h | 2 +- 12 files changed, 26 insertions(+), 24 deletions(-) diff --git a/moses/LM/IRST.cpp b/moses/LM/IRST.cpp index 54563068c..38eeeb3cd 100644 --- a/moses/LM/IRST.cpp +++ b/moses/LM/IRST.cpp @@ -40,6 +40,7 @@ using namespace std; namespace Moses { LanguageModelIRST::LanguageModelIRST(const std::string &line) +:LanguageModelSingleFactor("IRSTLM", line) { cerr << "line=" << line << endl; FactorType factorType; @@ -68,11 +69,6 @@ LanguageModelIRST::LanguageModelIRST(const std::string &line) Load(filePath, factorType, nGramOrder); } -LanguageModelIRST::LanguageModelIRST(int dub) - :m_lmtb(0),m_lmtb_dub(dub) -{ -} - LanguageModelIRST::~LanguageModelIRST() { diff --git a/moses/LM/IRST.h b/moses/LM/IRST.h index 0d5ec5ebb..7bb841d59 100644 --- a/moses/LM/IRST.h +++ b/moses/LM/IRST.h @@ -64,7 +64,6 @@ protected: public: LanguageModelIRST(const std::string &line); - LanguageModelIRST(int dub); ~LanguageModelIRST(); bool Load(const std::string &filePath , FactorType factorType diff --git a/moses/LM/Implementation.h b/moses/LM/Implementation.h index cfeb963e1..3247f92ec 100644 --- a/moses/LM/Implementation.h +++ b/moses/LM/Implementation.h @@ -63,7 +63,10 @@ protected: Word m_sentenceStartArray, m_sentenceEndArray; //! Contains factors which represents the beging and end words for this LM. //! Usually and + LanguageModelImplementation(const std::string& description, const std::string &line) + {} public: + virtual ~LanguageModelImplementation() {} //! Single or multi-factor diff --git a/moses/LM/Joint.h b/moses/LM/Joint.h index 6f71e1a9b..90a4b17b7 100644 --- a/moses/LM/Joint.h +++ b/moses/LM/Joint.h @@ -49,7 +49,9 @@ protected: size_t m_implFactor; public: - LanguageModelJoint(LanguageModelSingleFactor *lmImpl) { + LanguageModelJoint(const std::string &line, LanguageModelSingleFactor *lmImpl) + :LanguageModelMultiFactor("JointLM", line) + { m_lmImpl = lmImpl; } diff --git a/moses/LM/MultiFactor.h b/moses/LM/MultiFactor.h index 1d38fbee6..3f5fbd88f 100644 --- a/moses/LM/MultiFactor.h +++ b/moses/LM/MultiFactor.h @@ -41,7 +41,9 @@ class LanguageModelMultiFactor : public LanguageModelImplementation protected: FactorMask m_factorTypes; - LanguageModelMultiFactor(){} + LanguageModelMultiFactor(const std::string& description, const std::string &line) + :LanguageModelImplementation(description, line) + {} public: virtual bool Load(const std::string &filePath diff --git a/moses/LM/ORLM.h b/moses/LM/ORLM.h index 9a98d02ca..5ad3d8b52 100644 --- a/moses/LM/ORLM.h +++ b/moses/LM/ORLM.h @@ -20,8 +20,10 @@ class Phrase; class LanguageModelORLM : public LanguageModelSingleFactor { public: typedef count_t T; // type for ORLM filter - LanguageModelORLM() - : m_lm(0) {} + LanguageModelORLM(const std::string &line) + :LanguageModelSingleFactor("ORLM", line) + ,m_lm(0) + {} bool Load(const std::string &filePath, FactorType factorType, size_t nGramOrder); virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = NULL) const; ~LanguageModelORLM() { diff --git a/moses/LM/ParallelBackoff.cpp b/moses/LM/ParallelBackoff.cpp index ee8279aef..22391310d 100644 --- a/moses/LM/ParallelBackoff.cpp +++ b/moses/LM/ParallelBackoff.cpp @@ -69,6 +69,10 @@ private: WidMatrix *widMatrix; public: + LanguageModelParallelBackoff(const std::string &line) + :LanguageModelMultiFactor("ParallelBackoffLM", line) + {} + ~LanguageModelParallelBackoff(); bool Load(const std::string &filePath, const std::vector &factorTypes, size_t nGramOrder); @@ -347,9 +351,6 @@ const FFState *LanguageModelParallelBackoff::GetBeginSentenceState() const } -LanguageModelMultiFactor *NewParallelBackoff() { - return new LanguageModelParallelBackoff(); -} } diff --git a/moses/LM/ParallelBackoff.h b/moses/LM/ParallelBackoff.h index 223a07b5a..3f370fce7 100644 --- a/moses/LM/ParallelBackoff.h +++ b/moses/LM/ParallelBackoff.h @@ -24,10 +24,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA namespace Moses { -class LanguageModelMultiFactor; - -/** @todo what is this? - */ -LanguageModelMultiFactor *NewParallelBackoff(); } diff --git a/moses/LM/SRI.cpp b/moses/LM/SRI.cpp index f39d172c8..8730c1e05 100644 --- a/moses/LM/SRI.cpp +++ b/moses/LM/SRI.cpp @@ -38,9 +38,10 @@ using namespace std; namespace Moses { -LanguageModelSRI::LanguageModelSRI() - : m_srilmVocab(0) - , m_srilmModel(0) +LanguageModelSRI::LanguageModelSRI(const std::string &line) +:LanguageModelSingleFactor("SRILM", line) +,m_srilmVocab(0) +,m_srilmModel(0) { } diff --git a/moses/LM/SRI.h b/moses/LM/SRI.h index 1ced803e7..7aa9c27a6 100644 --- a/moses/LM/SRI.h +++ b/moses/LM/SRI.h @@ -52,7 +52,7 @@ protected: unsigned int GetLmID( const Factor *factor ) const; public: - LanguageModelSRI(); + LanguageModelSRI(const std::string &line); ~LanguageModelSRI(); bool Load(const std::string &filePath , FactorType factorType diff --git a/moses/LM/SingleFactor.cpp b/moses/LM/SingleFactor.cpp index 5f21c33f8..d4efb8378 100644 --- a/moses/LM/SingleFactor.cpp +++ b/moses/LM/SingleFactor.cpp @@ -49,7 +49,8 @@ struct PointerState : public FFState { } }; -LanguageModelSingleFactor::LanguageModelSingleFactor() +LanguageModelSingleFactor::LanguageModelSingleFactor(const std::string& description, const std::string &line) +:LanguageModelImplementation(description, line) { m_nullContextState = new PointerState(NULL); m_beginSentenceState = new PointerState(NULL); diff --git a/moses/LM/SingleFactor.h b/moses/LM/SingleFactor.h index 4e40c9fdb..e1d629321 100644 --- a/moses/LM/SingleFactor.h +++ b/moses/LM/SingleFactor.h @@ -43,7 +43,7 @@ protected: FFState *m_nullContextState; FFState *m_beginSentenceState; - LanguageModelSingleFactor(); + LanguageModelSingleFactor(const std::string& description, const std::string &line); public: virtual ~LanguageModelSingleFactor();