mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-27 03:49:57 +03:00
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
|
|
||
|
#include "DALM.h"
|
||
|
#include "moses/FactorCollection.h"
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
namespace Moses
|
||
|
{
|
||
|
LanguageModelDALM::LanguageModelDALM(const std::string &line)
|
||
|
:LanguageModelSingleFactor(line)
|
||
|
{
|
||
|
ReadParameters();
|
||
|
|
||
|
if (m_factorType == NOT_FOUND) {
|
||
|
m_factorType = 0;
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
LanguageModelDALM::~LanguageModelDALM()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
LMResult LanguageModelDALM::GetValue(const vector<const Word*> &contextFactor, State* finalState) const
|
||
|
{
|
||
|
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()) {
|
||
|
factor = contextFactor.back()->GetFactor(m_factorType);
|
||
|
} else {
|
||
|
factor = NULL;
|
||
|
}
|
||
|
|
||
|
(*finalState) = (State*) factor;
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|