| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef moses_LanguageModelImplementation_h |
| | #define moses_LanguageModelImplementation_h |
| |
|
| | #include <string> |
| | #include <vector> |
| | #include "moses/Factor.h" |
| | #include "moses/TypeDef.h" |
| | #include "moses/Util.h" |
| | #include "moses/Word.h" |
| | #include "Base.h" |
| |
|
| | #include <boost/shared_ptr.hpp> |
| |
|
| | namespace Moses |
| | { |
| |
|
| | class FactorCollection; |
| | class Factor; |
| | class Phrase; |
| |
|
| | |
| | struct LMResult { |
| | |
| | float score; |
| | |
| | bool unknown; |
| | }; |
| |
|
| | |
| | class LanguageModelImplementation : public LanguageModel |
| | { |
| | |
| |
|
| | void ShiftOrPush(std::vector<const Word*> &contextFactor, const Word &word) const; |
| |
|
| | protected: |
| | std::string m_filePath; |
| | size_t m_nGramOrder; |
| | Word m_sentenceStartWord, m_sentenceEndWord; |
| | |
| |
|
| | LanguageModelImplementation(const std::string &line); |
| |
|
| | public: |
| |
|
| | virtual ~LanguageModelImplementation() {} |
| |
|
| | void SetParameter(const std::string& key, const std::string& value); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | virtual LMResult GetValueGivenState(const std::vector<const Word*> &contextFactor, FFState &state) const; |
| |
|
| | |
| | |
| | virtual LMResult GetValueForgotState(const std::vector<const Word*> &contextFactor, FFState &outState) const = 0; |
| |
|
| | |
| | |
| | virtual void GetState(const std::vector<const Word*> &contextFactor, FFState &outState) const; |
| |
|
| | virtual const FFState *GetNullContextState() const = 0; |
| | virtual const FFState *GetBeginSentenceState() const = 0; |
| | virtual FFState *NewState(const FFState *from = NULL) const = 0; |
| |
|
| | virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const; |
| |
|
| | FFState *EvaluateWhenApplied(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const; |
| |
|
| | FFState* EvaluateWhenApplied(const ChartHypothesis& cur_hypo, int featureID, ScoreComponentCollection* accumulator) const; |
| |
|
| | void updateChartScore(float *prefixScore, float *finalScore, float score, size_t wordPos) const; |
| |
|
| | |
| | size_t GetNGramOrder() const { |
| | return m_nGramOrder; |
| | } |
| |
|
| | |
| | const Word &GetSentenceStartWord() const { |
| | return m_sentenceStartWord; |
| | } |
| | const Word &GetSentenceEndWord() const { |
| | return m_sentenceEndWord; |
| | } |
| |
|
| | const FFState* EmptyHypothesisState(const InputType &) const { |
| | return NewState(GetBeginSentenceState()); |
| | } |
| |
|
| | }; |
| |
|
| | } |
| |
|
| | #endif |
| |
|