mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#include <sstream>
|
|
#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;
|
|
}
|
|
|
|
}
|