mosesdecoder/moses/FF/PhraseLengthFeature.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

#include <sstream>
#include "PhraseLengthFeature.h"
2013-05-24 21:02:49 +04:00
#include "moses/Hypothesis.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/TranslationOption.h"
2015-10-03 00:15:03 +03:00
#include "util/string_stream.hh"
2013-05-29 21:16:15 +04:00
namespace Moses
{
using namespace std;
PhraseLengthFeature::PhraseLengthFeature(const std::string &line)
:StatelessFeatureFunction(0, line)
{
ReadParameters();
}
void PhraseLengthFeature::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
{
// get length of source and target phrase
size_t targetLength = targetPhrase.GetSize();
size_t sourceLength = source.GetSize();
// create feature names
util::StringStream nameSource;
nameSource << "s" << sourceLength;
util::StringStream nameTarget;
nameTarget << "t" << targetLength;
util::StringStream nameBoth;
nameBoth << sourceLength << "," << targetLength;
// increase feature counts
scoreBreakdown.PlusEquals(this,nameSource.str(),1);
scoreBreakdown.PlusEquals(this,nameTarget.str(),1);
scoreBreakdown.PlusEquals(this,nameBoth.str(),1);
//cerr << nameSource.str() << " " << nameTarget.str() << " " << nameBoth.str() << endl;
}
}