blob: 902ba64fcfd196f103e218d43f00ce38f5d90919 (
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
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <stdexcept>
#include "InputFeature.h"
#include "moses/Util.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/InputPath.h"
#include "moses/StaticData.h"
#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
using namespace std;
namespace Moses
{
InputFeature *InputFeature::s_instance = NULL;
InputFeature::InputFeature(const std::string &line)
: StatelessFeatureFunction(line,true)
, m_numRealWordCount(0)
{
m_numInputScores = this->m_numScoreComponents;
ReadParameters();
UTIL_THROW_IF2(s_instance, "Can only have 1 input feature");
s_instance = this;
}
void InputFeature::Load()
{
const PhraseDictionary *pt = PhraseDictionary::GetColl()[0];
const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt);
m_legacy = (ptBin != NULL);
}
void InputFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "num-input-features") {
m_numInputScores = Scan<size_t>(value);
} else if (key == "real-word-count") {
m_numRealWordCount = Scan<size_t>(value);
} else {
StatelessFeatureFunction::SetParameter(key, value);
}
}
void InputFeature::EvaluateWithSourceContext(const InputType &input
, const InputPath &inputPath
, const TargetPhrase &targetPhrase
, const StackVec *stackVec
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection *estimatedScore) const
{
if (m_legacy) {
//binary phrase-table does input feature itself
return;
} else if (input.GetType() == WordLatticeInput) {
const ScorePair *scores = inputPath.GetInputScore();
if (scores) {
scoreBreakdown.PlusEquals(this, *scores);
}
}
}
} // namespace
|