diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2016-03-29 01:58:20 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2016-03-29 01:58:20 +0300 |
commit | ff8caa1226553dffa6a34c8374a5e4b7803d3483 (patch) | |
tree | 783e21b357fb3f0c525272e64550d16989599a16 /moses/FF | |
parent | 0e15cef0784c298fe7847290315c07c8eba74480 (diff) | |
parent | b8bc4a9fb64731b593ba56cce1da1af0bbb6138e (diff) |
Merge ../mosesdecoder into perf_moses2
Diffstat (limited to 'moses/FF')
-rw-r--r-- | moses/FF/OSM-Feature/KenOSM.cpp | 20 | ||||
-rw-r--r-- | moses/FF/OSM-Feature/KenOSM.h | 31 | ||||
-rw-r--r-- | moses/FF/OSM-Feature/OpSequenceModel.cpp | 4 |
3 files changed, 27 insertions, 28 deletions
diff --git a/moses/FF/OSM-Feature/KenOSM.cpp b/moses/FF/OSM-Feature/KenOSM.cpp index 4047406e5..25a1e6a93 100644 --- a/moses/FF/OSM-Feature/KenOSM.cpp +++ b/moses/FF/OSM-Feature/KenOSM.cpp @@ -3,29 +3,29 @@ namespace Moses { -OSMLM* ConstructOSMLM(const std::string &file) +OSMLM* ConstructOSMLM(const char *file) { lm::ngram::ModelType model_type; - if (lm::ngram::RecognizeBinary(file.c_str(), model_type)) { - + lm::ngram::Config config; + if (lm::ngram::RecognizeBinary(file, model_type)) { switch(model_type) { case lm::ngram::PROBING: - return new KenOSM<lm::ngram::ProbingModel>(file); + return new KenOSM<lm::ngram::ProbingModel>(file, config); case lm::ngram::REST_PROBING: - return new KenOSM<lm::ngram::RestProbingModel>(file); + return new KenOSM<lm::ngram::RestProbingModel>(file, config); case lm::ngram::TRIE: - return new KenOSM<lm::ngram::TrieModel>(file); + return new KenOSM<lm::ngram::TrieModel>(file, config); case lm::ngram::QUANT_TRIE: - return new KenOSM<lm::ngram::QuantTrieModel>(file); + return new KenOSM<lm::ngram::QuantTrieModel>(file, config); case lm::ngram::ARRAY_TRIE: - return new KenOSM<lm::ngram::ArrayTrieModel>(file); + return new KenOSM<lm::ngram::ArrayTrieModel>(file, config); case lm::ngram::QUANT_ARRAY_TRIE: - return new KenOSM<lm::ngram::QuantArrayTrieModel>(file); + return new KenOSM<lm::ngram::QuantArrayTrieModel>(file, config); default: UTIL_THROW2("Unrecognized kenlm model type " << model_type); } } else { - return new KenOSM<lm::ngram::ProbingModel>(file); + return new KenOSM<lm::ngram::ProbingModel>(file, config); } } diff --git a/moses/FF/OSM-Feature/KenOSM.h b/moses/FF/OSM-Feature/KenOSM.h index 03deead07..53268442b 100644 --- a/moses/FF/OSM-Feature/KenOSM.h +++ b/moses/FF/OSM-Feature/KenOSM.h @@ -2,7 +2,6 @@ #include <string> #include "lm/model.hh" -#include <boost/shared_ptr.hpp> namespace Moses { @@ -12,7 +11,7 @@ class KenOSMBase public: virtual ~KenOSMBase() {} - virtual float Score(const lm::ngram::State&, const std::string&, + virtual float Score(const lm::ngram::State&, StringPiece, lm::ngram::State&) const = 0; virtual const lm::ngram::State &BeginSentenceState() const = 0; @@ -24,31 +23,31 @@ template <class KenModel> class KenOSM : public KenOSMBase { public: - KenOSM(const std::string& file) - : m_kenlm(new KenModel(file.c_str())) {} - - virtual float Score(const lm::ngram::State &in_state, - const std::string& word, - lm::ngram::State &out_state) const { - return m_kenlm->Score(in_state, m_kenlm->GetVocabulary().Index(word), - out_state); + KenOSM(const char *file, const lm::ngram::Config &config) + : m_kenlm(file, config) {} + + float Score(const lm::ngram::State &in_state, + StringPiece word, + lm::ngram::State &out_state) const { + return m_kenlm.Score(in_state, m_kenlm.GetVocabulary().Index(word), + out_state); } - virtual const lm::ngram::State &BeginSentenceState() const { - return m_kenlm->BeginSentenceState(); + const lm::ngram::State &BeginSentenceState() const { + return m_kenlm.BeginSentenceState(); } - virtual const lm::ngram::State &NullContextState() const { - return m_kenlm->NullContextState(); + const lm::ngram::State &NullContextState() const { + return m_kenlm.NullContextState(); } private: - boost::shared_ptr<KenModel> m_kenlm; + KenModel m_kenlm; }; typedef KenOSMBase OSMLM; -OSMLM* ConstructOSMLM(const std::string &file); +OSMLM* ConstructOSMLM(const char *file); } // namespace diff --git a/moses/FF/OSM-Feature/OpSequenceModel.cpp b/moses/FF/OSM-Feature/OpSequenceModel.cpp index 4df2cbba6..4118c8690 100644 --- a/moses/FF/OSM-Feature/OpSequenceModel.cpp +++ b/moses/FF/OSM-Feature/OpSequenceModel.cpp @@ -27,7 +27,7 @@ OpSequenceModel::~OpSequenceModel() void OpSequenceModel :: readLanguageModel(const char *lmFile) { string unkOp = "_TRANS_SLF_"; - OSM = ConstructOSMLM(m_lmPath); + OSM = ConstructOSMLM(m_lmPath.c_str()); State startState = OSM->NullContextState(); State endState; @@ -200,7 +200,7 @@ FFState* OpSequenceModel::EvaluateWhenApplied( int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const { - UTIL_THROW2("Chart decoding not support by UTIL_THROW2"); + UTIL_THROW2("Chart decoding not support by OpSequenceModel"); } |