2014-04-08 20:19:26 +04:00
|
|
|
#include "CountNonTerms.h"
|
|
|
|
#include "moses/Util.h"
|
|
|
|
#include "moses/TargetPhrase.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
CountNonTerms::CountNonTerms(const std::string &line)
|
2015-04-29 22:16:52 +03:00
|
|
|
:StatelessFeatureFunction(line,true)
|
2015-01-14 14:07:42 +03:00
|
|
|
,m_all(true)
|
|
|
|
,m_sourceSyntax(false)
|
|
|
|
,m_targetSyntax(false)
|
2014-04-08 20:19:26 +04:00
|
|
|
{
|
|
|
|
ReadParameters();
|
|
|
|
}
|
|
|
|
|
2014-07-10 01:35:59 +04:00
|
|
|
void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection &estimatedScores) const
|
2014-04-08 20:19:26 +04:00
|
|
|
{
|
|
|
|
vector<float> scores(m_numScoreComponents, 0);
|
|
|
|
size_t indScore = 0;
|
|
|
|
|
|
|
|
if (m_all) {
|
2015-01-14 14:07:42 +03:00
|
|
|
for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
|
|
|
|
const Word &word = targetPhrase.GetWord(i);
|
|
|
|
if (word.IsNonTerminal()) {
|
|
|
|
++scores[indScore];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++indScore;
|
2014-04-08 20:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_targetSyntax) {
|
2015-01-14 14:07:42 +03:00
|
|
|
for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
|
|
|
|
const Word &word = targetPhrase.GetWord(i);
|
2015-12-10 06:17:36 +03:00
|
|
|
if (word.IsNonTerminal() && word != m_options->syntax.output_default_non_terminal) {
|
2015-01-14 14:07:42 +03:00
|
|
|
++scores[indScore];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++indScore;
|
2014-04-08 20:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_sourceSyntax) {
|
2015-01-14 14:07:42 +03:00
|
|
|
for (size_t i = 0; i < sourcePhrase.GetSize(); ++i) {
|
|
|
|
const Word &word = sourcePhrase.GetWord(i);
|
2015-12-10 06:17:36 +03:00
|
|
|
if (word.IsNonTerminal() && word != m_options->syntax.input_default_non_terminal) {
|
2015-01-14 14:07:42 +03:00
|
|
|
++scores[indScore];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++indScore;
|
2014-04-08 20:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
scoreBreakdown.PlusEquals(this, scores);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CountNonTerms::SetParameter(const std::string& key, const std::string& value)
|
|
|
|
{
|
|
|
|
if (key == "all") {
|
|
|
|
m_all = Scan<bool>(value);
|
|
|
|
} else if (key == "source-syntax") {
|
2015-01-14 14:07:42 +03:00
|
|
|
m_sourceSyntax = Scan<bool>(value);
|
2014-04-08 20:19:26 +04:00
|
|
|
} else if (key == "target-syntax") {
|
2015-01-14 14:07:42 +03:00
|
|
|
m_targetSyntax = Scan<bool>(value);
|
2014-04-08 20:19:26 +04:00
|
|
|
} else {
|
|
|
|
StatelessFeatureFunction::SetParameter(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void
|
|
|
|
CountNonTerms::
|
|
|
|
Load(AllOptions::ptr const& opts)
|
|
|
|
{
|
|
|
|
m_options = opts;
|
|
|
|
}
|
|
|
|
|
2014-04-08 20:19:26 +04:00
|
|
|
|
|
|
|
}
|