00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef moses_LanguageModelImplementation_h
00022 #define moses_LanguageModelImplementation_h
00023
00024 #include <string>
00025 #include <vector>
00026 #include "moses/Factor.h"
00027 #include "moses/TypeDef.h"
00028 #include "moses/Util.h"
00029 #include "moses/Word.h"
00030 #include "Base.h"
00031
00032 #include <boost/shared_ptr.hpp>
00033
00034 namespace Moses
00035 {
00036
00037 class FactorCollection;
00038 class Factor;
00039 class Phrase;
00040
00042 struct LMResult {
00043
00044 float score;
00045
00046 bool unknown;
00047 };
00048
00050 class LanguageModelImplementation : public LanguageModel
00051 {
00052
00053
00054 void ShiftOrPush(std::vector<const Word*> &contextFactor, const Word &word) const;
00055
00056 protected:
00057 std::string m_filePath;
00058 size_t m_nGramOrder;
00059 Word m_sentenceStartWord, m_sentenceEndWord;
00060
00061
00062 LanguageModelImplementation(const std::string &line);
00063
00064 public:
00065
00066 virtual ~LanguageModelImplementation() {}
00067
00068 void SetParameter(const std::string& key, const std::string& value);
00069
00070
00071
00072
00073
00074
00075 virtual LMResult GetValueGivenState(const std::vector<const Word*> &contextFactor, FFState &state) const;
00076
00077
00078
00079 virtual LMResult GetValueForgotState(const std::vector<const Word*> &contextFactor, FFState &outState) const = 0;
00080
00082
00083 virtual void GetState(const std::vector<const Word*> &contextFactor, FFState &outState) const;
00084
00085 virtual const FFState *GetNullContextState() const = 0;
00086 virtual const FFState *GetBeginSentenceState() const = 0;
00087 virtual FFState *NewState(const FFState *from = NULL) const = 0;
00088
00089 virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const;
00090
00091 FFState *EvaluateWhenApplied(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const;
00092
00093 FFState* EvaluateWhenApplied(const ChartHypothesis& cur_hypo, int featureID, ScoreComponentCollection* accumulator) const;
00094
00095 void updateChartScore(float *prefixScore, float *finalScore, float score, size_t wordPos) const;
00096
00098 size_t GetNGramOrder() const {
00099 return m_nGramOrder;
00100 }
00101
00103 const Word &GetSentenceStartWord() const {
00104 return m_sentenceStartWord;
00105 }
00106 const Word &GetSentenceEndWord() const {
00107 return m_sentenceEndWord;
00108 }
00109
00110 const FFState* EmptyHypothesisState(const InputType &) const {
00111 return NewState(GetBeginSentenceState());
00112 }
00113
00114 };
00115
00116 }
00117
00118 #endif