Search in sources :

Example 16 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class OrSimplifierTest method require_that_non_feature_set_nodes_are_left_untouched.

@Test
public void require_that_non_feature_set_nodes_are_left_untouched() {
    Predicate p = or(feature("key1").inSet("value1"), feature("key1").inSet("value2"), not(feature("key1").inSet("value3")));
    Predicate expected = or(not(feature("key1").inSet("value3")), feature("key1").inSet("value1", "value2"));
    assertConvertedPredicateEquals(expected, p);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 17 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class OrSimplifierTest method require_that_conversion_is_recursive_and_cascades.

@Test
public void require_that_conversion_is_recursive_and_cascades() {
    Predicate p = or(feature("key1").inSet("value1", "value4"), feature("key1").inSet("value2", "value3"), or(feature("key1").inSet("value1"), feature("key1").inSet("value4")));
    Predicate expected = feature("key1").inSet("value1", "value2", "value3", "value4");
    assertConvertedPredicateEquals(expected, p);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 18 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class OrSimplifierTest method require_that_or_with_feature_sets_of_same_key_is_simplified_to_single_feature_set.

@Test
public void require_that_or_with_feature_sets_of_same_key_is_simplified_to_single_feature_set() {
    Predicate p = or(feature("key1").inSet("value1", "value4"), feature("key1").inSet("value2", "value3"), feature("key1").inSet("value1", "value4"));
    Predicate expected = feature("key1").inSet("value1", "value2", "value3", "value4");
    assertConvertedPredicateEquals(expected, p);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 19 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class AndOrSimplifier method simplifySubTree.

public Predicate simplifySubTree(Predicate predicate, boolean negated) {
    if (predicate == null) {
        return null;
    }
    if (predicate instanceof Negation) {
        return simplifySubTree(((Negation) predicate).getOperand(), !negated);
    } else if (predicate instanceof Conjunction) {
        List<Predicate> in = ((Conjunction) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            operand = simplifySubTree(operand, negated);
            if (operand instanceof Conjunction) {
                out.addAll(((Conjunction) operand).getOperands());
            } else {
                out.add(operand);
            }
        }
        if (negated) {
            return new Disjunction(out);
        }
        ((Conjunction) predicate).setOperands(out);
    } else if (predicate instanceof Disjunction) {
        List<Predicate> in = ((Disjunction) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            operand = simplifySubTree(operand, negated);
            if (operand instanceof Disjunction) {
                out.addAll(((Disjunction) operand).getOperands());
            } else {
                out.add(operand);
            }
        }
        if (negated) {
            return new Conjunction(out);
        }
        ((Disjunction) predicate).setOperands(out);
    } else {
        if (negated) {
            return new Negation(predicate);
        }
    }
    return predicate;
}
Also used : Disjunction(com.yahoo.document.predicate.Disjunction) Negation(com.yahoo.document.predicate.Negation) Conjunction(com.yahoo.document.predicate.Conjunction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Predicate(com.yahoo.document.predicate.Predicate)

Example 20 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class NotNodeReorderer method processSubTree.

/**
 * @return true if the predicate ends in a negation.
 */
public boolean processSubTree(Predicate predicate) {
    if (predicate == null) {
        return false;
    }
    if (predicate instanceof Negation) {
        // All negations are for leaf-nodes after AndOrSimplifier has run.
        return true;
    } else if (predicate instanceof Conjunction) {
        List<Predicate> in = ((Conjunction) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        List<Predicate> positiveChildren = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            if (processSubTree(operand)) {
                out.add(operand);
            } else {
                positiveChildren.add(operand);
            }
        }
        out.addAll(positiveChildren);
        ((Conjunction) predicate).setOperands(out);
        return positiveChildren.isEmpty();
    } else if (predicate instanceof Disjunction) {
        List<Predicate> in = ((Disjunction) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        List<Predicate> negativeChildren = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            if (processSubTree(operand)) {
                negativeChildren.add(operand);
            } else {
                out.add(operand);
            }
        }
        out.addAll(negativeChildren);
        ((Disjunction) predicate).setOperands(out);
        return !negativeChildren.isEmpty();
    }
    return false;
}
Also used : Disjunction(com.yahoo.document.predicate.Disjunction) Negation(com.yahoo.document.predicate.Negation) Conjunction(com.yahoo.document.predicate.Conjunction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Predicate(com.yahoo.document.predicate.Predicate)

Aggregations

Predicate (com.yahoo.document.predicate.Predicate)45 Test (org.junit.Test)33 Conjunction (com.yahoo.document.predicate.Conjunction)7 Disjunction (com.yahoo.document.predicate.Disjunction)6 Negation (com.yahoo.document.predicate.Negation)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FeatureConjunction (com.yahoo.document.predicate.FeatureConjunction)3 FeatureRange (com.yahoo.document.predicate.FeatureRange)3 FeatureSet (com.yahoo.document.predicate.FeatureSet)3 IndexableFeatureConjunction (com.yahoo.search.predicate.index.conjunction.IndexableFeatureConjunction)3 Map (java.util.Map)3 DataType (com.yahoo.document.DataType)2 FieldValue (com.yahoo.document.datatypes.FieldValue)2 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)2 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)2 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)2 RangePartition (com.yahoo.document.predicate.RangePartition)2 ExpressionAssert.assertVerifyCtx (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtx)2 ExpressionAssert.assertVerifyCtxThrows (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtxThrows)2