00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef moses_Parameter_h
00023 #define moses_Parameter_h
00024
00025 #include <string>
00026 #include <set>
00027 #include <map>
00028 #include <vector>
00029 #include "TypeDef.h"
00030
00031 namespace Moses
00032 {
00033
00034 typedef std::vector<std::string> PARAM_VEC;
00035 typedef std::map<std::string, PARAM_VEC > PARAM_MAP;
00036 typedef std::map<std::string, bool> PARAM_BOOL;
00037 typedef std::map<std::string, std::string > PARAM_STRING;
00038
00043 class Parameter
00044 {
00045 protected:
00046 PARAM_MAP m_setting;
00047 PARAM_BOOL m_valid;
00048 PARAM_STRING m_abbreviation;
00049 PARAM_STRING m_description;
00050 PARAM_STRING m_fullname;
00051
00052 std::map<std::string, std::vector<float> > m_weights;
00053
00054 std::string FindParam(const std::string ¶mSwitch, int argc, char* argv[]);
00055 void OverwriteParam(const std::string ¶mSwitch, const std::string ¶mName, int argc, char* argv[]);
00056 bool ReadConfigFile(const std::string &filePath );
00057 bool FilesExist(const std::string ¶mName, int fieldNo, std::vector<std::string> const& fileExtension=std::vector<std::string>(1,""));
00058 bool isOption(const char* token);
00059 bool Validate();
00060
00061 void AddParam(const std::string ¶mName, const std::string &description);
00062 void AddParam(const std::string ¶mName, const std::string &abbrevName, const std::string &description);
00063
00064 void PrintCredit();
00065
00066 void SetWeight(const std::string &name, size_t ind, float weight);
00067 void SetWeight(const std::string &name, size_t ind, const std::vector<float> &weights);
00068 void AddWeight(const std::string &name, size_t ind, const std::vector<float> &weights);
00069 void ConvertWeightArgs();
00070 void ConvertWeightArgsSingleWeight(const std::string &oldWeightName, const std::string &newWeightName);
00071 void ConvertWeightArgsPhraseModel(const std::string &oldWeightName);
00072 void ConvertWeightArgsLM();
00073 void ConvertWeightArgsDistortion();
00074 void ConvertWeightArgsGeneration(const std::string &oldWeightName, const std::string &newWeightName);
00075 void ConvertWeightArgsWordPenalty();
00076 void CreateWeightsMap();
00077 void WeightOverwrite();
00078 void AddFeature(const std::string &line);
00079
00080
00081 public:
00082 Parameter();
00083 ~Parameter();
00084 bool LoadParam(int argc, char* argv[]);
00085 bool LoadParam(const std::string &filePath);
00086 void Explain();
00087
00089 const PARAM_VEC &GetParam(const std::string ¶mName) {
00090 return m_setting[paramName];
00091 }
00093 bool isParamSpecified(const std::string ¶mName) {
00094 return m_setting.find( paramName ) != m_setting.end();
00095 }
00096
00097 const std::string GetFullName(std::string abbr) {
00098 return m_fullname[abbr];
00099 }
00100
00101 const std::string GetAbbreviation(std::string full) {
00102 return m_abbreviation[full];
00103 }
00104 const PARAM_VEC &GetParamShortName(const std::string ¶mName) {
00105 return GetParam(GetFullName(paramName));
00106 }
00107
00108 void OverwriteParam(const std::string ¶mName, PARAM_VEC values);
00109
00110 void OverwriteParamShortName(const std::string ¶mShortName, PARAM_VEC values) {
00111 OverwriteParam(GetFullName(paramShortName),values);
00112 }
00113
00114 std::vector<float> &GetWeights(const std::string &name);
00115 std::set<std::string> GetWeightNames() const;
00116
00117 const PARAM_MAP &GetParams() const {
00118 return m_setting;
00119 }
00120
00121 void Save(const std::string path);
00122 };
00123
00124 }
00125
00126 #endif