mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-27 20:12:02 +03:00
e4f5c69109
Some FF (Mmsapt, LexicalReordering, Many single-value FF) provide this number during "registration"; when missing, a default weight vector of uniform 1.0 is automatically generated. This eliminates the need for the user to figure out what the exact number of features is for each FF, which can get complicated, e.g. in the case of Mmsapt/PhraseDictionaryBitextSampling.
77 lines
1.9 KiB
C++
77 lines
1.9 KiB
C++
#include "CountNonTerms.h"
|
|
#include "moses/Util.h"
|
|
#include "moses/TargetPhrase.h"
|
|
#include "moses/StaticData.h"
|
|
|
|
using namespace std;
|
|
|
|
namespace Moses
|
|
{
|
|
CountNonTerms::CountNonTerms(const std::string &line)
|
|
:StatelessFeatureFunction(line,true)
|
|
,m_all(true)
|
|
,m_sourceSyntax(false)
|
|
,m_targetSyntax(false)
|
|
{
|
|
ReadParameters();
|
|
}
|
|
|
|
void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase
|
|
, const TargetPhrase &targetPhrase
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
, ScoreComponentCollection &estimatedFutureScore) const
|
|
{
|
|
const StaticData &staticData = StaticData::Instance();
|
|
|
|
vector<float> scores(m_numScoreComponents, 0);
|
|
size_t indScore = 0;
|
|
|
|
if (m_all) {
|
|
for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
|
|
const Word &word = targetPhrase.GetWord(i);
|
|
if (word.IsNonTerminal()) {
|
|
++scores[indScore];
|
|
}
|
|
}
|
|
++indScore;
|
|
}
|
|
|
|
if (m_targetSyntax) {
|
|
for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
|
|
const Word &word = targetPhrase.GetWord(i);
|
|
if (word.IsNonTerminal() && word != staticData.GetOutputDefaultNonTerminal()) {
|
|
++scores[indScore];
|
|
}
|
|
}
|
|
++indScore;
|
|
}
|
|
|
|
if (m_sourceSyntax) {
|
|
for (size_t i = 0; i < sourcePhrase.GetSize(); ++i) {
|
|
const Word &word = sourcePhrase.GetWord(i);
|
|
if (word.IsNonTerminal() && word != staticData.GetInputDefaultNonTerminal()) {
|
|
++scores[indScore];
|
|
}
|
|
}
|
|
++indScore;
|
|
}
|
|
|
|
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") {
|
|
m_sourceSyntax = Scan<bool>(value);
|
|
} else if (key == "target-syntax") {
|
|
m_targetSyntax = Scan<bool>(value);
|
|
} else {
|
|
StatelessFeatureFunction::SetParameter(key, value);
|
|
}
|
|
}
|
|
|
|
|
|
}
|