2014-08-05 13:26:42 +04:00
|
|
|
#include <vector>
|
2013-06-25 09:54:23 +04:00
|
|
|
#include "PhrasePenalty.h"
|
|
|
|
#include "moses/ScoreComponentCollection.h"
|
2014-08-05 13:26:42 +04:00
|
|
|
#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();
|
|
|
|
}
|
|
|
|
|
2014-07-10 01:35:59 +04:00
|
|
|
void PhrasePenalty::EvaluateInIsolation(const Phrase &source
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection &estimatedFutureScore) const
|
2013-06-25 09:54:23 +04:00
|
|
|
{
|
2014-08-05 13:26:42 +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");
|
2014-08-05 13:26:42 +04:00
|
|
|
|
2015-01-14 14:07:42 +03:00
|
|
|
vector<float> scores(m_numScoreComponents, 0);
|
|
|
|
scores[ptId] = 1.0f;
|
2014-08-05 13:26:42 +04:00
|
|
|
|
2015-01-14 14:07:42 +03:00
|
|
|
scoreBreakdown.Assign(this, scores);
|
|
|
|
}
|
2014-08-05 13:26:42 +04:00
|
|
|
|
2015-01-14 14:07:42 +03:00
|
|
|
} else {
|
|
|
|
scoreBreakdown.Assign(this, 1.0f);
|
2014-08-05 13:26:42 +04:00
|
|
|
}
|
2013-06-25 09:54:23 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 13:26:42 +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 {
|
2014-08-05 13:26:42 +04:00
|
|
|
StatelessFeatureFunction::SetParameter(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 09:54:23 +04:00
|
|
|
} // namespace
|
|
|
|
|