mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +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.");
|
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) {
|
ReadParameters();
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageModelIRST::~LanguageModelIRST()
|
LanguageModelIRST::~LanguageModelIRST()
|
||||||
|
@ -41,6 +41,23 @@ using namespace std;
|
|||||||
|
|
||||||
namespace Moses
|
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
|
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.
|
Word m_sentenceStartWord, m_sentenceEndWord; //! Contains factors which represents the beging and end words for this LM.
|
||||||
//! Usually <s> and </s>
|
//! Usually <s> and </s>
|
||||||
|
|
||||||
LanguageModelImplementation(const std::string& description, const std::string &line)
|
LanguageModelImplementation(const std::string& description, const std::string &line);
|
||||||
:LanguageModel(description, line) {
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~LanguageModelImplementation() {}
|
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
|
/* 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
|
* Specific implementation can return State and len data to be used in hypothesis pruning
|
||||||
* \param contextFactor n-gram to be scored
|
* \param contextFactor n-gram to be scored
|
||||||
|
@ -43,20 +43,7 @@ LanguageModelSRI::LanguageModelSRI(const std::string &line)
|
|||||||
,m_srilmVocab(0)
|
,m_srilmVocab(0)
|
||||||
,m_srilmModel(0)
|
,m_srilmModel(0)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_args.size(); ++i) {
|
ReadParameters();
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageModelSRI::~LanguageModelSRI()
|
LanguageModelSRI::~LanguageModelSRI()
|
||||||
|
@ -72,6 +72,16 @@ bool LanguageModelSingleFactor::IsUseable(const FactorMask &mask) const
|
|||||||
return ret;
|
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:
|
public:
|
||||||
virtual ~LanguageModelSingleFactor();
|
virtual ~LanguageModelSingleFactor();
|
||||||
bool IsUseable(const FactorMask &mask) const;
|
bool IsUseable(const FactorMask &mask) const;
|
||||||
|
void SetParameter(const std::string& key, const std::string& value);
|
||||||
|
|
||||||
const Factor *GetSentenceStart() const {
|
const Factor *GetSentenceStart() const {
|
||||||
return m_sentenceStart;
|
return m_sentenceStart;
|
||||||
|
Loading…
Reference in New Issue
Block a user