blob: f944de23a0c0a562dd3c1117c3a0d04f3b6e0315 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "SkeletonLM.h"
#include "moses/FactorCollection.h"
using namespace std;
namespace Moses
{
SkeletonLM::SkeletonLM(const std::string &line)
:LanguageModelSingleFactor(line)
{
ReadParameters();
UTIL_THROW_IF2(m_nGramOrder == NOT_FOUND, "Must set order");
UTIL_THROW_IF2(m_nGramOrder <= 1, "Ngram order must be more than 1");
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;
}
SkeletonLM::~SkeletonLM()
{
}
LMResult SkeletonLM::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;
}
}
|