📄 parameter.cpp.svn-base
字号:
} // distortion if (noErrorFlag) { std::vector<std::string> ext; //raw tables in either un compressed or compressed form ext.push_back(""); ext.push_back(".gz"); //prefix tree format ext.push_back(".binlexr.idx"); noErrorFlag = FilesExist("distortion-file", 3, ext); } return noErrorFlag;}/** check whether a file exists */bool Parameter::FilesExist(const string ¶mName, size_t tokenizeIndex,std::vector<std::string> const& extensions){ typedef std::vector<std::string> StringVec; StringVec::const_iterator iter; PARAM_MAP::const_iterator iterParam = m_setting.find(paramName); if (iterParam == m_setting.end()) { // no param. therefore nothing to check return true; } const StringVec &pathVec = (*iterParam).second; for (iter = pathVec.begin() ; iter != pathVec.end() ; ++iter) { StringVec vec = Tokenize(*iter); if (tokenizeIndex >= vec.size()) { stringstream errorMsg(""); errorMsg << "Expected at least " << (tokenizeIndex+1) << " tokens per emtry in '" << paramName << "', but only found " << vec.size(); UserMessage::Add(errorMsg.str()); return false; } const string &pathStr = vec[tokenizeIndex]; bool fileFound=0; for(size_t i=0;i<extensions.size() && !fileFound;++i) { fileFound|=FileExists(pathStr + extensions[i]); } if(!fileFound) { stringstream errorMsg(""); errorMsg << "File " << pathStr << " does not exist"; UserMessage::Add(errorMsg.str()); return false; } } return true;}/** look for a switch in arg, update parameter */// TODO arg parsing like this does not belong in the library, it belongs// in moses-cmdstring Parameter::FindParam(const string ¶mSwitch, int argc, char* argv[]){ for (int i = 0 ; i < argc ; i++) { if (string(argv[i]) == paramSwitch) { if (i+1 < argc) { return argv[i+1]; } else { stringstream errorMsg(""); errorMsg << "Option " << paramSwitch << " requires a parameter!"; UserMessage::Add(errorMsg.str()); // TODO return some sort of error, not the empty string } } } return "";}/** update parameter settings with command line switches * \param paramSwitch (potentially short) name of switch * \param paramName full name of parameter * \param argc number of arguments on command line * \param argv values of paramters on command line */void Parameter::OverwriteParam(const string ¶mSwitch, const string ¶mName, int argc, char* argv[]){ int startPos = -1; for (int i = 0 ; i < argc ; i++) { if (string(argv[i]) == paramSwitch) { startPos = i+1; break; } } if (startPos < 0) return; int index = 0; m_setting[paramName]; // defines the parameter, important for boolean switches while (startPos < argc && (!isOption(argv[startPos]))) { if (m_setting[paramName].size() > (size_t)index) m_setting[paramName][index] = argv[startPos]; else m_setting[paramName].push_back(argv[startPos]); index++; startPos++; }}/** read parameters from a configuration file */bool Parameter::ReadConfigFile( string filePath ) { InputFileStream inFile(filePath); string line, paramName; while(getline(inFile, line)) { // comments size_t comPos = line.find_first_of("#"); if (comPos != string::npos) line = line.substr(0, comPos); // trim leading and trailing spaces/tabs line = Trim(line); if (line[0]=='[') { // new parameter for (size_t currPos = 0 ; currPos < line.size() ; currPos++) { if (line[currPos] == ']') { paramName = line.substr(1, currPos - 1); break; } } } else if (line != "") { // add value to parameter m_setting[paramName].push_back(line); } } return true;}struct Credit{ string name, contact, currentPursuits, areaResponsibility; Credit(string name, string contact, string currentPursuits, string areaResponsibility) { this->name = name ; this->contact = contact ; this->currentPursuits = currentPursuits ; this->areaResponsibility = areaResponsibility; } bool operator<(const Credit &other) const { if (areaResponsibility.size() != 0 && other.areaResponsibility.size() ==0) return true; if (areaResponsibility.size() == 0 && other.areaResponsibility.size() !=0) return false; return name < other.name; }};std::ostream& operator<<(std::ostream &os, const Credit &credit){ os << credit.name; if (credit.contact != "") os << "\n contact: " << credit.contact; if (credit.currentPursuits != "") os << "\n " << credit.currentPursuits; if (credit.areaResponsibility != "") os << "\n I'll answer question on: " << credit.areaResponsibility; os << endl; return os;}void Parameter::PrintCredit(){ vector<Credit> everyone; everyone.push_back(Credit("Nicola Bertoldi" , "911" , "" , "scripts & other stuff")); everyone.push_back(Credit("Ondrej Bojar" , "" , "czech this out!" , "")); everyone.push_back(Credit("Chris Callison-Burch" , "anytime, anywhere" , "international playboy" , "")); everyone.push_back(Credit("Alexandra Constantin" , "" , "eu sunt varza" , "")); everyone.push_back(Credit("Brooke Cowan" , "brooke@csail.mit.edu" , "if you're going to san francisco, be sure to wear a flower in your hair" , "")); everyone.push_back(Credit("Chris Dyer" , "can't. i'll be out driving my mustang" , "driving my mustang" , "")); everyone.push_back(Credit("Marcello Federico" , "federico at itc at it" , "Researcher at ITC-irst, Trento, Italy" , "IRST language model")); everyone.push_back(Credit("Evan Herbst" , "Small college in upstate New York" , "" , "")); everyone.push_back(Credit("Philipp Koehn" , "only between 2 and 4am" , "" , "Nothing fazes this dude")); everyone.push_back(Credit("Christine Moran" , "weird building at MIT" , "" , "")); everyone.push_back(Credit("Wade Shen" , "via morse code" , "buying another laptop" , "")); everyone.push_back(Credit("Richard Zens" , "richard at aachen dot de" , "" , "ambiguous source input, confusion networks, confusing source code")); everyone.push_back(Credit("Hieu Hoang", "http://www.hoang.co.uk/hieu/" , "phd student at Edinburgh Uni. Original Moses developer" , "general queries/ flames on Moses. Doing stuff on async factored translation, so anything on that as well")); sort(everyone.begin(), everyone.end()); cerr << "Moses - A beam search decoder for phrase-based statistical machine translation models" << endl << "Copyright (C) 2006 University of Edinburgh" << endl << endl << "This library is free software; you can redistribute it and/or" << endl << "modify it under the terms of the GNU Lesser General Public" << endl << "License as published by the Free Software Foundation; either" << endl << "version 2.1 of the License, or (at your option) any later version." << endl << endl << "This library is distributed in the hope that it will be useful," << endl << "but WITHOUT ANY WARRANTY; without even the implied warranty of" << endl << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" << endl << "Lesser General Public License for more details." << endl << endl << "You should have received a copy of the GNU Lesser General Public" << endl << "License along with this library; if not, write to the Free Software" << endl << "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA" << endl << endl << "***********************************************************************" << endl << endl << "Built on " << __DATE__ << endl << endl << "CREDITS" << endl << endl; ostream_iterator<Credit> out(cerr, "\n"); copy(everyone.begin(), everyone.end(), out); cerr << endl << endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -