Ejemplo n.º 1
0
void Rules::CreateRule(const NonTerm &nonTerm,
                       const Parameter &params)
{
  Rule *rule = new Rule(nonTerm, m_alignedSentence);

  rule->Prevalidate(params);
  rule->CreateTarget(params);
  rule->CreateProperties(params);

  if (rule->CanRecurse()) {
    Extend(*rule, params);
  }

  if (rule->IsValid()) {
    m_keepRules.insert(rule);
  } else {
    delete rule;
  }

}
Ejemplo n.º 2
0
void Rules::Extend(const Rule &rule, const ConsistentPhrase &cp, const Parameter &params)
{
  const ConsistentPhrase::NonTerms &nonTerms = cp.GetNonTerms();
  for (size_t i = 0; i < nonTerms.size(); ++i) {
    const NonTerm &nonTerm = nonTerms[i];

    Rule *newRule = new Rule(rule, nonTerm);
    newRule->Prevalidate(params);
    newRule->CreateTarget(params);
    newRule->CreateProperties(params);

    if (newRule->CanRecurse()) {
      // recursively extend
      Extend(*newRule, params);
    }

    if (newRule->IsValid()) {
      m_keepRules.insert(newRule);
    } else {
      delete newRule;
    }
  }
}