Search in sources :

Example 61 with TermWeightPosition

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

the class ContentFunctionsTest method testEvaluationScoreFail.

@Test
public void testEvaluationScoreFail() {
    String query = buildFunction(scoredPhraseFunction, "'CONTENT'", "-0.200", Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'dog'", "'cat'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2;
    list1 = asList(Arrays.asList(1, 2, 3), Arrays.asList(0, 0, 0), Arrays.asList(-0.223f, -1.4339f, -0.2001f));
    list2 = asList(Arrays.asList(3, 4, 5), Arrays.asList(0, 0, 0), Arrays.asList(-0.001f, -1.4339f, -0.2001f));
    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 62 with TermWeightPosition

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

the class ContentFunctionsTest method testEvaluationPhraseTermOverlapPass4.

@Test
public void testEvaluationPhraseTermOverlapPass4() {
    String query = buildFunction(phraseFunction, Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'cat'", "'rat'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2;
    // cat
    list1 = asList(5);
    // rat
    list2 = asList(1, 5);
    termOffSetMap.put("cat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", true, eventId), list1)));
    termOffSetMap.put("rat", 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, 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 63 with TermWeightPosition

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

the class ContentFunctionsTest method testEvaluationAdjacentFailedThreeTerms.

@Test
public void testEvaluationAdjacentFailedThreeTerms() {
    String query = buildFunction(ContentFunctions.CONTENT_ADJACENT_FUNCTION_NAME, Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'dog'", "'cat'", "'rat'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2, list3;
    list1 = asList(1, 2, 3);
    list2 = asList(3, 4, 5);
    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, 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 64 with TermWeightPosition

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

the class ContentFunctionsTest method testSomeEmptyOffsetsPhrase.

@Test
public void testSomeEmptyOffsetsPhrase() {
    String query = buildFunction(phraseFunction, "BODY", Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'foo'", "'bar'", "'car'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2, list3, list4;
    list1 = asList(296);
    list2 = asList(1079);
    list3 = asList(260, 284, 304);
    list4 = asList(1165);
    termOffSetMap.put("foo", new TermFrequencyList(Maps.immutableEntry(new Zone("BODY", true, eventId), list1)));
    termOffSetMap.put("bar", new TermFrequencyList(Maps.immutableEntry(new Zone("BODY", true, eventId), list2)));
    termOffSetMap.put("car", new TermFrequencyList(Maps.immutableEntry(new Zone("BODY", true, eventId), list3), Maps.immutableEntry(new Zone("META", true, eventId), list4)));
    context.set(Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, termOffSetMap);
    context.set("BODY", Arrays.asList("foo", "bar", "car"));
    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 65 with TermWeightPosition

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

the class ContentFunctionsTest method testEvaluationScoreNoZonePass.

@Test
public void testEvaluationScoreNoZonePass() {
    String query = buildFunction(scoredPhraseFunction, "-0.200", Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'dog'", "'cat'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2;
    list1 = asList(Arrays.asList(1, 2, 3), Arrays.asList(0, 0, 0), Arrays.asList(-0.223f, -1.4339f, -0.0001f));
    list2 = asList(Arrays.asList(3, 4, 5), Arrays.asList(0, 0, 0), Arrays.asList(-0.001f, -1.4339f, -0.2001f));
    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, 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