00001 00002 #include "ExampleLM.h" 00003 #include "moses/FactorCollection.h" 00004 00005 using namespace std; 00006 00007 namespace Moses 00008 { 00009 ExampleLM::ExampleLM(const std::string &line) 00010 :LanguageModelSingleFactor(line) 00011 { 00012 ReadParameters(); 00013 00014 UTIL_THROW_IF2(m_nGramOrder == NOT_FOUND, "Must set order"); 00015 UTIL_THROW_IF2(m_nGramOrder <= 1, "Ngram order must be more than 1"); 00016 00017 FactorCollection &factorCollection = FactorCollection::Instance(); 00018 00019 // needed by parent language model classes. Why didn't they set these themselves? 00020 m_sentenceStart = factorCollection.AddFactor(Output, m_factorType, BOS_); 00021 m_sentenceStartWord[m_factorType] = m_sentenceStart; 00022 00023 m_sentenceEnd = factorCollection.AddFactor(Output, m_factorType, EOS_); 00024 m_sentenceEndWord[m_factorType] = m_sentenceEnd; 00025 } 00026 00027 ExampleLM::~ExampleLM() 00028 { 00029 } 00030 00031 LMResult ExampleLM::GetValue(const vector<const Word*> &contextFactor, State* finalState) const 00032 { 00033 LMResult ret; 00034 ret.score = contextFactor.size(); 00035 ret.unknown = false; 00036 00037 // use last word as state info 00038 const Factor *factor; 00039 size_t hash_value(const Factor &f); 00040 if (contextFactor.size()) { 00041 factor = contextFactor.back()->GetFactor(m_factorType); 00042 } else { 00043 factor = NULL; 00044 } 00045 00046 (*finalState) = (State*) factor; 00047 00048 return ret; 00049 } 00050 00051 } 00052 00053 00054