mosesdecoder/moses/LM/DALMWrapper.h

103 lines
2.5 KiB
C
Raw Normal View History

2013-11-05 18:37:56 +04:00
// $Id$
#pragma once
#include <vector>
2013-12-16 18:17:56 +04:00
#include "Implementation.h"
#include "moses/Hypothesis.h"
2013-11-05 18:37:56 +04:00
namespace DALM
{
class Logger;
class Vocabulary;
2013-12-16 18:17:56 +04:00
class State;
class LM;
2014-06-03 11:13:32 +04:00
union Fragment;
class Gap;
2013-11-11 23:49:00 +04:00
typedef unsigned int VocabId;
}
2013-11-05 18:37:56 +04:00
namespace Moses
{
2013-11-11 23:49:00 +04:00
class Factor;
2014-06-03 11:13:32 +04:00
class DALMChartState;
2013-11-05 18:37:56 +04:00
2013-12-16 18:17:56 +04:00
class LanguageModelDALM : public LanguageModel
2013-11-05 18:37:56 +04:00
{
2013-12-16 18:17:56 +04:00
public:
LanguageModelDALM(const std::string &line);
virtual ~LanguageModelDALM();
2014-01-15 19:42:02 +04:00
2015-12-10 06:17:36 +03:00
void Load(AllOptions::ptr const& opts);
2013-12-16 18:17:56 +04:00
virtual const FFState *EmptyHypothesisState(const InputType &/*input*/) const;
virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const;
virtual FFState *EvaluateWhenApplied(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const;
2013-12-16 18:17:56 +04:00
virtual FFState *EvaluateWhenApplied(const ChartHypothesis& hypo, int featureID, ScoreComponentCollection *out) const;
2013-12-16 18:17:56 +04:00
virtual bool IsUseable(const FactorMask &mask) const;
2014-01-15 19:42:02 +04:00
virtual void SetParameter(const std::string& key, const std::string& value);
2013-11-05 18:37:56 +04:00
protected:
2013-12-16 18:17:56 +04:00
const Factor *m_beginSentenceFactor;
FactorType m_factorType;
std::string m_filePath;
size_t m_nGramOrder; //! max n-gram length contained in this LM
2014-06-08 11:44:59 +04:00
size_t m_ContextSize;
2013-12-16 18:17:56 +04:00
2014-01-15 19:42:02 +04:00
DALM::Logger *m_logger;
DALM::Vocabulary *m_vocab;
DALM::LM *m_lm;
DALM::VocabId wid_start, wid_end;
2013-11-11 23:49:00 +04:00
mutable std::vector<DALM::VocabId> m_vocabMap;
2013-11-18 17:54:40 +04:00
2014-01-15 19:42:02 +04:00
void CreateVocabMapping(const std::string &wordstxt);
DALM::VocabId GetVocabId(const Factor *factor) const;
2013-11-11 23:49:00 +04:00
2013-12-16 18:17:56 +04:00
private:
// Convert last words of hypothesis into vocab ids, returning an end pointer.
DALM::VocabId *LastIDs(const Hypothesis &hypo, DALM::VocabId *indices) const {
DALM::VocabId *index = indices;
DALM::VocabId *end = indices + m_nGramOrder - 1;
int position = hypo.GetCurrTargetWordsRange().GetEndPos();
for (; ; ++index, --position) {
if (index == end) return index;
if (position == -1) {
*index = wid_start;
return index + 1;
}
*index = GetVocabId(hypo.GetWord(position).GetFactor(m_factorType));
}
}
2014-06-03 11:13:32 +04:00
2014-06-08 11:44:59 +04:00
void EvaluateTerminal(
const Word &word,
float &hypoScore,
DALMChartState *newState,
DALM::State &state,
DALM::Fragment *prefixFragments,
unsigned char &prefixLength
) const;
void EvaluateNonTerminal(
const Word &word,
float &hypoScore,
DALMChartState *newState,
DALM::State &state,
DALM::Fragment *prefixFragments,
unsigned char &prefixLength,
const DALMChartState *prevState,
2015-01-12 07:05:27 +03:00
size_t prevTargetPhraseLength
2014-06-08 11:44:59 +04:00
) const;
2013-11-05 18:37:56 +04:00
};
}
2013-12-16 18:17:56 +04:00