Search in sources :

Example 11 with Predicate

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

the class PredicateTreeAnnotatorTest method require_that_featureconjunctions_are_registered_and_given_an_interval.

@Test
public void require_that_featureconjunctions_are_registered_and_given_an_interval() {
    Predicate p = and(or(range("key", partition("key=10-19"), partition("key=20-29"), edgePartition("key=0", 5, 10, 20), edgePartition("key=30", 0, 0, 3)), conj(not(feature("keyA").inSet("C")), feature("keyB").inSet("D"))), feature("foo").inSet("bar"));
    PredicateTreeAnnotations r = PredicateTreeAnnotator.createPredicateTreeAnnotations(p);
    assertEquals(2, r.minFeature);
    assertEquals(3, r.intervalEnd);
    assertEquals(3, r.intervalMap.size());
    assertEquals(2, r.boundsMap.size());
    assertEquals(1, r.featureConjunctions.size());
    Map.Entry<IndexableFeatureConjunction, List<Integer>> entry = r.featureConjunctions.entrySet().iterator().next();
    assertEquals(1, entry.getValue().size());
    assertEquals(0b1_0000000000000010, entry.getValue().get(0).longValue());
}
Also used : IndexableFeatureConjunction(com.yahoo.search.predicate.index.conjunction.IndexableFeatureConjunction) List(java.util.List) Map(java.util.Map) Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 12 with Predicate

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

the class BooleanSimplifierTest method assertSimplifiedTo.

private void assertSimplifiedTo(Predicate expected, Predicate input) {
    BooleanSimplifier simplifier = new BooleanSimplifier();
    Predicate actual = simplifier.process(input, new PredicateOptions(10));
    assertEquals(expected, actual);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate)

Example 13 with Predicate

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

the class VespaFeedParser method parseDocuments.

public static int parseDocuments(String feedFile, int maxDocuments, Consumer<Predicate> consumer) throws IOException {
    int documentCount = 0;
    try (BufferedReader reader = new BufferedReader(new FileReader(feedFile), 8 * 1024)) {
        reader.readLine();
        // Skip to start of first document
        reader.readLine();
        String line = reader.readLine();
        while (!line.startsWith("</vespafeed>") && documentCount < maxDocuments) {
            while (!line.startsWith("<boolean>")) {
                line = reader.readLine();
            }
            Predicate predicate = Predicate.fromString(extractBooleanExpression(line));
            consumer.accept(predicate);
            ++documentCount;
            while (!line.startsWith("<document") && !line.startsWith("</vespafeed>")) {
                line = reader.readLine();
            }
        }
    }
    return documentCount;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Predicate(com.yahoo.document.predicate.Predicate)

Example 14 with Predicate

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

the class PredicateFieldValueTest method requireThatConstructorsWork.

@Test
public void requireThatConstructorsWork() {
    assertNull(new PredicateFieldValue().getPredicate());
    Predicate predicate = SimplePredicates.newPredicate();
    assertEquals(predicate, new PredicateFieldValue(predicate).getPredicate());
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 15 with Predicate

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

the class ComplexNodeTransformerTest method testConvert.

private void testConvert(String predicate, String expected, int arity) {
    Predicate p = Predicate.fromString(predicate);
    ComplexNodeTransformer transformer = new ComplexNodeTransformer();
    Predicate converted = transformer.process(p, new PredicateOptions(arity, lowerBound, upperBound));
    assertEquals(expected, converted.toString());
}
Also used : 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