redo parsing of feature function parameters

This commit is contained in:
Hieu Hoang 2013-06-20 13:25:02 +01:00
parent 8103de2973
commit d68277d369
30 changed files with 44 additions and 63 deletions

View File

@ -57,7 +57,7 @@ DecodeFeature::DecodeFeature(const std::string& description
VERBOSE(2,"DecodeFeature: input=" << m_inputFactors << " output=" << m_outputFactors << std::endl);
}
bool DecodeFeature::SetParameter(const std::string& key, const std::string& value)
void DecodeFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "input-factor") {
m_input =Tokenize<FactorType>(value, ",");
@ -66,9 +66,8 @@ bool DecodeFeature::SetParameter(const std::string& key, const std::string& valu
m_output =Tokenize<FactorType>(value, ",");
m_outputFactors = FactorMask(m_output);
} else {
return StatelessFeatureFunction::SetParameter(key, value);
StatelessFeatureFunction::SetParameter(key, value);
}
return true;
}

View File

@ -61,7 +61,7 @@ public:
const std::vector<FactorType>& GetOutput() const;
bool IsUseable(const FactorMask &mask) const;
virtual bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
protected:
std::vector<FactorType> m_input;

View File

@ -90,23 +90,20 @@ void FeatureFunction::ParseLine(const std::string& description, const std::strin
}
}
bool FeatureFunction::SetParameter(const std::string& key, const std::string& value)
void FeatureFunction::SetParameter(const std::string& key, const std::string& value)
{
if (key == "tuneable") {
m_tuneable = Scan<bool>(value);
} else {
UTIL_THROW(util::Exception, "Unknown argument " << key << "=" << value);
}
return true;
}
void FeatureFunction::ReadParameters()
{
while (!m_args.empty()) {
const vector<string> &args = m_args[0];
bool consumed = SetParameter(args[0], args[1]);
CHECK(consumed);
SetParameter(args[0], args[1]);
m_args.erase(m_args.begin());
}

View File

@ -106,7 +106,7 @@ public:
, ScoreComponentCollection &scoreBreakdown) const {
}
virtual bool SetParameter(const std::string& key, const std::string& value);
virtual void SetParameter(const std::string& key, const std::string& value);
virtual void ReadParameters();
};

View File

@ -23,7 +23,7 @@ GlobalLexicalModel::GlobalLexicalModel(const std::string &line)
}
bool GlobalLexicalModel::SetParameter(const std::string& key, const std::string& value)
void GlobalLexicalModel::SetParameter(const std::string& key, const std::string& value)
{
if (key == "file") {
m_filePath = value;
@ -32,9 +32,8 @@ bool GlobalLexicalModel::SetParameter(const std::string& key, const std::string&
} else if (key == "outputFactors") {
m_outputFactorsVec = Tokenize<FactorType>(value,",");
} else {
return StatelessFeatureFunction::SetParameter(key, value);
StatelessFeatureFunction::SetParameter(key, value);
}
return true;
}
GlobalLexicalModel::~GlobalLexicalModel()

View File

@ -77,7 +77,7 @@ public:
ScoreComponentCollection* accumulator) const {
throw std::logic_error("GlobalLexicalModel not supported in chart decoder, yet");
}
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
};

View File

@ -22,16 +22,15 @@ PhraseBoundaryFeature::PhraseBoundaryFeature(const std::string &line)
ReadParameters();
}
bool PhraseBoundaryFeature::SetParameter(const std::string& key, const std::string& value)
void PhraseBoundaryFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "source") {
m_sourceFactors = Tokenize<FactorType>(value, ",");
} else if (key == "target") {
m_targetFactors = Tokenize<FactorType>(value, ",");
} else {
return StatefulFeatureFunction::SetParameter(key, value);
StatefulFeatureFunction::SetParameter(key, value);
}
return true;
}
const FFState* PhraseBoundaryFeature::EmptyHypothesisState(const InputType &) const

View File

@ -52,7 +52,7 @@ public:
ScoreComponentCollection* ) const {
throw std::logic_error("PhraseBoundaryState not supported in chart decoder, yet");
}
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
private:
void AddFeatures(

View File

@ -32,7 +32,7 @@ PhrasePairFeature::PhrasePairFeature(const std::string &line)
}
}
bool PhrasePairFeature::SetParameter(const std::string& key, const std::string& value)
void PhrasePairFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "input-factor") {
m_sourceFactorId = Scan<FactorType>(value);
@ -51,10 +51,8 @@ bool PhrasePairFeature::SetParameter(const std::string& key, const std::string&
} else if (key == "ignore-punctuation") {
m_filePathSource = value;
} else {
return StatelessFeatureFunction::SetParameter(key, value);
StatelessFeatureFunction::SetParameter(key, value);
}
return true;
}
void PhrasePairFeature::Load()

View File

@ -46,7 +46,7 @@ public:
}
void Load();
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
};

View File

@ -25,16 +25,15 @@ SourceWordDeletionFeature::SourceWordDeletionFeature(const std::string &line)
ReadParameters();
}
bool SourceWordDeletionFeature::SetParameter(const std::string& key, const std::string& value)
void SourceWordDeletionFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "factor") {
m_factorType = Scan<FactorType>(value);
} else if (key == "path") {
m_filename = value;
} else {
return StatelessFeatureFunction::SetParameter(key, value);
StatelessFeatureFunction::SetParameter(key, value);
}
return true;
}
void SourceWordDeletionFeature::Load()

View File

@ -37,7 +37,7 @@ public:
const TargetPhrase& targetPhrase,
ScoreComponentCollection* accumulator,
const AlignmentInfo &alignmentInfo) const;
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
};

View File

@ -30,7 +30,7 @@ TargetBigramFeature::TargetBigramFeature(const std::string &line)
}
bool TargetBigramFeature::SetParameter(const std::string& key, const std::string& value)
void TargetBigramFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "factor") {
m_factorType = Scan<FactorType>(value);
@ -39,7 +39,6 @@ bool TargetBigramFeature::SetParameter(const std::string& key, const std::string
} else {
StatefulFeatureFunction::SetParameter(key, value);
}
return true;
}
void TargetBigramFeature::Load()

View File

@ -47,7 +47,7 @@ public:
ScoreComponentCollection* ) const {
abort();
}
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
private:
FactorType m_factorType;

View File

@ -44,7 +44,7 @@ TargetNgramFeature::TargetNgramFeature(const std::string &line)
ReadParameters();
}
bool TargetNgramFeature::SetParameter(const std::string& key, const std::string& value)
void TargetNgramFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "factor") {
m_factorType = Scan<FactorType>(value);
@ -53,9 +53,8 @@ bool TargetNgramFeature::SetParameter(const std::string& key, const std::string&
} else if (key == "lower-ngrams") {
m_lower_ngrams = Scan<bool>(value);
} else {
return StatefulFeatureFunction::SetParameter(key, value);
StatefulFeatureFunction::SetParameter(key, value);
}
return true;
}
bool TargetNgramFeature::Load(const std::string &filePath)

View File

@ -191,7 +191,7 @@ public:
virtual FFState* EvaluateChart(const ChartHypothesis& cur_hypo, int featureId,
ScoreComponentCollection* accumulator) const;
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
private:
FactorType m_factorType;

View File

@ -23,16 +23,15 @@ TargetWordInsertionFeature::TargetWordInsertionFeature(const std::string &line)
ReadParameters();
}
bool TargetWordInsertionFeature::SetParameter(const std::string& key, const std::string& value)
void TargetWordInsertionFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "factor") {
m_factorType = Scan<FactorType>(value);
} else if (key == "path") {
m_filename = value;
} else {
return StatelessFeatureFunction::SetParameter(key, value);
StatelessFeatureFunction::SetParameter(key, value);
}
return true;
}
void TargetWordInsertionFeature::Load()

View File

@ -37,7 +37,7 @@ public:
const TargetPhrase& targetPhrase,
ScoreComponentCollection* accumulator,
const AlignmentInfo &alignmentInfo) const;
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
};

View File

@ -60,7 +60,7 @@ WordTranslationFeature::WordTranslationFeature(const std::string &line)
}
bool WordTranslationFeature::SetParameter(const std::string& key, const std::string& value)
void WordTranslationFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "input-factor") {
m_factorTypeSource = Scan<FactorType>(value);
@ -83,9 +83,8 @@ bool WordTranslationFeature::SetParameter(const std::string& key, const std::str
} else if (key == "target-path") {
m_filePathTarget = value;
} else {
return StatelessFeatureFunction::SetParameter(key, value);
StatelessFeatureFunction::SetParameter(key, value);
}
return true;
}
void WordTranslationFeature::Load()

View File

@ -52,7 +52,7 @@ public:
void EvaluateChart(const ChartBasedFeatureContext& context,
ScoreComponentCollection* accumulator) const;
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
};
}

View File

@ -126,14 +126,13 @@ const OutputWordCollection *GenerationDictionary::FindWord(const Word &word) con
return ret;
}
bool GenerationDictionary::SetParameter(const std::string& key, const std::string& value)
void GenerationDictionary::SetParameter(const std::string& key, const std::string& value)
{
if (key == "path") {
m_filePath = value;
} else {
return DecodeFeature::SetParameter(key, value);
DecodeFeature::SetParameter(key, value);
}
return true;
}
}

View File

@ -68,7 +68,7 @@ public:
* Or NULL if the input word isn't found. The search function used is the WordComparer functor
*/
const OutputWordCollection *FindWord(const Word &word) const;
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
};

View File

@ -44,16 +44,15 @@ GetTargetPhraseCollection(InputType const& src,WordsRange const& range) const
return GetTargetPhraseCollection(phrase);
}
bool PhraseDictionary::SetParameter(const std::string& key, const std::string& value)
void PhraseDictionary::SetParameter(const std::string& key, const std::string& value)
{
if (key == "path") {
m_filePath = value;
} else if (key == "table-limit") {
m_tableLimit = Scan<size_t>(value);
} else {
return DecodeFeature::SetParameter(key, value);
DecodeFeature::SetParameter(key, value);
}
return true;
}
void PhraseDictionary::SetFeaturesToApply()

View File

@ -91,7 +91,7 @@ public:
return m_featuresToApply;
}
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
protected:
size_t m_tableLimit;

View File

@ -69,7 +69,7 @@ ChartRuleLookupManager *PhraseDictionaryDynSuffixArray::CreateRuleLookupManager(
throw "Chart decoding not supported by PhraseDictionaryDynSuffixArray";
}
bool PhraseDictionaryDynSuffixArray::SetParameter(const std::string& key, const std::string& value)
void PhraseDictionaryDynSuffixArray::SetParameter(const std::string& key, const std::string& value)
{
if (key == "source") {
m_source = value;
@ -78,9 +78,8 @@ bool PhraseDictionaryDynSuffixArray::SetParameter(const std::string& key, const
} else if (key == "alignment") {
m_alignments = value;
} else {
return PhraseDictionary::SetParameter(key, value);
PhraseDictionary::SetParameter(key, value);
}
return true;
}
}// end namepsace

View File

@ -26,7 +26,7 @@ public:
void deleteSnt(unsigned, unsigned);
ChartRuleLookupManager *CreateRuleLookupManager(const InputType&, const ChartCellCollectionBase&);
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
private:
BilingualDynSuffixArray *m_biSA;

View File

@ -51,7 +51,7 @@ PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &descri
}
}
bool PhraseDictionaryMultiModel::SetParameter(const std::string& key, const std::string& value)
void PhraseDictionaryMultiModel::SetParameter(const std::string& key, const std::string& value)
{
if (key == "mode") {
m_mode = value;
@ -61,9 +61,8 @@ bool PhraseDictionaryMultiModel::SetParameter(const std::string& key, const std:
} else if (key == "lambda") {
m_multimodelweights = Tokenize<float>(value, ",");
} else {
return PhraseDictionary::SetParameter(key, value);
PhraseDictionary::SetParameter(key, value);
}
return true;
}
PhraseDictionaryMultiModel::~PhraseDictionaryMultiModel()

View File

@ -81,7 +81,7 @@ public:
/* Don't do anything source specific here as this object is shared between threads.*/
}
ChartRuleLookupManager *CreateRuleLookupManager(const InputType&, const ChartCellCollectionBase&);
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
const std::vector<float>* GetTemporaryMultiModelWeightsVector() const;
void SetTemporaryMultiModelWeightsVector(std::vector<float> weights);

View File

@ -84,7 +84,7 @@ PhraseDictionaryMultiModelCounts::PhraseDictionaryMultiModelCounts(const std::st
}
bool PhraseDictionaryMultiModelCounts::SetParameter(const std::string& key, const std::string& value)
void PhraseDictionaryMultiModelCounts::SetParameter(const std::string& key, const std::string& value)
{
if (key == "mode") {
m_mode = value;
@ -97,10 +97,8 @@ bool PhraseDictionaryMultiModelCounts::SetParameter(const std::string& key, cons
} else if (key == "target-table") {
m_targetTable = Tokenize(value, ",");
} else {
return PhraseDictionaryMultiModel::SetParameter(key, value);
PhraseDictionaryMultiModel::SetParameter(key, value);
}
return true;
}
PhraseDictionaryMultiModelCounts::~PhraseDictionaryMultiModelCounts()

View File

@ -103,7 +103,7 @@ public:
/* Don't do anything source specific here as this object is shared between threads.*/
}
bool SetParameter(const std::string& key, const std::string& value);
void SetParameter(const std::string& key, const std::string& value);
private:
std::vector<PhraseDictionary*> m_inverse_pd;