diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-11-26 19:41:25 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-11-26 19:41:25 +0300 |
commit | a2bb435a1a90f1d4165d6a080de474618fb13988 (patch) | |
tree | 4dfc52c3c6c12e403bc8e16205a4d514bd64a531 /moses/Parameter.cpp | |
parent | 4ca730a67cfa96b9e070aaa8fafbee84e9a362d5 (diff) |
make GetParam() a const method with no side effect
Diffstat (limited to 'moses/Parameter.cpp')
-rw-r--r-- | moses/Parameter.cpp | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index 85d28bdb0..2bc0d4032 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -222,6 +222,18 @@ const PARAM_VEC &Parameter::GetParam(const std::string ¶mName) return m_setting[paramName]; } +const PARAM_VEC *Parameter::GetParam2(const std::string ¶mName) const +{ + PARAM_MAP::const_iterator iter = m_setting.find( paramName ); + if (iter == m_setting.end()) { + return NULL; + } + else { + return &iter->second; + } + +} + /** initialize a parameter, sub of constructor */ void Parameter::AddParam(const string ¶mName, const string &description) { @@ -375,19 +387,16 @@ bool Parameter::LoadParam(int argc, char* argv[]) void Parameter::AddFeaturesCmd() { - if (!isParamSpecified("feature-add")) { - return; + const PARAM_VEC *params = GetParam2("feature-add"); + if (params) { + PARAM_VEC::const_iterator iter; + for (iter = params->begin(); iter != params->end(); ++iter) { + const string &line = *iter; + AddFeature(line); + } + + m_setting.erase("feature-add"); } - - const PARAM_VEC ¶ms = GetParam("feature-add"); - - PARAM_VEC::const_iterator iter; - for (iter = params.begin(); iter != params.end(); ++iter) { - const string &line = *iter; - AddFeature(line); - } - - m_setting.erase("feature-add"); } std::vector<float> Parameter::GetWeights(const std::string &name) @@ -485,19 +494,26 @@ void Parameter::ConvertWeightArgsPhraseModel(const string &oldWeightName) size_t numRealWordsInInput = 0; map<string, size_t> ptIndices; - if (GetParam("input-scores").size()) { - numInputScores = Scan<size_t>(GetParam("input-scores")[0]); - } + const PARAM_VEC *params = GetParam2("input-scores"); + if (params) { + numInputScores = Scan<size_t>(params->at(0)); - if (GetParam("input-scores").size() > 1) { - numRealWordsInInput = Scan<size_t>(GetParam("input-scores")[1]); + if (params->size() > 1) { + numRealWordsInInput = Scan<size_t>(params->at(1)); + } } // load phrase translation tables - if (GetParam("ttable-file").size() > 0) { + params = GetParam2("ttable-file"); + if (params) { // weights - const vector<string> &translationVector = GetParam("ttable-file"); - vector<size_t> maxTargetPhrase = Scan<size_t>(GetParam("ttable-limit")); + const vector<string> translationVector = *params; + + vector<size_t> maxTargetPhrase; + params = GetParam2("ttable-limit"); + if (params) { + maxTargetPhrase = Scan<size_t>(*params); + } if(maxTargetPhrase.size() == 1 && translationVector.size() > 1) { VERBOSE(1, "Using uniform ttable-limit of " << maxTargetPhrase[0] << " for all translation tables." << endl); |