refactor input score handling to use Evaluate(inputtype, inputpath). Not a placeholder factor anymore

This commit is contained in:
Hieu Hoang 2013-08-14 16:53:06 +01:00
parent 2b030339e0
commit abfe02f154
5 changed files with 28 additions and 30 deletions

View File

@ -1,6 +1,8 @@
#include <stdexcept>
#include "InputFeature.h"
#include "moses/Util.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/InputPath.h"
#include "util/check.hh"
using namespace std;
@ -10,20 +12,30 @@ namespace Moses
InputFeature::InputFeature(const std::string &line)
:StatelessFeatureFunction("InputFeature", line)
{
for (size_t i = 0; i < m_args.size(); ++i) {
const vector<string> &args = m_args[i];
CHECK(args.size() == 2);
ReadParameters();
}
if (args[0] == "num-input-features") {
m_numInputScores = Scan<size_t>(args[1]);
} else if (args[0] == "real-word-count") {
m_numRealWordCount = Scan<size_t>(args[1]);
} else {
throw "Unknown argument " + args[0];
}
}
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::Evaluate(const InputType &input
, const InputPath &inputPath
, ScoreComponentCollection &scoreBreakdown) const
{
const ScoreComponentCollection *scores = inputPath.GetInputScore();
if (scores) {
}
}
} // namespace

View File

@ -16,6 +16,8 @@ protected:
public:
InputFeature(const std::string &line);
void SetParameter(const std::string& key, const std::string& value);
bool IsUseable(const FactorMask &mask) const {
return true;
}
@ -27,6 +29,9 @@ public:
return m_numRealWordCount;
}
virtual void Evaluate(const InputType &input
, const InputPath &inputPath
, ScoreComponentCollection &scoreBreakdown) const;
};

View File

@ -149,20 +149,6 @@ void TargetPhrase::SetXMLScore(float score)
m_scoreBreakdown.Assign(prod, scoreVector);
}
void TargetPhrase::SetInputScore(const Scores &scoreVector)
{
//we use an existing score producer to figure out information for score setting (number of scores and weights)
const StaticData &staticData = StaticData::Instance();
const FeatureFunction* prod = staticData.GetPhraseDictionaries()[0];
//expand the input weight vector
CHECK(scoreVector.size() <= prod->GetNumScoreComponents());
Scores sizedScoreVector = scoreVector;
sizedScoreVector.resize(prod->GetNumScoreComponents(),0.0f);
m_scoreBreakdown.Assign(prod, sizedScoreVector);
}
void TargetPhrase::SetAlignmentInfo(const StringPiece &alignString)
{
AlignmentInfo::CollType alignTerm, alignNonTerm;

View File

@ -72,7 +72,6 @@ public:
// used to set translation or gen score
void SetXMLScore(float score);
void SetInputScore(const Scores &scoreVector);
#ifdef HAVE_PROTOBUF
void WriteToRulePB(hgmert::Rule* pb) const;

View File

@ -257,10 +257,6 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const InputPath &inputPa
targetPhrase.GetScoreBreakdown().Assign(unknownWordPenaltyProducer, unknownScore);
if (inputScores != NULL) {
targetPhrase.SetInputScore(*inputScores);
}
// source phrase
const Phrase &sourcePhrase = inputPath.GetPhrase();
m_unksrcs.push_back(&sourcePhrase);