Search in sources :

Example 1 with Choicepoint

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);
    }
}
Also used : Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint)

Example 2 with Choicepoint

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;
}
Also used : Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint) PhraseMatcher(com.yahoo.prelude.querytransform.PhraseMatcher) FlattenedItem(com.yahoo.prelude.semantics.engine.FlattenedItem)

Example 3 with Choicepoint

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;
}
Also used : Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint)

Example 4 with Choicepoint

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;
}
Also used : Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint) PhraseItem(com.yahoo.prelude.query.PhraseItem)

Example 5 with Choicepoint

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;
}
Also used : Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint) Choicepoint(com.yahoo.prelude.semantics.engine.Choicepoint)

Aggregations

Choicepoint (com.yahoo.prelude.semantics.engine.Choicepoint)6 PhraseItem (com.yahoo.prelude.query.PhraseItem)1 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)1 FlattenedItem (com.yahoo.prelude.semantics.engine.FlattenedItem)1