mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
refactor parsing of args for language models
This commit is contained in:
parent
40f4267373
commit
89f88fdb6b
@ -48,19 +48,8 @@ LanguageModelIRST::LanguageModelIRST(const std::string &line)
|
||||
throw runtime_error("Error: " + SPrint(threadCount) + " number of threads specified but IRST LM is not threadsafe.");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_args.size(); ++i) {
|
||||
const vector<string> &args = m_args[i];
|
||||
ReadParameters();
|
||||
|
||||
if (args[0] == "factor") {
|
||||
m_factorType = Scan<FactorType>(args[1]);
|
||||
} else if (args[0] == "order") {
|
||||
m_nGramOrder = Scan<size_t>(args[1]);
|
||||
} else if (args[0] == "path") {
|
||||
m_filePath = args[1];
|
||||
} else {
|
||||
throw "Unknown argument " + args[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LanguageModelIRST::~LanguageModelIRST()
|
||||
|
@ -41,6 +41,23 @@ using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
LanguageModelImplementation::LanguageModelImplementation(const std::string& description, const std::string &line)
|
||||
:LanguageModel(description, line) {
|
||||
}
|
||||
|
||||
void LanguageModelImplementation::SetParameter(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "order") {
|
||||
m_nGramOrder = Scan<size_t>(value);
|
||||
}
|
||||
else if (key == "path") {
|
||||
m_filePath = value;
|
||||
}
|
||||
else {
|
||||
LanguageModel::SetParameter(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LanguageModelImplementation::ShiftOrPush(std::vector<const Word*> &contextFactor, const Word &word) const
|
||||
{
|
||||
|
@ -61,13 +61,14 @@ protected:
|
||||
Word m_sentenceStartWord, m_sentenceEndWord; //! Contains factors which represents the beging and end words for this LM.
|
||||
//! Usually <s> and </s>
|
||||
|
||||
LanguageModelImplementation(const std::string& description, const std::string &line)
|
||||
:LanguageModel(description, line) {
|
||||
}
|
||||
LanguageModelImplementation(const std::string& description, const std::string &line);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~LanguageModelImplementation() {}
|
||||
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
|
||||
/* get score of n-gram. n-gram should not be bigger than m_nGramOrder
|
||||
* Specific implementation can return State and len data to be used in hypothesis pruning
|
||||
* \param contextFactor n-gram to be scored
|
||||
|
@ -43,20 +43,7 @@ LanguageModelSRI::LanguageModelSRI(const std::string &line)
|
||||
,m_srilmVocab(0)
|
||||
,m_srilmModel(0)
|
||||
{
|
||||
for (size_t i = 0; i < m_args.size(); ++i) {
|
||||
const vector<string> &args = m_args[i];
|
||||
|
||||
if (args[0] == "factor") {
|
||||
m_factorType = Scan<FactorType>(args[1]);
|
||||
} else if (args[0] == "order") {
|
||||
m_nGramOrder = Scan<size_t>(args[1]);
|
||||
} else if (args[0] == "path") {
|
||||
m_filePath = args[1];
|
||||
} else {
|
||||
throw "Unknown argument " + args[0];
|
||||
}
|
||||
}
|
||||
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
LanguageModelSRI::~LanguageModelSRI()
|
||||
|
@ -72,6 +72,16 @@ bool LanguageModelSingleFactor::IsUseable(const FactorMask &mask) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LanguageModelSingleFactor::SetParameter(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "factor") {
|
||||
m_factorType = Scan<FactorType>(value);
|
||||
}
|
||||
else {
|
||||
LanguageModelImplementation::SetParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,6 +48,7 @@ protected:
|
||||
public:
|
||||
virtual ~LanguageModelSingleFactor();
|
||||
bool IsUseable(const FactorMask &mask) const;
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
|
||||
const Factor *GetSentenceStart() const {
|
||||
return m_sentenceStart;
|
||||
|
Loading…
Reference in New Issue
Block a user