allow num of features to be specified as an argument, rather than need to be passed into constructor

This commit is contained in:
Hieu Hoang 2013-02-03 18:27:55 +00:00
parent 4caffffe7b
commit 4ca673df8e
5 changed files with 37 additions and 1 deletions

View File

@ -75,6 +75,12 @@ std::vector<FeatureFunction*> FeatureFunction::m_producers;
std::vector<const StatelessFeatureFunction*> StatelessFeatureFunction::m_statelessFFs;
std::vector<const StatefulFeatureFunction*> StatefulFeatureFunction::m_statefulFFs;
FeatureFunction::FeatureFunction(const std::string& description, const std::string &line)
: ScoreProducer(description, line)
{
m_producers.push_back(this);
}
FeatureFunction::FeatureFunction(const std::string& description, size_t numScoreComponents, const std::string &line)
: ScoreProducer(description, numScoreComponents, line)
{
@ -100,6 +106,12 @@ bool StatelessFeatureFunction::ComputeValueInTranslationOption() const
return false;
}
StatefulFeatureFunction::StatefulFeatureFunction(const std::string& description, const std::string &line)
: FeatureFunction(description, line)
{
m_statefulFFs.push_back(this);
}
StatefulFeatureFunction::StatefulFeatureFunction(const std::string& description, size_t numScoreComponents, const std::string &line)
: FeatureFunction(description,numScoreComponents, line)
{

View File

@ -82,6 +82,7 @@ class FeatureFunction: public ScoreProducer
public:
static const std::vector<FeatureFunction*>& GetFeatureFunctions() { return m_producers; }
FeatureFunction(const std::string& description, const std::string &line);
FeatureFunction(const std::string& description, size_t numScoreComponents, const std::string &line);
virtual bool IsStateless() const = 0;
virtual ~FeatureFunction();
@ -135,7 +136,9 @@ class StatefulFeatureFunction: public FeatureFunction
public:
static const std::vector<const StatefulFeatureFunction*>& GetStatefulFeatureFunctions() {return m_statefulFFs;}
StatefulFeatureFunction(const std::string& description, const std::string &line);
StatefulFeatureFunction(const std::string& description, 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

View File

@ -10,7 +10,7 @@ using namespace std;
namespace Moses
{
LexicalReordering::LexicalReordering(const std::string &line)
: StatefulFeatureFunction("LexicalReordering", 6, line)
: StatefulFeatureFunction("LexicalReordering", line)
{
std::cerr << "Initializing LexicalReordering.." << std::endl;

View File

@ -14,6 +14,26 @@ namespace Moses
multiset<string> ScoreProducer::description_counts;
const size_t ScoreProducer::unlimited = -1;
ScoreProducer::ScoreProducer(const std::string& description, const std::string &line)
: m_reportSparseFeatures(false)
{
ParseLine(line);
m_numScoreComponents = FindNumFeatures();
size_t index = description_counts.count(description);
ostringstream dstream;
dstream << description;
dstream << index;
description_counts.insert(description);
m_description = dstream.str();
if (m_numScoreComponents != unlimited)
{
ScoreComponentCollection::RegisterScoreProducer(this);
}
}
ScoreProducer::ScoreProducer(const std::string& description, size_t numScoreComponents, const std::string &line)
: m_reportSparseFeatures(false), m_numScoreComponents(numScoreComponents)
{

View File

@ -28,6 +28,7 @@ protected:
static std::multiset<std::string> description_counts;
ScoreProducer(const ScoreProducer&); // don't implement
ScoreProducer(const std::string& description, const std::string &line);
ScoreProducer(const std::string& description, size_t numScoreComponents, const std::string &line);
void ParseLine(const std::string &line);