Search in sources :

Example 21 with TermWeightPosition

use of datawave.ingest.protobuf.TermWeightPosition in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationAdjacent3.

@Test
public void testEvaluationAdjacent3() {
    String query = buildFunction(ContentFunctions.CONTENT_ADJACENT_FUNCTION_NAME, Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'dog'", "'cat'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2;
    list1 = asList(1, 2, 3);
    list2 = asList(5);
    termOffSetMap.put("dog", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list1)));
    termOffSetMap.put("cat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list2)));
    context.set(Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, termOffSetMap);
    Object o = expr.evaluate(context);
    Assert.assertTrue(expect(o, false));
}
Also used : Expression(org.apache.commons.jexl2.Expression) Zone(datawave.query.jexl.functions.TermFrequencyList.Zone) TermWeightPosition(datawave.ingest.protobuf.TermWeightPosition) Test(org.junit.Test)

Example 22 with TermWeightPosition

use of datawave.ingest.protobuf.TermWeightPosition in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationMultipleContentFunctions.

@Test
public void testEvaluationMultipleContentFunctions() {
    String query1 = buildFunction(ContentFunctions.CONTENT_WITHIN_FUNCTION_NAME, "3", Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'bat'", "'dog'", "'cat'");
    String query2 = buildFunction(ContentFunctions.CONTENT_WITHIN_FUNCTION_NAME, "3", Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'dog'", "'cat'");
    String query = query1 + "||" + query2;
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2, list3;
    list1 = asList(1, 2, 4);
    list2 = asList(4, 5, 6);
    list3 = asList(11, 12, 14);
    termOffSetMap.put("dog", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list1)));
    termOffSetMap.put("cat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list2)));
    termOffSetMap.put("bat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list3)));
    context.set(Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, termOffSetMap);
    Object o = expr.evaluate(context);
    Assert.assertTrue(expect(o, true));
}
Also used : Expression(org.apache.commons.jexl2.Expression) Zone(datawave.query.jexl.functions.TermFrequencyList.Zone) TermWeightPosition(datawave.ingest.protobuf.TermWeightPosition) Test(org.junit.Test)

Example 23 with TermWeightPosition

use of datawave.ingest.protobuf.TermWeightPosition in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method forwardAllSharedTokenIndex.

@Test
public void forwardAllSharedTokenIndex() {
    String query = buildFunction(ContentFunctions.CONTENT_PHRASE_FUNCTION_NAME, Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'c'", "'b'", "'a'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> t1, t2, t3;
    t1 = asList(Arrays.asList(234, 239, 252, 257, 265, 281, 286, 340, 363, 367), Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
    t2 = asList(Arrays.asList(212, 229, 252, 272), Arrays.asList(0, 0, 0, 0));
    t3 = asList(Arrays.asList(1, 101, 202, 213, 252, 312, 336), Arrays.asList(0, 0, 0, 0, 0, 0, 0));
    termOffSetMap.put("a", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), t1)));
    termOffSetMap.put("b", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), t2)));
    termOffSetMap.put("c", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), t3)));
    context.set(Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, termOffSetMap);
    Object o = expr.evaluate(context);
    Assert.assertTrue(expect(o, true));
}
Also used : Expression(org.apache.commons.jexl2.Expression) Zone(datawave.query.jexl.functions.TermFrequencyList.Zone) TermWeightPosition(datawave.ingest.protobuf.TermWeightPosition) Test(org.junit.Test)

Example 24 with TermWeightPosition

use of datawave.ingest.protobuf.TermWeightPosition in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationPhraseThreeTermFail.

@Test
public void testEvaluationPhraseThreeTermFail() {
    String query = buildFunction(phraseFunction, Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'cat'", "'dog'", "'rat'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2, list3;
    list1 = asList(1, 2, 4);
    list2 = asList(5, 7, 9);
    list3 = asList(6, 8, 10);
    termOffSetMap.put("dog", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list1)));
    termOffSetMap.put("cat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list2)));
    termOffSetMap.put("rat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list3)));
    context.set(Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, termOffSetMap);
    Object o = expr.evaluate(context);
    Assert.assertTrue(expect(o, false));
}
Also used : Expression(org.apache.commons.jexl2.Expression) Zone(datawave.query.jexl.functions.TermFrequencyList.Zone) TermWeightPosition(datawave.ingest.protobuf.TermWeightPosition) Test(org.junit.Test)

Example 25 with TermWeightPosition

use of datawave.ingest.protobuf.TermWeightPosition in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationThreeTerms.

@Test
public void testEvaluationThreeTerms() {
    String query = buildFunction(ContentFunctions.CONTENT_WITHIN_FUNCTION_NAME, "3", Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'dog'", "'cat'", "'rat'");
    Expression expr = engine.createExpression(query);
    // (15-3)-9 <= 3
    List<TermWeightPosition> list1, list2, list3;
    list1 = asList(1, 5, 9);
    list2 = asList(3, 7, 11);
    list3 = asList(10, 15, 20, 25);
    termOffSetMap.put("dog", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list1)));
    termOffSetMap.put("cat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list2)));
    termOffSetMap.put("rat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list3)));
    context.set(Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, termOffSetMap);
    Object o = expr.evaluate(context);
    Assert.assertTrue(expect(o, true));
}
Also used : Expression(org.apache.commons.jexl2.Expression) Zone(datawave.query.jexl.functions.TermFrequencyList.Zone) TermWeightPosition(datawave.ingest.protobuf.TermWeightPosition) Test(org.junit.Test)

Aggregations

TermWeightPosition (datawave.ingest.protobuf.TermWeightPosition)69 Zone (datawave.query.jexl.functions.TermFrequencyList.Zone)67 Test (org.junit.Test)67 Expression (org.apache.commons.jexl2.Expression)66 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 TermFrequencyIterator (datawave.core.iterators.TermFrequencyIterator)1 TermWeight (datawave.ingest.protobuf.TermWeight)1 Content (datawave.query.attributes.Content)1 Document (datawave.query.attributes.Document)1 TermFrequencyList (datawave.query.jexl.functions.TermFrequencyList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NavigableSet (java.util.NavigableSet)1 Key (org.apache.accumulo.core.data.Key)1 Range (org.apache.accumulo.core.data.Range)1