コード例 #1
0
void UnknownWordPenalty::Lookup(const std::vector<InputPath*> &inputPathQueue)
{
  Scores *estimatedFutureScore = new Scores();

  for (size_t i = 0; i < inputPathQueue.size(); ++i) {
    InputPath &path = *inputPathQueue[i];
    PhraseTableLookup &ptLookup = path.GetPtLookup(m_ptId);

    const Phrase &source = path.GetPhrase();
    if (source.GetSize() == 1) {
      const Word &sourceWord = source.GetWord(0);
      string str = sourceWord.ToString();
      str = "UNK:" + str + ":UNK";

      Word targetWord;
      targetWord.CreateFromString(str);

      TargetPhrase *tp = new TargetPhrase(1);
      tp->Set(0, targetWord);
      tp->GetScores().Add(*this, LOWEST_SCORE);

      FeatureFunction::Evaluate(source, *tp, *estimatedFutureScore);

      TargetPhrases *tpColl = new TargetPhrases();
      m_targetPhrases.push_back(tpColl);
      tpColl->Add(tp);

      ptLookup.Set(tpColl, NULL);
    } else {
      ptLookup.Set(NULL, NULL);
    }
  }
}