Search in sources :

Example 1 with ProductionList

use of com.yahoo.prelude.semantics.rule.ProductionList in project vespa by vespa-engine.

the class ConditionTestCase method testNamedConditionReference.

public void testNamedConditionReference() {
    TermCondition term = new TermCondition("foo");
    NamedCondition named = new NamedCondition("cond", term);
    ConditionReference reference = new ConditionReference("cond");
    // To initialize the condition reference...
    ProductionRule rule = new ReplacingProductionRule();
    rule.setCondition(reference);
    rule.setProduction(new ProductionList());
    RuleBase ruleBase = new RuleBase();
    ruleBase.setName("test");
    ruleBase.addCondition(named);
    ruleBase.addRule(rule);
    ruleBase.initialize();
    Query query = new Query("?query=foo");
    assertTrue(query + "  matches " + reference, reference.matches(new Evaluation(query).freshRuleEvaluation()));
}
Also used : NamedCondition(com.yahoo.prelude.semantics.rule.NamedCondition) ConditionReference(com.yahoo.prelude.semantics.rule.ConditionReference) Evaluation(com.yahoo.prelude.semantics.engine.Evaluation) TermCondition(com.yahoo.prelude.semantics.rule.TermCondition) ProductionRule(com.yahoo.prelude.semantics.rule.ProductionRule) ReplacingProductionRule(com.yahoo.prelude.semantics.rule.ReplacingProductionRule) Query(com.yahoo.search.Query) ReplacingProductionRule(com.yahoo.prelude.semantics.rule.ReplacingProductionRule) ProductionList(com.yahoo.prelude.semantics.rule.ProductionList) RuleBase(com.yahoo.prelude.semantics.RuleBase)

Example 2 with ProductionList

use of com.yahoo.prelude.semantics.rule.ProductionList 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());
}
Also used : NamedCondition(com.yahoo.prelude.semantics.rule.NamedCondition) ConditionReference(com.yahoo.prelude.semantics.rule.ConditionReference) Evaluation(com.yahoo.prelude.semantics.engine.Evaluation) RuleEvaluation(com.yahoo.prelude.semantics.engine.RuleEvaluation) TermCondition(com.yahoo.prelude.semantics.rule.TermCondition) ProductionRule(com.yahoo.prelude.semantics.rule.ProductionRule) ReplacingProductionRule(com.yahoo.prelude.semantics.rule.ReplacingProductionRule) Query(com.yahoo.search.Query) ReplacingProductionRule(com.yahoo.prelude.semantics.rule.ReplacingProductionRule) TermProduction(com.yahoo.prelude.semantics.rule.TermProduction) ReferenceTermProduction(com.yahoo.prelude.semantics.rule.ReferenceTermProduction) ReferenceTermProduction(com.yahoo.prelude.semantics.rule.ReferenceTermProduction) ProductionList(com.yahoo.prelude.semantics.rule.ProductionList) RuleBase(com.yahoo.prelude.semantics.RuleBase) RuleEvaluation(com.yahoo.prelude.semantics.engine.RuleEvaluation)

Aggregations

RuleBase (com.yahoo.prelude.semantics.RuleBase)2 Evaluation (com.yahoo.prelude.semantics.engine.Evaluation)2 ConditionReference (com.yahoo.prelude.semantics.rule.ConditionReference)2 NamedCondition (com.yahoo.prelude.semantics.rule.NamedCondition)2 ProductionList (com.yahoo.prelude.semantics.rule.ProductionList)2 ProductionRule (com.yahoo.prelude.semantics.rule.ProductionRule)2 ReplacingProductionRule (com.yahoo.prelude.semantics.rule.ReplacingProductionRule)2 TermCondition (com.yahoo.prelude.semantics.rule.TermCondition)2 Query (com.yahoo.search.Query)2 RuleEvaluation (com.yahoo.prelude.semantics.engine.RuleEvaluation)1 ReferenceTermProduction (com.yahoo.prelude.semantics.rule.ReferenceTermProduction)1 TermProduction (com.yahoo.prelude.semantics.rule.TermProduction)1