00001 #include <vector>
00002 #include "PhrasePenalty.h"
00003 #include "moses/ScoreComponentCollection.h"
00004 #include "moses/TranslationModel/PhraseDictionary.h"
00005 #include "util/exception.hh"
00006
00007 using namespace std;
00008
00009 namespace Moses
00010 {
00011 PhrasePenalty::PhrasePenalty(const std::string &line)
00012 : StatelessFeatureFunction(1, line)
00013 , m_perPhraseTable(false)
00014 {
00015 ReadParameters();
00016 }
00017
00018 void PhrasePenalty::EvaluateInIsolation(const Phrase &source
00019 , const TargetPhrase &targetPhrase
00020 , ScoreComponentCollection &scoreBreakdown
00021 , ScoreComponentCollection &estimatedScores) const
00022 {
00023 if (m_perPhraseTable) {
00024 const PhraseDictionary *pt = targetPhrase.GetContainer();
00025 if (pt) {
00026 size_t ptId = pt->GetId();
00027 UTIL_THROW_IF2(ptId >= m_numScoreComponents, "Wrong number of scores");
00028
00029 vector<float> scores(m_numScoreComponents, 0);
00030 scores[ptId] = 1.0f;
00031
00032 scoreBreakdown.Assign(this, scores);
00033 }
00034
00035 } else {
00036 scoreBreakdown.Assign(this, 1.0f);
00037 }
00038 }
00039
00040 void PhrasePenalty::SetParameter(const std::string& key, const std::string& value)
00041 {
00042 if (key == "per-phrase-table") {
00043 m_perPhraseTable =Scan<bool>(value);
00044 } else {
00045 StatelessFeatureFunction::SetParameter(key, value);
00046 }
00047 }
00048
00049
00050 }
00051