mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 21:03:22 +03:00
dea76752e9
This is one of those little chores in managing a long-lived C++ project: standard C headers like stdio.h and math.h now have their own place in the C++ standard as resp. cstdio, cmath, and so on. In this branch the #include names are updated for the search/ subdirectory; more branches to follow. C++11 adds cstdint, but to support compilation with the previous standard, that change is left for later.
44 lines
1.8 KiB
C++
44 lines
1.8 KiB
C++
#include "search/rule.hh"
|
|
|
|
#include "lm/model.hh"
|
|
#include "search/context.hh"
|
|
|
|
#include <ostream>
|
|
|
|
#include <cmath>
|
|
|
|
namespace search {
|
|
|
|
template <class Model> ScoreRuleRet ScoreRule(const Model &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing) {
|
|
ScoreRuleRet ret;
|
|
ret.prob = 0.0;
|
|
ret.oov = 0;
|
|
const lm::WordIndex oov = model.GetVocabulary().NotFound(), bos = model.GetVocabulary().BeginSentence();
|
|
lm::ngram::RuleScore<Model> scorer(model, *(writing++));
|
|
std::vector<lm::WordIndex>::const_iterator word = words.begin();
|
|
if (word != words.end() && *word == bos) {
|
|
scorer.BeginSentence();
|
|
++word;
|
|
}
|
|
for (; word != words.end(); ++word) {
|
|
if (*word == kNonTerminal) {
|
|
ret.prob += scorer.Finish();
|
|
scorer.Reset(*(writing++));
|
|
} else {
|
|
if (*word == oov) ++ret.oov;
|
|
scorer.Terminal(*word);
|
|
}
|
|
}
|
|
ret.prob += scorer.Finish();
|
|
return ret;
|
|
}
|
|
|
|
template ScoreRuleRet ScoreRule(const lm::ngram::RestProbingModel &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing);
|
|
template ScoreRuleRet ScoreRule(const lm::ngram::ProbingModel &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing);
|
|
template ScoreRuleRet ScoreRule(const lm::ngram::TrieModel &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing);
|
|
template ScoreRuleRet ScoreRule(const lm::ngram::QuantTrieModel &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing);
|
|
template ScoreRuleRet ScoreRule(const lm::ngram::ArrayTrieModel &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing);
|
|
template ScoreRuleRet ScoreRule(const lm::ngram::QuantArrayTrieModel &model, const std::vector<lm::WordIndex> &words, lm::ngram::ChartState *writing);
|
|
|
|
} // namespace search
|