mosesdecoder/moses/LM/ExampleLM.cpp

55 lines
1.2 KiB
C++
Raw Normal View History

2013-09-25 01:26:51 +04:00
2017-04-26 15:10:32 +03:00
#include "ExampleLM.h"
2013-09-25 01:26:51 +04:00
#include "moses/FactorCollection.h"
using namespace std;
namespace Moses
{
2017-04-26 15:10:32 +03:00
ExampleLM::ExampleLM(const std::string &line)
:LanguageModelSingleFactor(line)
2013-09-25 01:26:51 +04:00
{
ReadParameters();
2016-11-15 02:43:19 +03:00
UTIL_THROW_IF2(m_nGramOrder == NOT_FOUND, "Must set order");
UTIL_THROW_IF2(m_nGramOrder <= 1, "Ngram order must be more than 1");
2013-09-25 01:26:51 +04:00
FactorCollection &factorCollection = FactorCollection::Instance();
// needed by parent language model classes. Why didn't they set these themselves?
m_sentenceStart = factorCollection.AddFactor(Output, m_factorType, BOS_);
m_sentenceStartWord[m_factorType] = m_sentenceStart;
m_sentenceEnd = factorCollection.AddFactor(Output, m_factorType, EOS_);
m_sentenceEndWord[m_factorType] = m_sentenceEnd;
}
2017-04-26 15:10:32 +03:00
ExampleLM::~ExampleLM()
2013-09-25 01:26:51 +04:00
{
}
2017-04-26 15:10:32 +03:00
LMResult ExampleLM::GetValue(const vector<const Word*> &contextFactor, State* finalState) const
2013-09-25 01:26:51 +04:00
{
LMResult ret;
ret.score = contextFactor.size();
ret.unknown = false;
// use last word as state info
const Factor *factor;
size_t hash_value(const Factor &f);
if (contextFactor.size()) {
2013-09-27 12:35:24 +04:00
factor = contextFactor.back()->GetFactor(m_factorType);
} else {
factor = NULL;
2013-09-25 01:26:51 +04:00
}
(*finalState) = (State*) factor;
return ret;
}
}