From abe6bb7c2257cce6ed746e54fdd97fbf1f1ef3aa Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Mon, 10 Jun 2013 18:11:55 +0100 Subject: refactor parsing of feature functiona args --- moses/TranslationModel/PhraseDictionary.cpp | 39 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'moses/TranslationModel/PhraseDictionary.cpp') diff --git a/moses/TranslationModel/PhraseDictionary.cpp b/moses/TranslationModel/PhraseDictionary.cpp index 22802f6b5..66b5ddff8 100644 --- a/moses/TranslationModel/PhraseDictionary.cpp +++ b/moses/TranslationModel/PhraseDictionary.cpp @@ -32,24 +32,18 @@ namespace Moses PhraseDictionary::PhraseDictionary(const std::string &description, const std::string &line) :DecodeFeature(description, line) + ,m_tableLimit(20) // default { - m_tableLimit= 20; // TODO default? - - for (size_t i = 0; i < m_args.size(); ++i) { - const vector &args = m_args[i]; - - if (args[0] == "path") { - m_filePath = args[1]; - } else if (args[0] == "table-limit") { - m_tableLimit = Scan(args[1]); - } else if (args[0] == "target-path") { - m_targetFile = args[1]; - } else if (args[0] == "alignment-path") { - m_alignmentsFile = args[1]; + size_t ind = 0; + while (ind < m_args.size()) { + vector &args = m_args[ind]; + bool consumed = OverrideParameter(args[0], args[1]); + if (consumed) { + m_args.erase(m_args.begin() + ind); } else { - //throw "Unknown argument " + args[0]; + ++ind; } - } // for (size_t i = 0; i < toks.size(); ++i) { + } // find out which feature function can be applied in this decode step const std::vector &allFeatures = FeatureFunction::GetFeatureFunctions(); @@ -72,11 +66,16 @@ GetTargetPhraseCollection(InputType const& src,WordsRange const& range) const bool PhraseDictionary::OverrideParameter(const std::string& key, const std::string& value) { - if (key == "table-limit") { - m_tableLimit = Scan(value); - } - else { - return DecodeFeature::OverrideParameter(key, value); + if (key == "path") { + m_filePath = value; + } else if (key == "table-limit") { + m_tableLimit = Scan(value); + } else if (key == "target-path") { + m_targetFile = value; + } else if (key == "alignment-path") { + m_alignmentsFile = value; + } else { + return DecodeFeature::OverrideParameter(key, value); } return true; -- cgit v1.2.3