summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java55
1 files changed, 26 insertions, 29 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java
index bfddb55566c..e468526fbe0 100644
--- a/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java
+++ b/container-search/src/main/java/com/yahoo/prelude/semantics/rule/ConditionReference.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. 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.TermItem;
import com.yahoo.prelude.querytransform.PhraseMatcher;
import com.yahoo.prelude.semantics.RuleBase;
import com.yahoo.prelude.semantics.RuleBaseException;
@@ -11,8 +10,6 @@ import com.yahoo.prelude.semantics.engine.FlattenedItem;
import com.yahoo.prelude.semantics.engine.RuleEvaluation;
import com.yahoo.protect.Validator;
-import java.util.Map;
-
/**
* A reference to a named condition
*
@@ -24,7 +21,7 @@ public class ConditionReference extends Condition {
private String conditionName;
/**
- * The actual condition references by this, or null if not initialized or not found,
+ * The actual condition referenced by this, or null if not initialized or not found,
* or if this is really an automata reference
*/
private NamedCondition namedCondition;
@@ -33,7 +30,7 @@ public class ConditionReference extends Condition {
* True if this condition should be looked up in the automata
* annotations of the item instead of by reference to another item
*/
- private boolean automataLookup=false;
+ private boolean automataLookup = false;
public ConditionReference(String conditionName) {
this(null,conditionName);
@@ -42,37 +39,36 @@ public class ConditionReference extends Condition {
public ConditionReference(String label,String conditionName) {
super(label);
Validator.ensureNotNull("Name of referenced condition",conditionName);
- this.conditionName=conditionName;
+ this.conditionName = conditionName;
setContextName(conditionName);
}
/** Returns the name of the referenced rule, never null */
public String getConditionName() { return conditionName; }
- public void setConditionName(String name) { this.conditionName=name; }
+ public void setConditionName(String name) { this.conditionName = name; }
public boolean doesMatch(RuleEvaluation e) {
if (automataLookup) return automataMatch(e);
- if (namedCondition==null)
- throw new EvaluationException("Condition reference '" + conditionName +
- "' not found or not initialized");
+ if (namedCondition == null)
+ throw new EvaluationException("Condition reference '" + conditionName + "' not found or not initialized");
return namedCondition.matches(e);
}
private boolean automataMatch(RuleEvaluation e) {
- FlattenedItem current=e.currentItem();
- if (current==null) return false;
+ FlattenedItem current = e.currentItem();
+ if (current == null) return false;
- Object annotation=current.getItem().getAnnotation(conditionName);
- if (annotation==null) return false;
+ Object annotation = current.getItem().getAnnotation(conditionName);
+ if (annotation == null) return false;
if (! (annotation instanceof PhraseMatcher.Phrase)) return false;
- PhraseMatcher.Phrase phrase=(PhraseMatcher.Phrase)annotation;
+ PhraseMatcher.Phrase phrase = (PhraseMatcher.Phrase)annotation;
- Choicepoint choicePoint=e.getChoicepoint(this,true);
- boolean matches=automataMatchPhrase(phrase,e);
+ Choicepoint choicePoint = e.getChoicepoint(this,true);
+ boolean matches = automataMatchPhrase(phrase,e);
if (!matches && e.isInNegation()) { // TODO: Temporary hack! Works for single items only
e.addMatch(current,null);
@@ -84,40 +80,41 @@ public class ConditionReference extends Condition {
return matches;
}
- private boolean automataMatchPhrase(PhraseMatcher.Phrase phrase,RuleEvaluation e) {
- for (PhraseMatcher.Phrase.MatchIterator i=phrase.itemIterator(); i.hasNext(); ) {
+ private boolean automataMatchPhrase(PhraseMatcher.Phrase phrase, RuleEvaluation e) {
+ for (PhraseMatcher.Phrase.MatchIterator i = phrase.itemIterator(); i.hasNext(); ) {
i.next();
- FlattenedItem current=e.currentItem();
- if (current==null) return false;
+ FlattenedItem current = e.currentItem();
+ if (current == null) return false;
if (!labelMatches(e.currentItem().getItem(),e)) return false;
if (!e.isInNegation())
- e.addMatch(current,i.getReplace());
+ e.addMatch(current, i.getReplace());
e.next();
}
- if (phrase.getLength()>phrase.getBackedLength()) return false; // The underlying composite item has changed
+ if (phrase.getLength() > phrase.getBackedLength()) return false; // The underlying composite item has changed
return true;
}
public void makeReferences(RuleBase ruleBase) {
- namedCondition=ruleBase.getCondition(conditionName);
- if (namedCondition==null) { // Then this may reference some automata value, if we have an automata
+ namedCondition = ruleBase.getCondition(conditionName);
+ if (namedCondition == null) { // Then this may reference some automata value, if we have an automata
if (ruleBase.usesAutomata())
- automataLookup=true;
+ automataLookup = true;
else
throw new RuleBaseException("Referenced condition '" + conditionName +
- "' does not exist in " + ruleBase);
+ "' does not exist in " + ruleBase);
}
}
protected boolean hasOpenChoicepoint(RuleEvaluation e) {
- if (namedCondition==null) return false;
+ if (namedCondition == null) return false;
return namedCondition.getCondition().hasOpenChoicepoint(e);
}
protected boolean isDefaultContextName() {
- return getContextName()==null || getContextName().equals(conditionName);
+ return getContextName() == null || getContextName().equals(conditionName);
}
+ @Override
protected String toInnerString() {
return "[" + conditionName + "]";
}