Search in sources :

Example 1 with BooleanPredicate

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

the class PredicateIndexBuilderTest method requireThatEmptyDocumentsCanBeIndexed.

@Test
public void requireThatEmptyDocumentsCanBeIndexed() {
    PredicateIndexBuilder builder = new PredicateIndexBuilder(10);
    assertEquals(0, builder.getZeroConstraintDocCount());
    builder.indexDocument(2, new BooleanPredicate(true));
    assertEquals(1, builder.getZeroConstraintDocCount());
    builder.build();
}
Also used : BooleanPredicate(com.yahoo.document.predicate.BooleanPredicate) Test(org.junit.Test)

Example 2 with BooleanPredicate

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

the class PredicateFieldValueSerializationTestCase method requireThatPredicateDeserializationMatchesCpp.

@Test
public void requireThatPredicateDeserializationMatchesCpp() throws IOException {
    assertDeserialize("foo_in_bar_and_baz_in_cox", new Conjunction(new FeatureSet("foo", "bar"), new FeatureSet("baz", "cox")));
    assertDeserialize("foo_in_bar_or_baz_in_cox", new Disjunction(new FeatureSet("foo", "bar"), new FeatureSet("baz", "cox")));
    assertDeserialize("foo_in_6_9", new FeatureRange("foo", 6L, 9L));
    assertDeserialize("foo_in_6_x", new FeatureRange("foo", 6L, null));
    assertDeserialize("foo_in_x_9", new FeatureRange("foo", null, 9L));
    assertDeserialize("foo_in_x_x", new FeatureRange("foo", null, null));
    assertDeserialize("foo_in_x", new FeatureSet("foo"));
    assertDeserialize("foo_in_bar", new FeatureSet("foo", "bar"));
    assertDeserialize("foo_in_bar_baz", new FeatureSet("foo", "bar", "baz"));
    assertDeserialize("not_foo_in_bar", new Negation(new FeatureSet("foo", "bar")));
    assertDeserialize("true", new BooleanPredicate(true));
    assertDeserialize("false", new BooleanPredicate(false));
}
Also used : Disjunction(com.yahoo.document.predicate.Disjunction) Negation(com.yahoo.document.predicate.Negation) Conjunction(com.yahoo.document.predicate.Conjunction) FeatureRange(com.yahoo.document.predicate.FeatureRange) FeatureSet(com.yahoo.document.predicate.FeatureSet) BooleanPredicate(com.yahoo.document.predicate.BooleanPredicate) Test(org.junit.Test)

Example 3 with BooleanPredicate

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

the class BooleanSimplifier method simplifySubTree.

public Predicate simplifySubTree(Predicate predicate) {
    if (predicate == null) {
        return null;
    }
    if (predicate instanceof Conjunction) {
        List<Predicate> in = ((PredicateOperator) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            operand = simplifySubTree(operand);
            if (isFalse(operand)) {
                return new BooleanPredicate(false);
            } else if (!isTrue(operand)) {
                out.add(operand);
            }
        }
        if (out.size() == 1) {
            return out.get(0);
        } else if (out.size() == 0) {
            return new BooleanPredicate(true);
        }
        ((Conjunction) predicate).setOperands(out);
    } else if (predicate instanceof Disjunction) {
        List<Predicate> in = ((PredicateOperator) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            operand = simplifySubTree(operand);
            if (isTrue(operand)) {
                return new BooleanPredicate(true);
            } else if (!isFalse(operand)) {
                out.add(operand);
            }
        }
        if (out.size() == 1) {
            return out.get(0);
        } else if (out.size() == 0) {
            return new BooleanPredicate(false);
        }
        ((Disjunction) predicate).setOperands(out);
    } else if (predicate instanceof Negation) {
        Predicate operand = ((Negation) predicate).getOperand();
        operand = simplifySubTree(operand);
        if (isTrue(operand)) {
            return new BooleanPredicate(false);
        } else if (isFalse(operand)) {
            return new BooleanPredicate(true);
        }
        ((Negation) predicate).setOperand(operand);
    }
    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) PredicateOperator(com.yahoo.document.predicate.PredicateOperator) List(java.util.List) ArrayList(java.util.ArrayList) BooleanPredicate(com.yahoo.document.predicate.BooleanPredicate) BooleanPredicate(com.yahoo.document.predicate.BooleanPredicate) Predicate(com.yahoo.document.predicate.Predicate)

Aggregations

BooleanPredicate (com.yahoo.document.predicate.BooleanPredicate)3 Conjunction (com.yahoo.document.predicate.Conjunction)2 Disjunction (com.yahoo.document.predicate.Disjunction)2 Negation (com.yahoo.document.predicate.Negation)2 Test (org.junit.Test)2 FeatureRange (com.yahoo.document.predicate.FeatureRange)1 FeatureSet (com.yahoo.document.predicate.FeatureSet)1 Predicate (com.yahoo.document.predicate.Predicate)1 PredicateOperator (com.yahoo.document.predicate.PredicateOperator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1