diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
commit | 6249432407af8730c10bccc7894c0725fcaf5e47 (patch) | |
tree | 3ac1f094b9fdc199b04bc5ef209ce00e3596e37d /mert/SemposScorer.cpp | |
parent | 59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (diff) |
beautify
Diffstat (limited to 'mert/SemposScorer.cpp')
-rw-r--r-- | mert/SemposScorer.cpp | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/mert/SemposScorer.cpp b/mert/SemposScorer.cpp index 8dd1fc8ee..235f73fbf 100644 --- a/mert/SemposScorer.cpp +++ b/mert/SemposScorer.cpp @@ -12,7 +12,7 @@ using namespace std; namespace MosesTuning { - + SemposScorer::SemposScorer(const string& config) : StatisticsBasedScorer("SEMPOS", config), @@ -25,8 +25,7 @@ SemposScorer::SemposScorer(const string& config) m_semposMap.clear(); string weightsfile = getConfig("weightsfile", ""); - if (weightsfile != "") - { + if (weightsfile != "") { loadWeights(weightsfile); } } @@ -144,42 +143,35 @@ int SemposScorer::encodeSempos(const string& sempos) float SemposScorer::weight(int item) const { - std::map<int,float>::const_iterator it = weightsMap.find(item); - if (it == weightsMap.end()) - { - return 1.0f; - } - else - { - return it->second; - } + std::map<int,float>::const_iterator it = weightsMap.find(item); + if (it == weightsMap.end()) { + return 1.0f; + } else { + return it->second; + } } void SemposScorer::loadWeights(const string& weightsfile) { - string line; - ifstream myfile; - myfile.open(weightsfile.c_str(), ifstream::in); - if (myfile.is_open()) - { - while ( myfile.good() ) - { - getline (myfile,line); - vector<string> fields; - if (line == "") continue; - split(line, '\t', fields); - if (fields.size() != 2) throw std::runtime_error("Bad format of a row in weights file."); - int encoded = encodeString(fields[0]); - float weight = atof(fields[1].c_str()); - weightsMap[encoded] = weight; - } - myfile.close(); - } - else - { - cerr << "Unable to open file "<< weightsfile << endl; - exit(1); + string line; + ifstream myfile; + myfile.open(weightsfile.c_str(), ifstream::in); + if (myfile.is_open()) { + while ( myfile.good() ) { + getline (myfile,line); + vector<string> fields; + if (line == "") continue; + split(line, '\t', fields); + if (fields.size() != 2) throw std::runtime_error("Bad format of a row in weights file."); + int encoded = encodeString(fields[0]); + float weight = atof(fields[1].c_str()); + weightsMap[encoded] = weight; } + myfile.close(); + } else { + cerr << "Unable to open file "<< weightsfile << endl; + exit(1); + } } |