|
|
|
#ifndef moses_FeatureFunction_h |
|
#define moses_FeatureFunction_h |
|
|
|
#include <vector> |
|
#include <set> |
|
#include <string> |
|
#include "moses/FeatureVector.h" |
|
#include "moses/TypeDef.h" |
|
#include "moses/parameters/AllOptions.h" |
|
#include <boost/shared_ptr.hpp> |
|
|
|
namespace Moses |
|
{ |
|
|
|
class AllOptions; |
|
class Phrase; |
|
class TargetPhrase; |
|
class TranslationOptionList; |
|
class TranslationOption; |
|
class Hypothesis; |
|
class ChartHypothesis; |
|
class InputType; |
|
class ScoreComponentCollection; |
|
class Bitmap; |
|
class Range; |
|
class FactorMask; |
|
class InputPath; |
|
class StackVec; |
|
class DistortionScoreProducer; |
|
class TranslationTask; |
|
|
|
|
|
|
|
class FeatureFunction |
|
{ |
|
protected: |
|
|
|
static std::vector<FeatureFunction*> s_staticColl; |
|
|
|
std::string m_description, m_argLine; |
|
std::vector<std::vector<std::string> > m_args; |
|
bool m_tuneable; |
|
bool m_requireSortingAfterSourceContext; |
|
size_t m_verbosity; |
|
size_t m_numScoreComponents; |
|
size_t m_index; |
|
std::vector<bool> m_tuneableComponents; |
|
size_t m_numTuneableComponents; |
|
AllOptions::ptr m_options; |
|
|
|
static std::multiset<std::string> description_counts; |
|
|
|
public: |
|
static void Register(FeatureFunction* ff); |
|
private: |
|
|
|
void ParseLine(const std::string &line); |
|
|
|
public: |
|
static const std::vector<FeatureFunction*>& GetFeatureFunctions() { |
|
return s_staticColl; |
|
} |
|
|
|
static FeatureFunction &FindFeatureFunction(const std::string& name); |
|
static void Destroy(); |
|
|
|
FeatureFunction(const std::string &line, bool registerNow); |
|
FeatureFunction(size_t numScoreComponents, const std::string &line, bool registerNow = true); |
|
virtual bool IsStateless() const = 0; |
|
virtual ~FeatureFunction(); |
|
|
|
|
|
virtual void Load(AllOptions::ptr const& opts) { |
|
m_options = opts; |
|
} |
|
|
|
AllOptions::ptr const& |
|
options() const { |
|
return m_options; |
|
} |
|
|
|
static void ResetDescriptionCounts() { |
|
description_counts.clear(); |
|
} |
|
|
|
|
|
|
|
size_t GetNumScoreComponents() const { |
|
return m_numScoreComponents; |
|
} |
|
|
|
|
|
const std::string& GetScoreProducerDescription() const { |
|
return m_description; |
|
} |
|
|
|
FName GetFeatureName(const std::string& name) const { |
|
return FName(GetScoreProducerDescription(), name); |
|
} |
|
|
|
|
|
|
|
|
|
virtual bool IsTuneable() const { |
|
return m_tuneable; |
|
} |
|
|
|
virtual bool HasTuneableComponents() const { |
|
return m_numTuneableComponents; |
|
} |
|
|
|
virtual bool IsTuneableComponent(size_t i) const { |
|
if (m_numTuneableComponents == m_numScoreComponents) { |
|
return true; |
|
} |
|
return m_tuneableComponents[i]; |
|
} |
|
|
|
virtual bool RequireSortingAfterSourceContext() const { |
|
return m_requireSortingAfterSourceContext; |
|
} |
|
|
|
virtual std::vector<float> DefaultWeights() const; |
|
|
|
size_t GetIndex() const; |
|
size_t SetIndex(size_t const idx); |
|
|
|
protected: |
|
virtual void |
|
CleanUpAfterSentenceProcessing(InputType const& source) { } |
|
|
|
public: |
|
|
|
virtual void |
|
InitializeForInput(ttasksptr const& ttask) { }; |
|
|
|
|
|
virtual void |
|
CleanUpAfterSentenceProcessing(ttasksptr const& ttask); |
|
|
|
const std::string & |
|
GetArgLine() const { |
|
return m_argLine; |
|
} |
|
|
|
|
|
|
|
virtual bool IsUseable(const FactorMask &mask) const = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void |
|
EvaluateInIsolation(const Phrase &source, const TargetPhrase &targetPhrase, |
|
ScoreComponentCollection& scoreBreakdown, |
|
ScoreComponentCollection& estimatedScores) const = 0; |
|
|
|
|
|
static void SetupAll(TranslationTask const& task); |
|
virtual void Setup(TranslationTask const& task) const { }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void EvaluateWithSourceContext(const InputType &input |
|
, const InputPath &inputPath |
|
, const TargetPhrase &targetPhrase |
|
, const StackVec *stackVec |
|
, ScoreComponentCollection &scoreBreakdown |
|
, ScoreComponentCollection *estimatedScores = NULL) const = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void EvaluateTranslationOptionListWithSourceContext(const InputType &input |
|
, const TranslationOptionList &translationOptionList) const = 0; |
|
|
|
virtual void SetParameter(const std::string& key, const std::string& value); |
|
virtual void ReadParameters(); |
|
virtual void SetTuneableComponents(const std::string& value); |
|
}; |
|
|
|
} |
|
|
|
#endif |
|
|