Search in sources :

Example 36 with Expression

use of org.hl7.elm.r1.Expression in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationPhraseTermOverlap.

@Test
public void testEvaluationPhraseTermOverlap() {
    String query = buildFunction(phraseFunction, Constants.TERM_OFFSET_MAP_JEXL_VARIABLE_NAME, "'cat'", "'rat'", "'dog'");
    Expression expr = engine.createExpression(query);
    List<TermWeightPosition> list1, list2, list3;
    // cat
    list1 = asList(1);
    // rat
    list2 = asList(1);
    // dog
    list3 = asList(1);
    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)

Example 37 with Expression

use of org.hl7.elm.r1.Expression in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testSomeEmptyOffsetsWithin.

@Test
public void testSomeEmptyOffsetsWithin() {
    String query = buildFunction(ContentFunctions.CONTENT_WITHIN_FUNCTION_NAME, "BODY", "5", 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 38 with Expression

use of org.hl7.elm.r1.Expression in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationPhraseBasicTermOrderFail.

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

use of org.hl7.elm.r1.Expression in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationFailedThreeTerms.

@Test
public void testEvaluationFailedThreeTerms() {
    String query = buildFunction(ContentFunctions.CONTENT_WITHIN_FUNCTION_NAME, "3", 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 40 with Expression

use of org.hl7.elm.r1.Expression in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testEvaluationNoContentFields.

/**
 * Same as testEvaluation1, however the term frequency list marks teh fields as non-content expansion fields and hence we expect no results
 */
@Test
public void testEvaluationNoContentFields() {
    String query = buildFunction(ContentFunctions.CONTENT_WITHIN_FUNCTION_NAME, "1", 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));
    // match (7-3_ should match (3+1)
    list2 = asList(Arrays.asList(5, 6, 7), Arrays.asList(0, 0, 3));
    termOffSetMap.put("dog", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", false, eventId), list1)));
    termOffSetMap.put("cat", new TermFrequencyList(Maps.immutableEntry(new Zone("CONTENT", false, 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)

Aggregations

Test (org.junit.Test)102 Expression (org.apache.commons.jexl2.Expression)98 TermWeightPosition (datawave.ingest.protobuf.TermWeightPosition)66 Zone (datawave.query.jexl.functions.TermFrequencyList.Zone)66 Test (org.junit.jupiter.api.Test)60 ArrayList (java.util.ArrayList)36 HashMap (java.util.HashMap)35 Patient (org.hl7.fhir.r4.model.Patient)29 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)28 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)28 Expression (io.atlasmap.v2.Expression)26 JexlContext (org.apache.commons.jexl2.JexlContext)26 Expression (org.hl7.elm.r1.Expression)26 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)24 JexlEngine (org.apache.commons.jexl2.JexlEngine)22 MapContext (org.apache.commons.jexl2.MapContext)22 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)16 Coding (org.hl7.fhir.r4.model.Coding)15