2011-08-15 07:40:28 +04:00
|
|
|
#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"
|
2011-08-15 07:40:28 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2011-08-15 07:40:28 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2013-01-02 20:54:38 +04:00
|
|
|
PhraseLengthFeature::PhraseLengthFeature(const std::string &line)
|
2013-10-29 22:44:33 +04:00
|
|
|
:StatelessFeatureFunction(0, line)
|
2013-01-02 20:54:38 +04:00
|
|
|
{
|
2013-06-20 16:06:03 +04:00
|
|
|
ReadParameters();
|
2013-01-02 20:54:38 +04:00
|
|
|
}
|
|
|
|
|
2013-05-28 13:51:28 +04:00
|
|
|
void PhraseLengthFeature::Evaluate(const Phrase &source
|
2013-05-29 21:16:15 +04:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection &estimatedFutureScore) const
|
2011-08-15 07:40:28 +04:00
|
|
|
{
|
|
|
|
// get length of source and target phrase
|
2013-05-24 15:07:50 +04:00
|
|
|
size_t targetLength = targetPhrase.GetSize();
|
2013-05-28 14:38:18 +04:00
|
|
|
size_t sourceLength = source.GetSize();
|
2011-08-15 07:40:28 +04:00
|
|
|
|
|
|
|
// create feature names
|
|
|
|
stringstream nameSource;
|
|
|
|
nameSource << "s" << sourceLength;
|
|
|
|
|
|
|
|
stringstream nameTarget;
|
|
|
|
nameTarget << "t" << targetLength;
|
|
|
|
|
|
|
|
stringstream nameBoth;
|
|
|
|
nameBoth << sourceLength << "," << targetLength;
|
|
|
|
|
|
|
|
// increase feature counts
|
2013-05-24 15:07:50 +04:00
|
|
|
scoreBreakdown.PlusEquals(this,nameSource.str(),1);
|
|
|
|
scoreBreakdown.PlusEquals(this,nameTarget.str(),1);
|
|
|
|
scoreBreakdown.PlusEquals(this,nameBoth.str(),1);
|
2011-08-15 07:40:28 +04:00
|
|
|
|
|
|
|
//cerr << nameSource.str() << " " << nameTarget.str() << " " << nameBoth.str() << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|