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"
|
2015-10-03 00:15:03 +03:00
|
|
|
#include "util/string_stream.hh"
|
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
|
|
|
}
|
|
|
|
|
2014-07-10 01:35:59 +04:00
|
|
|
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
|
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
|
2015-10-03 02:33:38 +03:00
|
|
|
util::StringStream nameSource;
|
2011-08-15 07:40:28 +04:00
|
|
|
nameSource << "s" << sourceLength;
|
|
|
|
|
2015-10-03 02:33:38 +03:00
|
|
|
util::StringStream nameTarget;
|
2011-08-15 07:40:28 +04:00
|
|
|
nameTarget << "t" << targetLength;
|
|
|
|
|
2015-10-03 02:33:38 +03:00
|
|
|
util::StringStream nameBoth;
|
2011-08-15 07:40:28 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|