#include #include "PhraseLengthFeature.h" #include "Hypothesis.h" #include "ScoreComponentCollection.h" #include "TranslationOption.h" namespace Moses { using namespace std; PhraseLengthFeature::PhraseLengthFeature(const std::string &line) :StatelessFeatureFunction("pl", ScoreProducer::unlimited, line) { } void PhraseLengthFeature::Evaluate( const PhraseBasedFeatureContext& context, ScoreComponentCollection* accumulator) const { // get length of source and target phrase size_t targetLength = context.GetTargetPhrase().GetSize(); size_t sourceLength = context.GetTranslationOption().GetSourceWordsRange().GetNumWordsCovered(); // create feature names stringstream nameSource; nameSource << "s" << sourceLength; stringstream nameTarget; nameTarget << "t" << targetLength; stringstream nameBoth; nameBoth << sourceLength << "," << targetLength; // increase feature counts accumulator->PlusEquals(this,nameSource.str(),1); accumulator->PlusEquals(this,nameTarget.str(),1); accumulator->PlusEquals(this,nameBoth.str(),1); //cerr << nameSource.str() << " " << nameTarget.str() << " " << nameBoth.str() << endl; } }