From 460d8e9692aeaa983f5090c938cd72678387470b Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Sat, 31 Oct 2015 08:56:40 +0000 Subject: [PATCH] LM state --- contrib/other-builds/moses2/LanguageModel.cpp | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/contrib/other-builds/moses2/LanguageModel.cpp b/contrib/other-builds/moses2/LanguageModel.cpp index bff36287c..80178c4bc 100644 --- a/contrib/other-builds/moses2/LanguageModel.cpp +++ b/contrib/other-builds/moses2/LanguageModel.cpp @@ -207,10 +207,25 @@ std::pair LanguageModel::Score(const std::vector LMNode; vector nodes = m_root.getNodes(context, stoppedAtInd); - const LMNode &lastNode = *nodes.back(); + const LMNode *lastNode = nodes.back(); + assert(lastNode); - ret.first = lastNode.getValue().prob; - ret.second = (void*) &lastNode; + ret.first = lastNode->getValue().prob; + + if (m_order == 1) { + // no state + ret.second = NULL; + } + else if (nodes.size() == m_order) { + // found entire ngram + const LMNode *state = nodes[nodes.size() - 2]; + assert(state); + ret.second = (void*) state; + } + else { + // backed off + ret.second = (void*) lastNode; + } if (stoppedAtInd == context.size()) { // found entire ngram