blob: 1f709787f27acdb3a59ddf1efadf91b42aa9042c (
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
|
#include <vector>
#include "PhrasePenalty.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/TranslationModel/PhraseDictionary.h"
#include "util/exception.hh"
using namespace std;
namespace Moses
{
PhrasePenalty::PhrasePenalty(const std::string &line)
: StatelessFeatureFunction(1, line)
, m_perPhraseTable(false)
{
ReadParameters();
}
void PhrasePenalty::EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection &estimatedScores) const
{
if (m_perPhraseTable) {
const PhraseDictionary *pt = targetPhrase.GetContainer();
if (pt) {
size_t ptId = pt->GetId();
UTIL_THROW_IF2(ptId >= m_numScoreComponents, "Wrong number of scores");
vector<float> scores(m_numScoreComponents, 0);
scores[ptId] = 1.0f;
scoreBreakdown.Assign(this, scores);
}
} else {
scoreBreakdown.Assign(this, 1.0f);
}
}
void PhrasePenalty::SetParameter(const std::string& key, const std::string& value)
{
if (key == "per-phrase-table") {
m_perPhraseTable =Scan<bool>(value);
} else {
StatelessFeatureFunction::SetParameter(key, value);
}
}
} // namespace
|