mosesdecoder/moses/FF/StatefulFeatureFunction.h

97 lines
2.8 KiB
C
Raw Permalink Normal View History

// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
2013-05-24 22:11:15 +04:00
#pragma once
#include "FeatureFunction.h"
2013-05-24 22:11:15 +04:00
namespace Moses
{
2013-09-01 19:58:23 +04:00
class FFState;
2013-05-24 22:11:15 +04:00
namespace Syntax
{
2015-11-27 15:20:38 +03:00
struct SHyperedge;
}
2013-05-24 22:11:15 +04:00
/** base class for all stateful feature functions.
2013-05-29 21:16:15 +04:00
* eg. LM, distortion penalty
2013-05-24 22:11:15 +04:00
*/
class StatefulFeatureFunction: public FeatureFunction
{
//All statefull FFs
static std::vector<const StatefulFeatureFunction*> m_statefulFFs;
public:
2015-02-19 15:27:23 +03:00
static const std::vector<const StatefulFeatureFunction*>&
GetStatefulFeatureFunctions() {
2013-05-29 21:16:15 +04:00
return m_statefulFFs;
}
2013-05-24 22:11:15 +04:00
StatefulFeatureFunction(const std::string &line, bool registerNow);
StatefulFeatureFunction(size_t numScoreComponents, const std::string &line);
2013-05-24 22:11:15 +04:00
/**
* \brief This interface should be implemented.
* Notes: When evaluating the value of this feature function, you should avoid
* calling hypo.GetPrevHypo(). If you need something from the "previous"
* hypothesis, you should store it in an FFState object which will be passed
* in as prev_state. If you don't do this, you will get in trouble.
*/
virtual FFState* EvaluateWhenApplied(
2013-05-24 22:11:15 +04:00
const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const = 0;
// virtual FFState* EvaluateWhenAppliedWithContext(
// ttasksptr const& ttasks,
// const Hypothesis& cur_hypo,
// const FFState* prev_state,
// ScoreComponentCollection* accumulator) const {
// return EvaluateWhenApplied(cur_hypo, prev_state, accumulator);
// }
virtual FFState* EvaluateWhenApplied(
2013-05-24 22:11:15 +04:00
const ChartHypothesis& /* cur_hypo */,
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const = 0;
virtual FFState* EvaluateWhenApplied(
const Syntax::SHyperedge& /* cur_hypo */,
int /* featureID - used to index the state in the previous hypotheses */,
2015-01-14 14:07:42 +03:00
ScoreComponentCollection* accumulator) const {
assert(false);
return 0; /* FIXME */
}
2013-05-24 22:11:15 +04:00
//! return the state associated with the empty hypothesis for a given sentence
virtual const FFState* EmptyHypothesisState(const InputType &input) const = 0;
2013-05-29 21:16:15 +04:00
bool IsStateless() const {
return false;
}
2013-05-25 02:18:38 +04:00
2015-11-20 03:00:42 +03:00
virtual void
EvaluateInIsolation
2015-11-20 03:00:42 +03:00
(Phrase const& source, TargetPhrase const& targetPhrase,
ScoreComponentCollection &scoreBreakdown,
ScoreComponentCollection &estimatedScores) const {}
2015-11-20 03:00:42 +03:00
virtual void
EvaluateWithSourceContext
2015-11-20 03:00:42 +03:00
(InputType const&input, InputPath const& inputPath, TargetPhrase const& targetPhrase,
StackVec const* stackVec, ScoreComponentCollection &scoreBreakdown,
ScoreComponentCollection *estimatedFutureScore = NULL) const {}
2015-11-20 03:00:42 +03:00
virtual void
EvaluateTranslationOptionListWithSourceContext
(const InputType &input, const TranslationOptionList &translationOptionList) const {}
2013-05-24 22:11:15 +04:00
};
}