refactor parsing of args for language models

This commit is contained in:
Hieu Hoang 2013-08-28 11:05:47 +01:00
parent 40f4267373
commit 89f88fdb6b
6 changed files with 34 additions and 29 deletions

View File

@ -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()

View File

@ -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
{

View File

@ -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

View File

@ -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()

View File

@ -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);
}
}
}

View File

@ -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;