コード例 #1
0
void
LexicalReordering::
SetCache(TranslationOption& to) const
{
  if (to.GetLexReorderingScores(this)) return;
  // Scores were were set already (e.g., by sampling phrase table)

  if (m_table) {
    Phrase const& sphrase = to.GetInputPath().GetPhrase();
    Phrase const& tphrase = to.GetTargetPhrase();
    to.CacheLexReorderingScores(*this, this->GetProb(sphrase,tphrase));
  } else { // e.g. OOV with Mmsapt
    // Scores vals(GetNumScoreComponents(), 0);
    // to.CacheLexReorderingScores(*this, vals);
  }
}
コード例 #2
0
void LexicalReorderingState::CopyScores(Scores& scores, const TranslationOption &topt, ReorderingType reoType) const
{
  // don't call this on a bidirectional object
  CHECK(m_direction == LexicalReorderingConfiguration::Backward || m_direction == LexicalReorderingConfiguration::Forward);
  const Scores *cachedScores = (m_direction == LexicalReorderingConfiguration::Backward) ?
                               topt.GetLexReorderingScores(m_configuration.GetScoreProducer()) : m_prevScore;

  // No scores available. TODO: Using a good prior distribution would be nicer.
  if(cachedScores == NULL)
    return;

  const Scores &scoreSet = *cachedScores;
  if(m_configuration.CollapseScores())
    scores[m_offset] = scoreSet[m_offset + reoType];
  else {
    std::fill(scores.begin() + m_offset, scores.begin() + m_offset + m_configuration.GetNumberOfTypes(), 0);
    scores[m_offset + reoType] = scoreSet[m_offset + reoType];
  }
}