aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java
Publish
Diffstat (limited to 'container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java')
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java
new file mode 100644
index 00000000000..595a2b4c75c
--- /dev/null
+++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java
@@ -0,0 +1,55 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.prelude.semantics.test;
+
+import com.yahoo.search.Query;
+import com.yahoo.prelude.semantics.RuleBase;
+import com.yahoo.prelude.semantics.engine.Evaluation;
+import com.yahoo.prelude.semantics.engine.RuleEvaluation;
+import com.yahoo.prelude.semantics.rule.ConditionReference;
+import com.yahoo.prelude.semantics.rule.NamedCondition;
+import com.yahoo.prelude.semantics.rule.ProductionList;
+import com.yahoo.prelude.semantics.rule.ProductionRule;
+import com.yahoo.prelude.semantics.rule.ReferenceTermProduction;
+import com.yahoo.prelude.semantics.rule.ReplacingProductionRule;
+import com.yahoo.prelude.semantics.rule.TermCondition;
+import com.yahoo.prelude.semantics.rule.TermProduction;
+
+/**
+ * @author <a href="mailto:bratseth@yahoo-inc.com">Jon S Bratseth</a>
+ */
+public class ProductionRuleTestCase extends junit.framework.TestCase {
+
+ public ProductionRuleTestCase(String name) {
+ super(name);
+ }
+
+ 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());
+ }
+
+}