Search in sources :

Example 1 with FlattenedItem

use of com.yahoo.prelude.semantics.engine.FlattenedItem 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 2 with FlattenedItem

use of com.yahoo.prelude.semantics.engine.FlattenedItem in project vespa by vespa-engine.

the class ConditionReference method automataMatchPhrase.

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;
        if (!labelMatches(e.currentItem().getItem(), e))
            return false;
        if (!e.isInNegation())
            e.addMatch(current, i.getReplace());
        e.next();
    }
    // The underlying composite item has changed
    if (phrase.getLength() > phrase.getBackedLength())
        return false;
    return true;
}
Also used : FlattenedItem(com.yahoo.prelude.semantics.engine.FlattenedItem)

Example 3 with FlattenedItem

use of com.yahoo.prelude.semantics.engine.FlattenedItem in project vespa by vespa-engine.

the class Condition method labelMatches.

/**
 * Whether the label matches the current item, true if there is no current item
 */
protected boolean labelMatches(RuleEvaluation e) {
    FlattenedItem flattenedItem = e.currentItem();
    if (flattenedItem == null)
        return true;
    TermItem item = flattenedItem.getItem();
    if (item == null)
        return true;
    return labelMatches(item, e);
}
Also used : TermItem(com.yahoo.prelude.query.TermItem) FlattenedItem(com.yahoo.prelude.semantics.engine.FlattenedItem)

Aggregations

FlattenedItem (com.yahoo.prelude.semantics.engine.FlattenedItem)3 TermItem (com.yahoo.prelude.query.TermItem)1 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)1 Choicepoint (com.yahoo.prelude.semantics.engine.Choicepoint)1