mosesdecoder/moses/FF/SourceGHKMTreeInputMatchFeature.cpp

76 lines
2.2 KiB
C++
Raw Normal View History

2014-06-21 00:00:16 +04:00
#include <map>
#include <vector>
#include <cassert>
2014-06-21 00:00:16 +04:00
#include "SourceGHKMTreeInputMatchFeature.h"
#include "moses/StaticData.h"
#include "moses/InputFileStream.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/Hypothesis.h"
#include "moses/ChartHypothesis.h"
#include "moses/Factor.h"
#include "moses/FactorCollection.h"
#include "moses/InputPath.h"
2014-06-21 00:25:14 +04:00
#include "moses/TreeInput.h"
2014-06-21 00:00:16 +04:00
using namespace std;
namespace Moses
{
SourceGHKMTreeInputMatchFeature::SourceGHKMTreeInputMatchFeature(const std::string &line)
: StatelessFeatureFunction(2, line)
{
std::cerr << GetScoreProducerDescription() << "Initializing feature...";
ReadParameters();
std::cerr << " Done." << std::endl;
}
void SourceGHKMTreeInputMatchFeature::SetParameter(const std::string& key, const std::string& value)
{
UTIL_THROW(util::Exception, GetScoreProducerDescription() << ": Unknown parameter " << key << "=" << value);
}
// assumes that source-side syntax labels are stored in the target non-terminal field of the rules
void SourceGHKMTreeInputMatchFeature::EvaluateWithSourceContext(const InputType &input
2015-01-14 14:07:42 +03:00
, const InputPath &inputPath
, const TargetPhrase &targetPhrase
, const StackVec *stackVec
, ScoreComponentCollection &scoreBreakdown
2015-11-04 18:10:45 +03:00
, ScoreComponentCollection *estimatedScores) const
2014-06-21 00:00:16 +04:00
{
2015-10-25 16:37:59 +03:00
const Range& range = inputPath.GetWordsRange();
size_t startPos = range.GetStartPos();
size_t endPos = range.GetEndPos();
2014-06-21 00:00:16 +04:00
const TreeInput& treeInput = static_cast<const TreeInput&>(input);
const NonTerminalSet& treeInputLabels = treeInput.GetLabelSet(startPos,endPos);
const Word& lhsLabel = targetPhrase.GetTargetLHS();
const StaticData& staticData = StaticData::Instance();
2015-12-12 03:00:41 +03:00
std::vector<float> newScores(m_numScoreComponents,0.0);
2015-12-10 06:17:36 +03:00
// m_numScoreComponents == 2 // first fires for matches, second for mismatches
2014-06-21 00:00:16 +04:00
2015-12-12 03:00:41 +03:00
if ( (treeInputLabels.find(lhsLabel) != treeInputLabels.end())
2015-12-10 06:17:36 +03:00
&& (lhsLabel != m_options->syntax.output_default_non_terminal) ) {
2014-06-21 00:00:16 +04:00
// match
newScores[0] = 1.0;
} else {
// mismatch
newScores[1] = 1.0;
}
scoreBreakdown.PlusEquals(this, newScores);
}
2015-12-10 06:17:36 +03:00
void
SourceGHKMTreeInputMatchFeature::
Load(AllOptions::ptr const& opts)
{
m_options = opts;
// m_output_default_nonterminal = opts->syntax.output_default_non_terminal;
}
2014-06-21 00:00:16 +04:00
}