summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/semantics/rule/LiteralTermProduction.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/semantics/rule/LiteralTermProduction.java')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/semantics/rule/LiteralTermProduction.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/LiteralTermProduction.java b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/LiteralTermProduction.java
new file mode 100644
index 00000000000..f157fd6901d
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/LiteralTermProduction.java
@@ -0,0 +1,79 @@
+// 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.rule;
+
+import com.yahoo.prelude.query.TermType;
+import com.yahoo.prelude.query.WordItem;
+import com.yahoo.prelude.semantics.engine.Match;
+import com.yahoo.prelude.semantics.engine.RuleEvaluation;
+import com.yahoo.protect.Validator;
+
+/**
+ * A literal term produced by a production rule
+ *
+ * @author <a href="mailto:bratseth@yahoo-inc.com">Jon S Bratseth</a>
+ */
+public class LiteralTermProduction extends TermProduction {
+
+ private String literal;
+
+ /**
+ * Creates a new produced literal term
+ *
+ * @param literal the label of the condition this should take it's value from
+ */
+ public LiteralTermProduction(String literal) {
+ super();
+ setLiteral(literal);
+ }
+
+ /**
+ * Creates a new produced literal term
+ *
+ * @param literal the label of the condition this should take it's value from
+ * @param termType the type of term to produce
+ */
+ public LiteralTermProduction(String literal, TermType termType) {
+ super(termType);
+ setLiteral(literal);
+ }
+
+ /**
+ * Creates a new produced literal term
+ *
+ * @param label the label of the produced term
+ * @param literal this term word
+ * @param termType the type of term to produce
+ */
+ public LiteralTermProduction(String label,String literal, TermType termType) {
+ super(label,termType);
+ setLiteral(literal);
+ }
+
+ /** The literal term value, never null */
+ public void setLiteral(String literal) {
+ Validator.ensureNotNull("A produced term",literal);
+ this.literal=literal;
+ }
+
+ /** Returns the term word produced, never null */
+ public String getLiteral() { return literal; }
+
+ public void produce(RuleEvaluation e,int offset) {
+ WordItem newItem=new WordItem(literal,getLabel());
+ if (replacing) {
+ Match matched=e.getNonreferencedMatch(0);
+ insertMatch(e,matched,newItem,offset);
+ }
+ else {
+ newItem.setWeight(getWeight());
+ if (e.getTraceLevel()>=6)
+ e.trace(6,"Adding '" + newItem + "'");
+ e.addItem(newItem,getTermType());
+ }
+ }
+
+ public String toInnerTermString() {
+ return getLabelString() + literal;
+ }
+
+}