use of com.yahoo.prelude.semantics.engine.Choicepoint in project vespa by vespa-engine.
the class ComparisonCondition method doesMatch.
protected boolean doesMatch(RuleEvaluation evaluation) {
Object left = null;
Object right = null;
boolean matches = false;
Choicepoint choicepoint = evaluation.getChoicepoint(this, true);
try {
matches = getLeftCondition().matches(evaluation);
if (!matches)
return false;
left = evaluation.getValue();
evaluation.setValue(null);
choicepoint.backtrackPosition();
matches = getRightCondition().matches(evaluation);
if (!matches)
return false;
right = evaluation.getValue();
evaluation.setValue(right);
matches = operator.compare(left, right);
return matches;
} finally {
if (!matches)
choicepoint.backtrack();
traceResult(matches, evaluation, left, right);
}
}
use of com.yahoo.prelude.semantics.engine.Choicepoint in project vespa by vespa-engine.
the class ConditionReference method automataMatch.
private boolean automataMatch(RuleEvaluation e) {
FlattenedItem current = e.currentItem();
if (current == 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;
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);
}
if ((!matches && !e.isInNegation() || (matches && e.isInNegation())))
choicePoint.backtrackPosition();
return matches;
}
use of com.yahoo.prelude.semantics.engine.Choicepoint in project vespa by vespa-engine.
the class AndCondition method doesMatch.
public boolean doesMatch(RuleEvaluation e) {
Choicepoint choicepoint = e.getChoicepoint(this, true);
choicepoint.updateState();
boolean matches = allSubConditionsMatches(e);
if (!matches)
choicepoint.backtrack();
return matches;
}
use of com.yahoo.prelude.semantics.engine.Choicepoint in project vespa by vespa-engine.
the class CompositeItemCondition method doesMatch.
@Override
protected boolean doesMatch(RuleEvaluation e) {
Choicepoint choicepoint = e.getChoicepoint(this, true);
choicepoint.updateState();
boolean matches = e.currentItem().getItem().getParent() instanceof PhraseItem && allSubConditionsMatches(e);
if (!matches)
choicepoint.backtrack();
return matches;
}
use of com.yahoo.prelude.semantics.engine.Choicepoint in project vespa by vespa-engine.
the class EllipsisCondition method doesMatch.
public boolean doesMatch(RuleEvaluation e) {
// We use a choice point to remember which untried alternatives are not tried (if any)
// We never need to backtrack to this choice - backtracking is done by the parent
// if this choice gives a global invalid state
Choicepoint choicepoint = e.getChoicepoint(this, false);
if (choicepoint == null) {
// First try
choicepoint = e.getChoicepoint(this, true);
} else {
if (!choicepoint.isOpen())
return false;
}
// Match all the rest of the items the first time, then all except the last item and so on
int numberOfTermsToMatch = e.itemCount() - e.currentPosition() - choicepoint.tryCount();
if (numberOfTermsToMatch < 0) {
choicepoint.close();
return false;
}
choicepoint.addTry();
String matchedTerms = matchTerms(numberOfTermsToMatch, e);
e.setValue(matchedTerms);
return true;
}
Aggregations