void Rules::CreateRule(const NonTerm &nonTerm, const Parameter ¶ms) { 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; } }
void Rules::Extend(const Rule &rule, const ConsistentPhrase &cp, const Parameter ¶ms) { 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; } } }