add DALM. Just a skeleton so far

This commit is contained in:
Hieu Hoang 2013-11-05 14:37:56 +00:00
parent 7e78dc5a63
commit 08d888382d
5 changed files with 95 additions and 0 deletions

View File

@ -48,6 +48,7 @@
<listOptionValue builtIn="false" value="KENLM_MAX_ORDER=7"/>
<listOptionValue builtIn="false" value="TRACE_ENABLE"/>
<listOptionValue builtIn="false" value="LM_IRST"/>
<listOptionValue builtIn="false" value="LM_DALM"/>
<listOptionValue builtIn="false" value="LM_RAND"/>
<listOptionValue builtIn="false" value="LM_NPLM"/>
<listOptionValue builtIn="false" value="_FILE_OFFSET_BIT=64"/>

View File

@ -1371,6 +1371,16 @@
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/LM/ChartState.h</locationURI>
</link>
<link>
<name>LM/DALM.cpp</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/LM/DALM.cpp</locationURI>
</link>
<link>
<name>LM/DALM.h</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/LM/DALM.h</locationURI>
</link>
<link>
<name>LM/IRST.cpp</name>
<type>1</type>

View File

@ -65,6 +65,10 @@
#include "moses/LM/NeuralLMWrapper.h"
#endif
#ifdef LM_DALM
#include "moses/LM/DALM.h"
#endif
#include "util/exception.hh"
#include <vector>
@ -183,6 +187,9 @@ FeatureRegistry::FeatureRegistry()
#ifdef LM_NEURAL
MOSES_FNAME2("NeuralLM", NeuralLMWrapper);
#endif
#ifdef LM_DALM
MOSES_FNAME2("DALM", LanguageModelDALM);
#endif
Add("KENLM", new KenFactory());
}

55
moses/LM/DALM.cpp Normal file
View File

@ -0,0 +1,55 @@
#include "DALM.h"
#include "moses/FactorCollection.h"
using namespace std;
namespace Moses
{
LanguageModelDALM::LanguageModelDALM(const std::string &line)
:LanguageModelSingleFactor(line)
{
ReadParameters();
if (m_factorType == NOT_FOUND) {
m_factorType = 0;
}
FactorCollection &factorCollection = FactorCollection::Instance();
// needed by parent language model classes. Why didn't they set these themselves?
m_sentenceStart = factorCollection.AddFactor(Output, m_factorType, BOS_);
m_sentenceStartWord[m_factorType] = m_sentenceStart;
m_sentenceEnd = factorCollection.AddFactor(Output, m_factorType, EOS_);
m_sentenceEndWord[m_factorType] = m_sentenceEnd;
}
LanguageModelDALM::~LanguageModelDALM()
{
}
LMResult LanguageModelDALM::GetValue(const vector<const Word*> &contextFactor, State* finalState) const
{
LMResult ret;
ret.score = contextFactor.size();
ret.unknown = false;
// use last word as state info
const Factor *factor;
size_t hash_value(const Factor &f);
if (contextFactor.size()) {
factor = contextFactor.back()->GetFactor(m_factorType);
} else {
factor = NULL;
}
(*finalState) = (State*) factor;
return ret;
}
}

22
moses/LM/DALM.h Normal file
View File

@ -0,0 +1,22 @@
// $Id$
#pragma once
#include <vector>
#include "SingleFactor.h"
namespace Moses
{
class LanguageModelDALM : public LanguageModelSingleFactor
{
protected:
public:
LanguageModelDALM(const std::string &line);
~LanguageModelDALM();
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const;
};
}