use of com.yahoo.prelude.semantics.rule.TermProduction in project vespa by vespa-engine.
the class ProductionRuleTestCase method testProductionRule.
public void testProductionRule() {
TermCondition term = new TermCondition("sony");
NamedCondition named = new NamedCondition("brand", term);
ConditionReference reference = new ConditionReference("brand");
TermProduction termProduction = new ReferenceTermProduction("brand", "brand");
ProductionList productionList = new ProductionList();
productionList.addProduction(termProduction);
ProductionRule rule = new ReplacingProductionRule();
rule.setCondition(reference);
rule.setProduction(productionList);
// To initialize the condition reference...
RuleBase ruleBase = new RuleBase();
ruleBase.setName("test");
ruleBase.addCondition(named);
ruleBase.addRule(rule);
ruleBase.initialize();
assertTrue("Brand is referenced", rule.matchReferences().contains("brand"));
Query query = new Query("?query=sony");
RuleEvaluation e = new Evaluation(query).freshRuleEvaluation();
assertTrue(rule.matches(e));
rule.produce(e);
assertEquals("brand:sony", query.getModel().getQueryTree().getRoot().toString());
}
Aggregations