diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-11-28 02:02:41 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-11-28 02:02:41 +0300 |
commit | 8306de019c02bfe141ac7a3ae9a1ce5d9ccb2e6a (patch) | |
tree | f569725335adb53fd5e1fd18cb8d1e3220a394b6 | |
parent | d249e398eacf1e91161c6b78fb5c6870e9923ea4 (diff) |
make GetParam() a const method with no side effect
-rw-r--r-- | moses/StaticData.cpp | 49 | ||||
-rw-r--r-- | moses/Util.h | 16 |
2 files changed, 32 insertions, 33 deletions
diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index 6e6e0495a..1edb73841 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -310,12 +310,12 @@ bool StaticData::LoadData(Parameter *parameter) UserMessage::Add("stack diversity > 0 is not allowed for lattice input"); return false; } - m_minHypoStackDiversity = Scan<size_t>(m_parameter->GetParam("stack-diversity")[0]); + m_parameter->SetParameter<size_t>(m_minHypoStackDiversity, "stack-diversity", 0); } - m_beamWidth = (m_parameter->GetParam("beam-threshold").size() > 0) ? - TransformScore(Scan<float>(m_parameter->GetParam("beam-threshold")[0])) - : TransformScore(DEFAULT_BEAM_WIDTH); + m_parameter->SetParameter(m_beamWidth, "beam-threshold", DEFAULT_BEAM_WIDTH); + m_beamWidth = TransformScore(m_beamWidth); + m_earlyDiscardingThreshold = (m_parameter->GetParam("early-discarding-threshold").size() > 0) ? TransformScore(Scan<float>(m_parameter->GetParam("early-discarding-threshold")[0])) : TransformScore(DEFAULT_EARLY_DISCARDING_THRESHOLD); @@ -437,20 +437,10 @@ bool StaticData::LoadData(Parameter *parameter) } } - m_startTranslationId = (m_parameter->GetParam("start-translation-id").size() > 0) ? - Scan<long>(m_parameter->GetParam("start-translation-id")[0]) : 0; + m_parameter->SetParameter<long>(m_startTranslationId, "start-translation-id", 0); // use of xml in input - if (m_parameter->GetParam("xml-input").size() == 0) m_xmlInputType = XmlPassThrough; - else if (m_parameter->GetParam("xml-input")[0]=="exclusive") m_xmlInputType = XmlExclusive; - else if (m_parameter->GetParam("xml-input")[0]=="inclusive") m_xmlInputType = XmlInclusive; - else if (m_parameter->GetParam("xml-input")[0]=="constraint") m_xmlInputType = XmlConstraint; - else if (m_parameter->GetParam("xml-input")[0]=="ignore") m_xmlInputType = XmlIgnore; - else if (m_parameter->GetParam("xml-input")[0]=="pass-through") m_xmlInputType = XmlPassThrough; - else { - UserMessage::Add("invalid xml-input value, must be pass-through, exclusive, inclusive, constraint, or ignore"); - return false; - } + m_parameter->SetParameter<XmlInputType>(m_xmlInputType, "xml-input", XmlPassThrough); // specify XML tags opening and closing brackets for XML option if (m_parameter->GetParam("xml-brackets").size() > 0) { @@ -465,20 +455,16 @@ bool StaticData::LoadData(Parameter *parameter) << m_xmlBrackets.first << " and " << m_xmlBrackets.second << endl); } - if (m_parameter->GetParam("placeholder-factor").size() > 0) { - m_placeHolderFactor = Scan<FactorType>(m_parameter->GetParam("placeholder-factor")[0]); - } else { - m_placeHolderFactor = NOT_FOUND; - } + m_parameter->SetParameter(m_placeHolderFactor, "placeholder-factor", NOT_FOUND); std::map<std::string, std::string> featureNameOverride = OverrideFeatureNames(); // all features map<string, int> featureIndexMap; - const vector<string> &features = m_parameter->GetParam("feature"); - for (size_t i = 0; i < features.size(); ++i) { - const string &line = Trim(features[i]); + const vector<string> *features = m_parameter->GetParam2("feature"); + for (size_t i = 0; features && i < features->size(); ++i) { + const string &line = Trim(features->at(i)); VERBOSE(1,"line=" << line << endl); if (line.empty()) continue; @@ -503,7 +489,7 @@ bool StaticData::LoadData(Parameter *parameter) NoCache(); OverrideFeatures(); - if (!m_parameter->isParamSpecified("show-weights")) { + if (m_parameter->GetParam2("show-weights") == NULL) { LoadFeatureFunctions(); } @@ -517,15 +503,12 @@ bool StaticData::LoadData(Parameter *parameter) //Add any other features here. //Load extra feature weights - vector<string> extraWeightConfig = m_parameter->GetParam("weight-file"); - if (extraWeightConfig.size()) { - if (extraWeightConfig.size() != 1) { - UserMessage::Add("One argument should be supplied for weight-file"); - return false; - } + string weightFile; + m_parameter->SetParameter<string>(weightFile, "weight-file", ""); + if (!weightFile.empty()) { ScoreComponentCollection extraWeights; - if (!extraWeights.Load(extraWeightConfig[0])) { - UserMessage::Add("Unable to load weights from " + extraWeightConfig[0]); + if (!extraWeights.Load(weightFile)) { + UserMessage::Add("Unable to load weights from " + weightFile); return false; } m_allWeights.PlusEquals(extraWeights); diff --git a/moses/Util.h b/moses/Util.h index 0e3ead4e1..8e8ccf34b 100644 --- a/moses/Util.h +++ b/moses/Util.h @@ -120,6 +120,22 @@ inline SearchAlgorithm Scan<SearchAlgorithm>(const std::string &input) return (SearchAlgorithm) Scan<size_t>(input); } +template<> +inline XmlInputType Scan<XmlInputType>(const std::string &input) +{ + XmlInputType ret; + if (input=="exclusive") ret = XmlExclusive; + else if (input=="inclusive") ret = XmlInclusive; + else if (input=="constraint") ret = XmlConstraint; + else if (input=="ignore") ret = XmlIgnore; + else if (input=="pass-through") ret = XmlPassThrough; + else { + UTIL_THROW2("Unknown XML input type"); + } + + return ret; +} + //! Specialisation to understand yes/no y/n true/false 0/1 template<> bool Scan<bool>(const std::string &input); |