redo parsing of feature function parameters

This commit is contained in:
Hieu Hoang 2013-06-20 13:06:03 +01:00
parent dc33fa3d3d
commit 24d2edd790
22 changed files with 35 additions and 223 deletions

View File

@ -23,16 +23,7 @@ struct DistortionState_traditional : public FFState {
DistortionScoreProducer::DistortionScoreProducer(const std::string &line) DistortionScoreProducer::DistortionScoreProducer(const std::string &line)
: StatefulFeatureFunction("Distortion", 1, line) { : StatefulFeatureFunction("Distortion", 1, line) {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
const FFState* DistortionScoreProducer::EmptyHypothesisState(const InputType &input) const const FFState* DistortionScoreProducer::EmptyHypothesisState(const InputType &input) const

View File

@ -107,5 +107,19 @@ void FeatureFunction::OverrideParameter(const std::string& key, const std::strin
UTIL_THROW_IF(!ret, util::Exception, "Unknown argument" << key); UTIL_THROW_IF(!ret, util::Exception, "Unknown argument" << key);
} }
void FeatureFunction::ReadParameters()
{
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
}
} }

View File

@ -108,6 +108,7 @@ public:
virtual bool SetParameter(const std::string& key, const std::string& value); virtual bool SetParameter(const std::string& key, const std::string& value);
virtual void OverrideParameter(const std::string& key, const std::string& value); virtual void OverrideParameter(const std::string& key, const std::string& value);
virtual void ReadParameters();
}; };
} }

View File

@ -13,18 +13,7 @@ GlobalLexicalModel::GlobalLexicalModel(const std::string &line)
: StatelessFeatureFunction("GlobalLexicalModel",1, line) : StatelessFeatureFunction("GlobalLexicalModel",1, line)
{ {
std::cerr << "Creating global lexical model...\n"; std::cerr << "Creating global lexical model...\n";
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
// define bias word // define bias word
FactorCollection &factorCollection = FactorCollection::Instance(); FactorCollection &factorCollection = FactorCollection::Instance();

View File

@ -19,19 +19,7 @@ PhraseBoundaryFeature::PhraseBoundaryFeature(const std::string &line)
: StatefulFeatureFunction("PhraseBoundaryFeature", 0, line) : StatefulFeatureFunction("PhraseBoundaryFeature", 0, line)
{ {
std::cerr << "Initializing source word deletion feature.." << std::endl; std::cerr << "Initializing source word deletion feature.." << std::endl;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
} }
bool PhraseBoundaryFeature::SetParameter(const std::string& key, const std::string& value) bool PhraseBoundaryFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -12,16 +12,7 @@ using namespace std;
PhraseLengthFeature::PhraseLengthFeature(const std::string &line) PhraseLengthFeature::PhraseLengthFeature(const std::string &line)
:StatelessFeatureFunction("PhraseLengthFeature", 0, line) :StatelessFeatureFunction("PhraseLengthFeature", 0, line)
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
void PhraseLengthFeature::Evaluate(const Phrase &source void PhraseLengthFeature::Evaluate(const Phrase &source

View File

@ -17,18 +17,7 @@ PhrasePairFeature::PhrasePairFeature(const std::string &line)
:StatelessFeatureFunction("PhrasePairFeature", 0, line) :StatelessFeatureFunction("PhrasePairFeature", 0, line)
{ {
std::cerr << "Initializing PhrasePairFeature.." << std::endl; std::cerr << "Initializing PhrasePairFeature.." << std::endl;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
if (m_simple == 1) std::cerr << "using simple phrase pairs.. "; if (m_simple == 1) std::cerr << "using simple phrase pairs.. ";
if (m_sourceContext == 1) std::cerr << "using source context.. "; if (m_sourceContext == 1) std::cerr << "using source context.. ";

View File

@ -22,18 +22,7 @@ SourceWordDeletionFeature::SourceWordDeletionFeature(const std::string &line)
m_unrestricted(true) m_unrestricted(true)
{ {
std::cerr << "Initializing source word deletion feature.." << std::endl; std::cerr << "Initializing source word deletion feature.." << std::endl;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
} }
bool SourceWordDeletionFeature::SetParameter(const std::string& key, const std::string& value) bool SourceWordDeletionFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -21,18 +21,7 @@ TargetBigramFeature::TargetBigramFeature(const std::string &line)
:StatefulFeatureFunction("TargetBigramFeature", 0, line) :StatefulFeatureFunction("TargetBigramFeature", 0, line)
{ {
std::cerr << "Initializing target bigram feature.." << std::endl; std::cerr << "Initializing target bigram feature.." << std::endl;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
FactorCollection& factorCollection = FactorCollection::Instance(); FactorCollection& factorCollection = FactorCollection::Instance();
const Factor* bosFactor = const Factor* bosFactor =

View File

@ -41,19 +41,7 @@ TargetNgramFeature::TargetNgramFeature(const std::string &line)
:StatefulFeatureFunction("TargetNgramFeature", 0, line) :StatefulFeatureFunction("TargetNgramFeature", 0, line)
{ {
std::cerr << "Initializing target ngram feature.." << std::endl; std::cerr << "Initializing target ngram feature.." << std::endl;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
} }
bool TargetNgramFeature::SetParameter(const std::string& key, const std::string& value) bool TargetNgramFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -20,18 +20,7 @@ TargetWordInsertionFeature::TargetWordInsertionFeature(const std::string &line)
m_unrestricted(true) m_unrestricted(true)
{ {
std::cerr << "Initializing target word insertion feature.." << std::endl; std::cerr << "Initializing target word insertion feature.." << std::endl;
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
} }
bool TargetWordInsertionFeature::SetParameter(const std::string& key, const std::string& value) bool TargetWordInsertionFeature::SetParameter(const std::string& key, const std::string& value)

View File

@ -9,17 +9,7 @@ namespace Moses
UnknownWordPenaltyProducer::UnknownWordPenaltyProducer(const std::string &line) UnknownWordPenaltyProducer::UnknownWordPenaltyProducer(const std::string &line)
: StatelessFeatureFunction("UnknownWordPenalty",1, line) { : StatelessFeatureFunction("UnknownWordPenalty",1, line) {
m_tuneable = false; m_tuneable = false;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
} }

View File

@ -8,16 +8,7 @@ namespace Moses
{ {
WordPenaltyProducer::WordPenaltyProducer(const std::string &line) WordPenaltyProducer::WordPenaltyProducer(const std::string &line)
: StatelessFeatureFunction("WordPenalty",1, line) { : StatelessFeatureFunction("WordPenalty",1, line) {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
void WordPenaltyProducer::Evaluate(const Phrase &source void WordPenaltyProducer::Evaluate(const Phrase &source

View File

@ -26,18 +26,7 @@ WordTranslationFeature::WordTranslationFeature(const std::string &line)
,m_domainTrigger(false) ,m_domainTrigger(false)
{ {
std::cerr << "Initializing word translation feature.. " << endl; std::cerr << "Initializing word translation feature.. " << endl;
ReadParameters();
size_t ind = 0;
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
if (m_simple == 1) std::cerr << "using simple word translations.. "; if (m_simple == 1) std::cerr << "using simple word translations.. ";
if (m_sourceContext == 1) std::cerr << "using source context.. "; if (m_sourceContext == 1) std::cerr << "using source context.. ";

View File

@ -38,16 +38,7 @@ namespace Moses
GenerationDictionary::GenerationDictionary(const std::string &line) GenerationDictionary::GenerationDictionary(const std::string &line)
: DecodeFeature("Generation", line) : DecodeFeature("Generation", line)
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
void GenerationDictionary::Load() void GenerationDictionary::Load()

View File

@ -49,16 +49,7 @@ PhraseDictionaryCompact::PhraseDictionaryCompact(const std::string &line)
,m_phraseDecoder(0) ,m_phraseDecoder(0)
,m_weight(0) ,m_weight(0)
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
void PhraseDictionaryCompact::Load() void PhraseDictionaryCompact::Load()

View File

@ -12,18 +12,7 @@ PhraseDictionaryDynSuffixArray::PhraseDictionaryDynSuffixArray(const std::string
:PhraseDictionary("PhraseDictionaryDynSuffixArray", line) :PhraseDictionary("PhraseDictionaryDynSuffixArray", line)
,m_biSA(new BilingualDynSuffixArray()) ,m_biSA(new BilingualDynSuffixArray())
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
} }
PhraseDictionaryDynSuffixArray::~PhraseDictionaryDynSuffixArray() PhraseDictionaryDynSuffixArray::~PhraseDictionaryDynSuffixArray()

View File

@ -42,16 +42,7 @@ namespace Moses
PhraseDictionaryMemory::PhraseDictionaryMemory(const std::string &line) PhraseDictionaryMemory::PhraseDictionaryMemory(const std::string &line)
: RuleTableTrie("PhraseDictionaryMemory", line) : RuleTableTrie("PhraseDictionaryMemory", line)
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
TargetPhraseCollection &PhraseDictionaryMemory::GetOrCreateTargetPhraseCollection( TargetPhraseCollection &PhraseDictionaryMemory::GetOrCreateTargetPhraseCollection(

View File

@ -28,17 +28,7 @@ namespace Moses
PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line) PhraseDictionaryMultiModel::PhraseDictionaryMultiModel(const std::string &line)
:PhraseDictionary("PhraseDictionaryMultiModel", line) :PhraseDictionary("PhraseDictionaryMultiModel", line)
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
if (m_mode != "interpolate") { if (m_mode != "interpolate") {
ostringstream msg; ostringstream msg;

View File

@ -68,17 +68,7 @@ PhraseDictionaryMultiModelCounts::PhraseDictionaryMultiModelCounts(const std::st
//m_mode = "interpolate"; //m_mode = "interpolate";
//m_combineFunction = LinearInterpolationFromCounts; //m_combineFunction = LinearInterpolationFromCounts;
cerr << "m_args=" << m_args.size() << endl; cerr << "m_args=" << m_args.size() << endl;
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
CHECK(m_args.size() == 0);
CHECK(m_targetTable.size() == m_pdStr.size()); CHECK(m_targetTable.size() == m_pdStr.size());

View File

@ -29,16 +29,7 @@ PhraseDictionaryTreeAdaptor::
PhraseDictionaryTreeAdaptor(const std::string &line) PhraseDictionaryTreeAdaptor(const std::string &line)
: PhraseDictionary("PhraseDictionaryBinary", line) : PhraseDictionary("PhraseDictionaryBinary", line)
{ {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor() PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor()

View File

@ -32,16 +32,7 @@ namespace Moses
{ {
PhraseDictionaryOnDisk::PhraseDictionaryOnDisk(const std::string &line) PhraseDictionaryOnDisk::PhraseDictionaryOnDisk(const std::string &line)
: MyBase("PhraseDictionaryOnDisk", line) { : MyBase("PhraseDictionaryOnDisk", line) {
size_t ind = 0; ReadParameters();
while (ind < m_args.size()) {
vector<string> &args = m_args[ind];
bool consumed = SetParameter(args[0], args[1]);
if (consumed) {
m_args.erase(m_args.begin() + ind);
} else {
++ind;
}
}
} }
PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk() PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk()