mosesdecoder/moses/FF/ExampleStatefulFF.cpp

84 lines
2.6 KiB
C++
Raw Permalink Normal View History

2013-09-25 23:19:05 +04:00
#include <vector>
2017-04-26 15:10:32 +03:00
#include "ExampleStatefulFF.h"
2013-09-25 23:19:05 +04:00
#include "moses/ScoreComponentCollection.h"
#include "moses/Hypothesis.h"
using namespace std;
2013-09-01 19:58:23 +04:00
namespace Moses
{
2013-09-25 23:19:05 +04:00
2014-06-16 03:55:36 +04:00
////////////////////////////////////////////////////////////////
2017-04-26 15:10:32 +03:00
ExampleStatefulFF::ExampleStatefulFF(const std::string &line)
2014-06-16 03:55:36 +04:00
:StatefulFeatureFunction(3, line)
{
ReadParameters();
}
// An empty implementation of this function is provided by StatefulFeatureFunction.
2015-11-20 03:00:42 +03:00
// Unless you are actually implementing this, please remove it from your
// implementation (and the declaration in the header file to reduce code clutter.
2017-04-26 15:10:32 +03:00
void ExampleStatefulFF::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
2013-09-25 23:19:05 +04:00
{}
// An empty implementation of this function is provided by StatefulFeatureFunction.
2015-11-20 03:00:42 +03:00
// Unless you are actually implementing this, please remove it from your
// implementation (and the declaration in the header file to reduce code clutter.
2017-04-26 15:10:32 +03:00
void ExampleStatefulFF::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
{}
// An empty implementation of this function is provided by StatefulFeatureFunction.
2015-11-20 03:00:42 +03:00
// Unless you are actually implementing this, please remove it from your
// implementation (and the declaration in the header file to reduce code clutter.
2017-04-26 15:10:32 +03:00
void ExampleStatefulFF::EvaluateTranslationOptionListWithSourceContext
(const InputType &input, const TranslationOptionList &translationOptionList) const
2013-09-25 23:19:05 +04:00
{}
2017-04-26 15:10:32 +03:00
FFState* ExampleStatefulFF::EvaluateWhenApplied(
2013-09-27 12:35:24 +04:00
const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const
2013-09-25 23:19:05 +04:00
{
2013-09-27 12:35:24 +04:00
// dense scores
vector<float> newScores(m_numScoreComponents);
newScores[0] = 1.5;
newScores[1] = 0.3;
newScores[2] = 0.4;
accumulator->PlusEquals(this, newScores);
// sparse scores
accumulator->PlusEquals(this, "sparse-name", 2.4);
// int targetLen = cur_hypo.GetCurrTargetPhrase().GetSize(); // ??? [UG]
2017-04-26 15:10:32 +03:00
return new ExampleState(0);
2013-09-25 23:19:05 +04:00
}
2017-04-26 15:10:32 +03:00
FFState* ExampleStatefulFF::EvaluateWhenApplied(
2013-09-27 12:35:24 +04:00
const ChartHypothesis& /* cur_hypo */,
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const
{
2017-04-26 15:10:32 +03:00
return new ExampleState(0);
2013-09-27 12:35:24 +04:00
}
2013-09-01 19:58:23 +04:00
2017-04-26 15:10:32 +03:00
void ExampleStatefulFF::SetParameter(const std::string& key, const std::string& value)
2014-06-18 12:08:19 +04:00
{
if (key == "arg") {
// set value here
} else {
StatefulFeatureFunction::SetParameter(key, value);
}
}
2013-09-01 19:58:23 +04:00
}