summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ProductionList.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/semantics/rule/ProductionList.java')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/semantics/rule/ProductionList.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ProductionList.java b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ProductionList.java
new file mode 100644
index 00000000000..3397a9ada1e
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ProductionList.java
@@ -0,0 +1,67 @@
+// 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 java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import com.yahoo.prelude.semantics.engine.RuleEvaluation;
+
+/**
+ * A list of the productions of a rule
+ *
+ * @author <a href="mailto:bratseth@yahoo-inc.com">Jon S Bratseth</a>
+ */
+public class ProductionList {
+
+ private List<Production> productions =new java.util.ArrayList<>();
+
+ /** True to replace by the production, false to add it */
+ private boolean replacing=true;
+
+ public void addProduction(Production term) {
+ term.setReplacing(replacing);
+ term.setPosition(productions.size());
+ productions.add(term);
+ }
+
+ /** True to replace, false to add, default true */
+ void setReplacing(boolean replacing) {
+ for (Iterator<Production> i=productions.iterator(); i.hasNext(); ) {
+ Production production=i.next();
+ production.setReplacing(replacing);
+ }
+
+ this.replacing=replacing;
+ }
+
+ /** Returns an unmodifiable view of the productions in this */
+ public List<Production> productionList() { return Collections.unmodifiableList(productions); }
+
+ public int getTermCount() { return productions.size(); }
+
+ void addMatchReferences(Set<String> matchReferences) {
+ for (Iterator<Production> i=productions.iterator(); i.hasNext(); ) {
+ Production term=i.next();
+ term.addMatchReferences(matchReferences);
+ }
+ }
+
+ public void produce(RuleEvaluation e) {
+ for (int i=0; i<productions.size(); i++) {
+ productions.get(i).produce(e,i);
+ }
+ }
+
+ public String toString() {
+ StringBuilder buffer=new StringBuilder();
+ for (Iterator<Production> i=productions.iterator(); i.hasNext(); ) {
+ buffer.append(i.next().toString());
+ if (i.hasNext())
+ buffer.append(" ");
+ }
+ return buffer.toString();
+ }
+
+}