本文整理汇总了C++中Hypothesis::GetCoverage方法的典型用法代码示例。如果您正苦于以下问题:C++ Hypothesis::GetCoverage方法的具体用法?C++ Hypothesis::GetCoverage怎么用?C++ Hypothesis::GetCoverage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hypothesis
的用法示例。
在下文中一共展示了Hypothesis::GetCoverage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Evaluate
size_t LM::Evaluate(
const Hypothesis& hypo,
size_t prevState,
Scores &scores) const
{
if (m_order <= 1) {
return 0; // not sure if returning NULL is correct
}
if (hypo.targetPhrase.GetSize() == 0) {
return 0; // not sure if returning NULL is correct
}
PhraseVec m_phraseVec(m_order);
const size_t currEndPos = hypo.targetRange.endPos;
const size_t startPos = hypo.targetRange.startPos;
size_t index = 0;
for (int currPos = (int) startPos - (int) m_order + 1 ; currPos <= (int) startPos ; currPos++) {
if (currPos >= 0)
m_phraseVec[index++] = &hypo.GetWord(currPos);
else {
m_phraseVec[index++] = &m_bos;
}
}
SCORE lmScore = GetValueCache(m_phraseVec);
// main loop
size_t endPos = std::min(startPos + m_order - 2
, currEndPos);
for (size_t currPos = startPos + 1 ; currPos <= endPos ; currPos++) {
// shift all args down 1 place
for (size_t i = 0 ; i < m_order - 1 ; i++)
m_phraseVec[i] = m_phraseVec[i + 1];
// add last factor
m_phraseVec.back() = &hypo.GetWord(currPos);
lmScore += GetValueCache(m_phraseVec);
}
// end of sentence
if (hypo.GetCoverage().IsComplete()) {
const size_t size = hypo.GetSize();
m_phraseVec.back() = &m_eos;
for (size_t i = 0 ; i < m_order - 1 ; i ++) {
int currPos = (int)(size - m_order + i + 1);
if (currPos < 0)
m_phraseVec[i] = &m_bos;
else
m_phraseVec[i] = &hypo.GetWord((size_t)currPos);
}
lmScore += GetValueCache(m_phraseVec);
} else {
if (endPos < currEndPos) {
//need to get the LM state (otherwise the last LM state is fine)
for (size_t currPos = endPos+1; currPos <= currEndPos; currPos++) {
for (size_t i = 0 ; i < m_order - 1 ; i++)
m_phraseVec[i] = m_phraseVec[i + 1];
m_phraseVec.back() = &hypo.GetWord(currPos);
}
}
}
size_t state = GetLastState();
return state;
}