mosesdecoder/moses/FF/StatefulFeatureFunction.h
Ulrich Germann e4f5c69109 One step closer to eliminating the requirement to provide num-features=... in the config file.
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.
2015-04-29 20:16:52 +01:00

67 lines
1.8 KiB
C++

#pragma once
#include "FeatureFunction.h"
#include "moses/Syntax/SHyperedge.h"
namespace Moses
{
class FFState;
/** base class for all stateful feature functions.
* eg. LM, distortion penalty
*/
class StatefulFeatureFunction: public FeatureFunction
{
//All statefull FFs
static std::vector<const StatefulFeatureFunction*> m_statefulFFs;
public:
static const std::vector<const StatefulFeatureFunction*>&
GetStatefulFeatureFunctions() {
return m_statefulFFs;
}
StatefulFeatureFunction(const std::string &line, bool registerNow);
StatefulFeatureFunction(size_t numScoreComponents, const std::string &line);
/**
* \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(
const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const = 0;
virtual FFState* EvaluateWhenApplied(
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 */,
ScoreComponentCollection* accumulator) const {
assert(false);
return 0; /* FIXME */
}
//! return the state associated with the empty hypothesis for a given sentence
virtual const FFState* EmptyHypothesisState(const InputType &input) const = 0;
bool IsStateless() const {
return false;
}
};
}