Пример #1
0
void Rules::CalcFractionalCount()
{
  typedef std::set<Rule*> RuleColl;
  typedef std::map<const ConsistentPhrase*, RuleColl> RuleByConsistentPhrase;
  RuleByConsistentPhrase allRules;

  // sort by source AND target ranges
  std::set<Rule*>::const_iterator iter;
  for (iter = m_keepRules.begin(); iter != m_keepRules.end(); ++iter) {
    Rule *rule = *iter;
    const ConsistentPhrase &cp = rule->GetConsistentPhrase();
    RuleColl &ruleColl =  allRules[&cp];
    ruleColl.insert(rule);
  }

  // fractional count
  RuleByConsistentPhrase::iterator iterOuter;
  for (iterOuter = allRules.begin(); iterOuter != allRules.end(); ++iterOuter) {
    RuleColl &rules = iterOuter->second;

    RuleColl::iterator iterInner;
    for (iterInner = rules.begin(); iterInner != rules.end(); ++iterInner) {
      Rule &rule = **iterInner;
      rule.SetCount(1.0f / (float) rules.size());
    }
  }

}
Пример #2
0
void Rules::Extend(const Rule &rule, const Parameter &params)
{
  const ConsistentPhrases &allCPS = m_alignedSentence.GetConsistentPhrases();
  int sourceMin = rule.GetNextSourcePosForNonTerm();

  int ruleStart = rule.GetConsistentPhrase().corners[0];
  int ruleEnd = rule.GetConsistentPhrase().corners[1];

  for (int sourceStart = sourceMin; sourceStart <= ruleEnd; ++sourceStart) {
    for (int sourceEnd = sourceStart; sourceEnd <= ruleEnd; ++sourceEnd) {
      if (sourceStart == ruleStart && sourceEnd == ruleEnd) {
        // don't cover whole rule with 1 non-term
        continue;
      }

      const ConsistentPhrases::Coll &cps = allCPS.GetColl(sourceStart, sourceEnd);
      Extend(rule, cps, params);
    }
  }
}