mosesdecoder/moses/FF/PhrasePenalty.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

#include <vector>
2013-06-25 09:54:23 +04:00
#include "PhrasePenalty.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/TranslationModel/PhraseDictionary.h"
#include "util/exception.hh"
using namespace std;
2013-06-25 09:54:23 +04:00
namespace Moses
{
PhrasePenalty::PhrasePenalty(const std::string &line)
2015-01-14 14:07:42 +03:00
: StatelessFeatureFunction(1, line)
, m_perPhraseTable(false)
2013-06-26 20:19:09 +04:00
{
2013-06-25 09:54:23 +04:00
ReadParameters();
}
void PhrasePenalty::EvaluateInIsolation(const Phrase &source
2015-01-14 14:07:42 +03:00
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
2015-11-04 18:10:45 +03:00
, ScoreComponentCollection &estimatedScores) const
2013-06-25 09:54:23 +04:00
{
if (m_perPhraseTable) {
2015-01-14 14:07:42 +03:00
const PhraseDictionary *pt = targetPhrase.GetContainer();
if (pt) {
size_t ptId = pt->GetId();
UTIL_THROW_IF2(ptId >= m_numScoreComponents, "Wrong number of scores");
2015-01-14 14:07:42 +03:00
vector<float> scores(m_numScoreComponents, 0);
scores[ptId] = 1.0f;
2015-01-14 14:07:42 +03:00
scoreBreakdown.Assign(this, scores);
}
2015-01-14 14:07:42 +03:00
} else {
scoreBreakdown.Assign(this, 1.0f);
}
2013-06-25 09:54:23 +04:00
}
void PhrasePenalty::SetParameter(const std::string& key, const std::string& value)
{
if (key == "per-phrase-table") {
2015-01-14 14:07:42 +03:00
m_perPhraseTable =Scan<bool>(value);
} else {
StatelessFeatureFunction::SetParameter(key, value);
}
}
2013-06-25 09:54:23 +04:00
} // namespace