mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
38 lines
1.0 KiB
C++
38 lines
1.0 KiB
C++
#include <sstream>
|
|
#include "PhraseLengthFeature.h"
|
|
#include "Hypothesis.h"
|
|
#include "ScoreComponentCollection.h"
|
|
#include "TranslationOption.h"
|
|
|
|
namespace Moses {
|
|
|
|
using namespace std;
|
|
|
|
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;
|
|
}
|
|
|
|
}
|