2013-09-23 18:30:28 +04:00
|
|
|
/// $Id$
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_Parameter_h
|
|
|
|
#define moses_Parameter_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <string>
|
2013-02-07 00:05:00 +04:00
|
|
|
#include <set>
|
2008-06-11 14:52:57 +04:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include "TypeDef.h"
|
2014-11-27 20:49:08 +03:00
|
|
|
#include "Util.h"
|
2015-03-05 03:34:02 +03:00
|
|
|
#include <boost/program_options.hpp>
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2013-09-25 03:47:08 +04:00
|
|
|
typedef std::vector<std::string> PARAM_VEC;
|
|
|
|
typedef std::map<std::string, PARAM_VEC > PARAM_MAP;
|
2008-06-11 14:52:57 +04:00
|
|
|
typedef std::map<std::string, bool> PARAM_BOOL;
|
|
|
|
typedef std::map<std::string, std::string > PARAM_STRING;
|
|
|
|
|
|
|
|
/** Handles parameter values set in config file or on command line.
|
2011-02-24 16:14:42 +03:00
|
|
|
* Process raw parameter data (names and values as strings) for StaticData
|
2013-05-29 21:16:15 +04:00
|
|
|
* to parse; to get useful values, see StaticData.
|
2012-06-29 02:29:46 +04:00
|
|
|
*/
|
2008-06-11 14:52:57 +04:00
|
|
|
class Parameter
|
|
|
|
{
|
2015-03-05 03:34:02 +03:00
|
|
|
typedef boost::program_options::options_description options_description;
|
|
|
|
typedef boost::program_options::value_semantic value_semantic;
|
2008-06-11 14:52:57 +04:00
|
|
|
protected:
|
2013-05-29 21:16:15 +04:00
|
|
|
PARAM_MAP m_setting;
|
|
|
|
PARAM_BOOL m_valid;
|
|
|
|
PARAM_STRING m_abbreviation;
|
|
|
|
PARAM_STRING m_description;
|
|
|
|
PARAM_STRING m_fullname;
|
2015-04-30 08:05:11 +03:00
|
|
|
// std::map<char,std::set<std::string> > m_confusable;
|
|
|
|
// stores long parameter names that start with a letter that is also a short option.
|
2015-03-05 03:34:02 +03:00
|
|
|
options_description m_options;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2012-12-05 21:12:01 +04:00
|
|
|
std::map<std::string, std::vector<float> > m_weights;
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
std::string FindParam(const std::string ¶mSwitch, int argc, char* argv[]);
|
|
|
|
void OverwriteParam(const std::string ¶mSwitch, const std::string ¶mName, int argc, char* argv[]);
|
|
|
|
bool ReadConfigFile(const std::string &filePath );
|
|
|
|
bool FilesExist(const std::string ¶mName, int fieldNo, std::vector<std::string> const& fileExtension=std::vector<std::string>(1,""));
|
|
|
|
bool isOption(const char* token);
|
|
|
|
bool Validate();
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2015-04-30 08:05:11 +03:00
|
|
|
void
|
2015-03-05 03:34:02 +03:00
|
|
|
AddParam(options_description& optgroup,
|
2015-05-02 13:45:24 +03:00
|
|
|
value_semantic const* optvalue,
|
|
|
|
std::string const& paramName,
|
|
|
|
std::string const& description);
|
2015-03-05 03:34:02 +03:00
|
|
|
|
2015-04-30 08:05:11 +03:00
|
|
|
void
|
2015-03-05 03:34:02 +03:00
|
|
|
AddParam(options_description& optgroup,
|
2015-05-02 13:45:24 +03:00
|
|
|
std::string const ¶mName,
|
|
|
|
std::string const &description);
|
2015-03-05 03:34:02 +03:00
|
|
|
|
2015-04-30 08:05:11 +03:00
|
|
|
void
|
2015-03-05 03:34:02 +03:00
|
|
|
AddParam(options_description& optgroup,
|
2015-05-02 13:45:24 +03:00
|
|
|
value_semantic const* optvalue,
|
|
|
|
std::string const& paramName,
|
|
|
|
std::string const& abbrevName,
|
|
|
|
std::string const& description);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2015-04-30 08:05:11 +03:00
|
|
|
void
|
2015-03-05 03:34:02 +03:00
|
|
|
AddParam(options_description& optgroup,
|
2015-05-02 13:45:24 +03:00
|
|
|
std::string const& paramName,
|
|
|
|
std::string const& abbrevName,
|
|
|
|
std::string const& description);
|
2015-04-30 08:05:11 +03:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
void PrintCredit();
|
2013-11-01 19:16:47 +04:00
|
|
|
void PrintFF() const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2012-12-12 22:30:11 +04:00
|
|
|
void SetWeight(const std::string &name, size_t ind, float weight);
|
|
|
|
void SetWeight(const std::string &name, size_t ind, const std::vector<float> &weights);
|
|
|
|
void AddWeight(const std::string &name, size_t ind, const std::vector<float> &weights);
|
2012-12-05 21:12:01 +04:00
|
|
|
void ConvertWeightArgs();
|
2012-12-12 22:30:11 +04:00
|
|
|
void ConvertWeightArgsSingleWeight(const std::string &oldWeightName, const std::string &newWeightName);
|
2013-02-22 23:17:57 +04:00
|
|
|
void ConvertWeightArgsPhraseModel(const std::string &oldWeightName);
|
2013-04-26 22:39:29 +04:00
|
|
|
void ConvertWeightArgsLM();
|
2012-12-12 22:30:11 +04:00
|
|
|
void ConvertWeightArgsDistortion();
|
2012-12-12 23:35:06 +04:00
|
|
|
void ConvertWeightArgsGeneration(const std::string &oldWeightName, const std::string &newWeightName);
|
2013-08-12 01:32:54 +04:00
|
|
|
void ConvertWeightArgsPhrasePenalty();
|
2013-04-24 22:23:14 +04:00
|
|
|
void ConvertWeightArgsWordPenalty();
|
2013-08-14 15:36:40 +04:00
|
|
|
void ConvertPhrasePenalty();
|
2012-12-05 21:12:01 +04:00
|
|
|
void CreateWeightsMap();
|
2014-05-31 22:52:30 +04:00
|
|
|
void CreateWeightsMap(const PARAM_VEC &vec);
|
2012-12-05 21:12:01 +04:00
|
|
|
void WeightOverwrite();
|
2013-01-15 22:32:13 +04:00
|
|
|
void AddFeature(const std::string &line);
|
2013-08-13 18:34:03 +04:00
|
|
|
void AddFeaturesCmd();
|
2012-12-05 21:12:01 +04:00
|
|
|
|
2012-12-11 22:57:42 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
Parameter();
|
|
|
|
~Parameter();
|
|
|
|
bool LoadParam(int argc, char* argv[]);
|
|
|
|
bool LoadParam(const std::string &filePath);
|
|
|
|
void Explain();
|
|
|
|
|
|
|
|
/** return a vector of strings holding the whitespace-delimited values on the ini-file line corresponding to the given parameter name */
|
2014-11-28 21:33:45 +03:00
|
|
|
const PARAM_VEC *GetParam(const std::string ¶mName) const;
|
2014-11-20 18:02:05 +03:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
/** check if parameter is defined (either in moses.ini or as switch) */
|
2014-11-20 14:21:50 +03:00
|
|
|
bool isParamSpecified(const std::string ¶mName) const {
|
2011-02-24 16:14:42 +03:00
|
|
|
return m_setting.find( paramName ) != m_setting.end();
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
void OverwriteParam(const std::string ¶mName, PARAM_VEC values);
|
|
|
|
|
2013-11-11 19:32:58 +04:00
|
|
|
std::vector<float> GetWeights(const std::string &name);
|
2014-01-20 19:54:17 +04:00
|
|
|
std::map<std::string, std::vector<float> > GetAllWeights() const {
|
2014-05-19 17:34:27 +04:00
|
|
|
return m_weights;
|
2014-01-20 19:54:17 +04:00
|
|
|
}
|
2013-02-07 00:05:00 +04:00
|
|
|
std::set<std::string> GetWeightNames() const;
|
2012-12-05 21:12:01 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const PARAM_MAP &GetParams() const {
|
|
|
|
return m_setting;
|
|
|
|
}
|
2012-12-05 21:12:01 +04:00
|
|
|
|
2013-06-04 20:01:10 +04:00
|
|
|
void Save(const std::string path);
|
2014-11-27 20:49:08 +03:00
|
|
|
|
|
|
|
template<typename T>
|
2015-01-14 14:07:42 +03:00
|
|
|
void SetParameter(T &var, const std::string &name, const T &defaultValue) const {
|
|
|
|
const PARAM_VEC *params = GetParam(name);
|
|
|
|
if (params && params->size()) {
|
|
|
|
var = Scan<T>( params->at(0));
|
|
|
|
} else {
|
|
|
|
var = defaultValue;
|
|
|
|
}
|
2014-11-27 20:49:08 +03:00
|
|
|
}
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
};
|
|
|
|
|
2014-11-30 23:15:15 +03:00
|
|
|
template<>
|
|
|
|
void Parameter::SetParameter<bool>(bool &var, const std::string &name, const bool &defaultValue) const;
|
2014-11-27 20:49:08 +03:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|