Exemple #1
0
void SpanLength::EvaluateWithSourceContext(const InputType &input
    , const InputPath &inputPath
    , const TargetPhrase &targetPhrase
    , const StackVec *stackVec
    , ScoreComponentCollection &scoreBreakdown
    , ScoreComponentCollection *estimatedFutureScore) const
{
  assert(stackVec);

  const PhraseProperty *property = targetPhrase.GetProperty("SpanLength");
  if (property == NULL) {
    return;
  }

  const SpanLengthPhraseProperty *slProp = static_cast<const SpanLengthPhraseProperty*>(property);

  const Phrase *ruleSource = targetPhrase.GetRuleSource();
  assert(ruleSource);

  float score = 0;
  for (size_t i = 0; i < stackVec->size(); ++i) {
    const ChartCellLabel &cell = *stackVec->at(i);
    const WordsRange &ntRange = cell.GetCoverage();
    size_t sourceWidth = ntRange.GetNumWordsCovered();
    float prob = slProp->GetProb(i, sourceWidth, m_const);
    score += TransformScore(prob);
  }

  if (score < -100.0f) {
    float weight = StaticData::Instance().GetWeight(this);
    if (weight < 0) {
      score = -100;
    }
  }

  scoreBreakdown.PlusEquals(this, score);

}
void MaxSpanFreeNonTermSource::EvaluateWithSourceContext(const InputType &input
    , const InputPath &inputPath
    , const TargetPhrase &targetPhrase
    , const StackVec *stackVec
    , ScoreComponentCollection &scoreBreakdown
    , ScoreComponentCollection *estimatedScores) const
{
  const Word &targetLHS = targetPhrase.GetTargetLHS();

  if (targetLHS == m_glueTargetLHS) {
    // don't delete glue rules
    return;
  }

  const Phrase *source = targetPhrase.GetRuleSource();
  assert(source);
  float score = 0;

  if (source->Front().IsNonTerminal()) {
    const ChartCellLabel &cell = *stackVec->front();
    if (cell.GetCoverage().GetNumWordsCovered() > m_maxSpan) {
      score = - std::numeric_limits<float>::infinity();
    }
  }

  if (source->Back().IsNonTerminal()) {
    const ChartCellLabel &cell = *stackVec->back();
    if (cell.GetCoverage().GetNumWordsCovered() > m_maxSpan) {
      score = - std::numeric_limits<float>::infinity();
    }
  }


  scoreBreakdown.PlusEquals(this, score);

}