diff options
author | phkoehn <phkoehn@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-30 23:52:16 +0400 |
---|---|---|
committer | phkoehn <phkoehn@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-30 23:52:16 +0400 |
commit | 6d54aca44aba5dfe3e2ef7d58de5ab78ae4b81ee (patch) | |
tree | f39a179fddf15c384cd5429b02d37570bae64f16 /moses | |
parent | 1de5a36386d3759900aca71ba3f1cdf023e3833c (diff) |
minor fixes, boolean switches can now be applied without value, e.g. "-t"
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@803 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rwxr-xr-x | moses/src/Hypothesis.cpp | 2 | ||||
-rwxr-xr-x | moses/src/InputOutput.h | 2 | ||||
-rwxr-xr-x | moses/src/Parameter.cpp | 47 | ||||
-rwxr-xr-x | moses/src/Parameter.h | 9 | ||||
-rwxr-xr-x | moses/src/StaticData.cpp | 78 | ||||
-rwxr-xr-x | moses/src/StaticData.h | 7 |
6 files changed, 63 insertions, 82 deletions
diff --git a/moses/src/Hypothesis.cpp b/moses/src/Hypothesis.cpp index b08c30e9f..fe0335162 100755 --- a/moses/src/Hypothesis.cpp +++ b/moses/src/Hypothesis.cpp @@ -56,7 +56,7 @@ Hypothesis::Hypothesis(InputType const& source, const TargetPhrase &emptyTarget) { // used for initial seeding of trans process // initialize scores _hash_computed = false; - s_HypothesesCreated = 0; + s_HypothesesCreated = 1; ResetScore(); } diff --git a/moses/src/InputOutput.h b/moses/src/InputOutput.h index c0759a71b..9ed11d0e5 100755 --- a/moses/src/InputOutput.h +++ b/moses/src/InputOutput.h @@ -38,7 +38,7 @@ class InputOutput public: InputOutput(); virtual InputType* GetInput(InputType*) = 0; - virtual void SetOutput(const Hypothesis *hypo, long translationId, bool reportSourceSpan, bool reportAllFactors) = 0; + virtual void SetOutput(const Hypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors) = 0; virtual void SetNBest(const LatticePathList &nBestList, long translationId) = 0; virtual ~InputOutput(); virtual void Release(InputType*); diff --git a/moses/src/Parameter.cpp b/moses/src/Parameter.cpp index a3bfae537..0b54ea9ac 100755 --- a/moses/src/Parameter.cpp +++ b/moses/src/Parameter.cpp @@ -53,8 +53,8 @@ Parameter::Parameter() AddParam("n-best-list", "file and size of n-best-list to be generated"); AddParam("output-factors", "list of factors in the output"); AddParam("phrase-drop-allowed", "da", "if present, allow dropping of source words"); //da = drop any (word); see -du for comparison - AddParam("report-all-factors", "?"); //TODO description, please - AddParam("report-source-span", "?"); //TODO description, please + AddParam("report-all-factors", "report all factors in output, not just first"); + AddParam("report-segmentation", "t", "report phrase segmentation in the output"); AddParam("stack", "s", "maximum stack size for histogram pruning"); AddParam("translation-details", "T", "for each best translation hypothesis, print out details about what sourcce spans were used, dropped"); AddParam("ttable-file", "location and properties of the translation tables"); @@ -67,50 +67,27 @@ Parameter::Parameter() AddParam("weight-l", "lm", "weight(s) for language models"); AddParam("weight-t", "tm", "weights for translation model components"); AddParam("weight-w", "w", "weight for word penalty"); - AddParam("weight-e", "e", "weight for word deletion"); //source word deletion overall weight - AddParam("weight-generation", "g", "weight(s) for generation components"); - AddParam("weight-i", "I", "weight for word insertion"); - AddParam("mapping", "description of decoding steps"); - AddParam("n-best-list", "file and size of n-best-list to be generated"); - AddParam("beam-threshold", "threshold for threshold pruning"); - AddParam("distortion-limit", "dl", "distortion (reordering) limit in maximum number of words"); - AddParam("input-factors", "list of factors in the input"); + AddParam("weight-e", "e", "weight for word deletion"); AddParam("output-factors", "list if factors in the output"); - AddParam("mysql", "(deprecated)"); - AddParam("input-file", "i", "location of the input file to be translated"); AddParam("cache-path", "?"); AddParam("distortion-file", "source factors (0 if table independent of source), target factors, location of the factorized/lexicalized reordering tables"); AddParam("distortion", "configurations for each factorized/lexicalized reordering model."); - AddParam("generation-file", "location and properties of the generation table"); - AddParam("stack", "s", "maximum stack size for histogram pruning"); - AddParam("verbose", "v", "verbosity level of the logging"); - AddParam("report-source-span", "?"); - AddParam("report-all-factors", "?"); - AddParam("drop-unknown", "du", "drop unknown words instead of copying them"); - AddParam("inputtype", "text (0) or confusion network (1)"); - AddParam("translation-details", "T", "for each best translation hypothesis, print out details about what sourcce spans were used, dropped"); - AddParam("max-trans-opt-per-coverage", "maximum number of translation options per input span (after applying mapping steps)"); - AddParam("max-partial-trans-opt", "maximum number of partial translation options per input span (during mapping steps)"); - AddParam("use-distortion-future-costs", "consider expected distortion cost in future cost estimation"); - AddParam("labeled-n-best-list", "labeled-n-best-list", "print out labels for each weight type in n-best list. default is true"); } /** initialize a parameter, sub of constructor */ -PARAM_VEC &Parameter::AddParam(const string ¶mName, const string &description) +void Parameter::AddParam(const string ¶mName, const string &description) { m_valid[paramName] = true; m_description[paramName] = description; - return m_setting[paramName]; } /** initialize a parameter (including abbreviation), sub of constructor */ -PARAM_VEC &Parameter::AddParam(const string ¶mName, const string &abbrevName, const string &description) +void Parameter::AddParam(const string ¶mName, const string &abbrevName, const string &description) { m_valid[paramName] = true; m_valid[abbrevName] = true; m_abbreviation[paramName] = abbrevName; m_description[paramName] = description; - return m_setting[paramName]; } /** print descriptions of all parameters */ @@ -177,17 +154,16 @@ bool Parameter::LoadParam(int argc, char* argv[]) // logging of parameters that were set in either config or switch int verbose = 1; - if (m_setting["verbose"].size() > 0) + if (m_setting.find("verbose") != m_setting.end() && + m_setting["verbose"].size() > 0) verbose = Scan<int>(m_setting["verbose"][0]); if (verbose >= 1) { // only if verbose cerr << "Defined parameters (per moses.ini or switch):" << endl; for(PARAM_MAP::const_iterator iterParam = m_setting.begin() ; iterParam != m_setting.end(); iterParam++) { - if (iterParam->second.size() > 0) { - cerr << "\t" << iterParam->first << ": "; - for ( size_t i = 0; i < iterParam->second.size(); i++ ) - cerr << iterParam->second[i] << " "; - cerr << endl; - } + cerr << "\t" << iterParam->first << ": "; + for ( size_t i = 0; i < iterParam->second.size(); i++ ) + cerr << iterParam->second[i] << " "; + cerr << endl; } } @@ -350,6 +326,7 @@ void Parameter::OverwriteParam(const string ¶mSwitch, const string ¶mNam 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) diff --git a/moses/src/Parameter.h b/moses/src/Parameter.h index 3ea5c4be2..321fec7a9 100755 --- a/moses/src/Parameter.h +++ b/moses/src/Parameter.h @@ -49,8 +49,8 @@ protected: bool isOption(const char* token); bool Validate(); - PARAM_VEC &AddParam(const std::string ¶mName, const std::string &description); - PARAM_VEC &AddParam(const std::string ¶mName, const std::string &abbrevName, const std::string &description); + void AddParam(const std::string ¶mName, const std::string &description); + void AddParam(const std::string ¶mName, const std::string &abbrevName, const std::string &description); public: Parameter(); @@ -62,6 +62,11 @@ public: { return m_setting[paramName]; } + /** check if parameter is defined (either in moses.ini or as switch) */ + bool isParamSpecified(const std::string ¶mName) + { + return m_setting.find( paramName ) != m_setting.end(); + } }; diff --git a/moses/src/StaticData.cpp b/moses/src/StaticData.cpp index a2b5313c9..5bd113df0 100755 --- a/moses/src/StaticData.cpp +++ b/moses/src/StaticData.cpp @@ -101,27 +101,14 @@ bool StaticData::LoadParameters(int argc, char* argv[]) m_nBestSize = 0; } - if (m_parameter.GetParam("labeled-n-best-list").size() == 1) - { - m_labeledNBestList = Scan<bool>( m_parameter.GetParam("labeled-n-best-list")[0]); - } - else - { - m_labeledNBestList = true; - } - + // include feature names in the n-best list + SetBooleanParameter( &m_labeledNBestList, "labeled-n-best-list", true ); // printing source phrase spans - if (m_parameter.GetParam("report-source-span").size() > 0) - m_reportSourceSpan = Scan<bool>(m_parameter.GetParam("report-source-span")[0]); - else - m_reportSourceSpan = false; + SetBooleanParameter( &m_reportSegmentation, "report-segmentation", false ); // print all factors of output translations - if (m_parameter.GetParam("report-all-factors").size() > 0) - m_reportAllFactors = Scan<bool>(m_parameter.GetParam("report-all-factors")[0]); - else - m_reportAllFactors = false; + SetBooleanParameter( &m_reportAllFactors, "report-all-factors", false ); //distortion weights const vector<string> distortionWeights = m_parameter.GetParam("weight-d"); @@ -158,25 +145,19 @@ bool StaticData::LoadParameters(int argc, char* argv[]) } //source word deletion - if(m_parameter.GetParam("phrase-drop-allowed").size() > 0) - { - m_wordDeletionEnabled = Scan<bool>(m_parameter.GetParam("phrase-drop-allowed")[0]); - } - else - { - m_wordDeletionEnabled = false; - } - if(m_parameter.GetParam("translation-details").size() > 0) { - m_isDetailedTranslationReportingEnabled = Scan<bool>( m_parameter.GetParam("translation-details")[0]); - } + SetBooleanParameter( &m_wordDeletionEnabled, "phrase-drop-allowed", false ); - if(m_parameter.GetParam("lmstats").size() > 0) { - m_computeLMBackoffStats = Scan<bool>( m_parameter.GetParam("lmstats")[0]); - if (!m_isDetailedTranslationReportingEnabled) { - std::cerr << "-lmstats implies -translation-details, enabling" << std::endl; - m_isDetailedTranslationReportingEnabled = true; - } + // additional output + SetBooleanParameter( &m_isDetailedTranslationReportingEnabled, + "translation-details", false ); + + SetBooleanParameter( &m_computeLMBackoffStats, "lmstats", false ); + if (m_computeLMBackoffStats && + ! m_isDetailedTranslationReportingEnabled) { + std::cerr << "-lmstats implies -translation-details, enabling" << std::endl; + m_isDetailedTranslationReportingEnabled = true; } + // load Lexical Reordering model const vector<string> &lrFileVector = m_parameter.GetParam("distortion-file"); @@ -451,16 +432,33 @@ bool StaticData::LoadParameters(int argc, char* argv[]) // Unknown Word Processing -- wade //TODO replace this w/general word dropping -- EVH - if (m_parameter.GetParam("drop-unknown").size() == 1) - { m_dropUnknown = Scan<bool>( m_parameter.GetParam("drop-unknown")[0]); } - else - { m_dropUnknown = 0; } - - //TRACE_ERR("m_dropUnknown: " << m_dropUnknown << endl); + SetBooleanParameter( &m_dropUnknown, "drop-unknown", false ); return true; } +void StaticData::SetBooleanParameter( bool *parameter, string parameterName, bool defaultValue ) { + + // default value if nothing is specified + *parameter = defaultValue; + if (! m_parameter.isParamSpecified( parameterName ) ) + { + return; + } + + // if parameter is just specified as, e.g. "-parameter" set it true + if (m_parameter.GetParam( parameterName ).size() == 0) + { + *parameter = true; + } + + // if paramter is specified "-parameter true" or "-parameter false" + else if (m_parameter.GetParam( parameterName ).size() == 1) + { + *parameter = Scan<bool>( m_parameter.GetParam( parameterName )[0]); + } +} + StaticData::~StaticData() { delete m_inputOutput; diff --git a/moses/src/StaticData.h b/moses/src/StaticData.h index ffea10979..1dcd526c2 100755 --- a/moses/src/StaticData.h +++ b/moses/src/StaticData.h @@ -94,7 +94,7 @@ protected: size_t m_verboseLevel; DistortionScoreProducer *m_distortionScoreProducer; WordPenaltyProducer *m_wpProducer; - bool m_reportSourceSpan; + bool m_reportSegmentation; bool m_reportAllFactors; bool m_useDistortionFutureCosts; bool m_isDetailedTranslationReportingEnabled; @@ -113,6 +113,7 @@ public: * also initialize the Parameter object */ bool LoadParameters(int argc, char* argv[]); + void SetBooleanParameter(bool *paramter, string parameterName, bool defaultValue); /*** * load not only the main phrase table but also any auxiliary tables that depend on which features are being used @@ -243,9 +244,9 @@ public: { return m_verboseLevel; } - bool GetReportSourceSpan() const + bool GetReportSegmentation() const { - return m_reportSourceSpan; + return m_reportSegmentation; } bool GetReportAllFactors() const { |