Search in sources :

Example 21 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class KiePMMLFieldRefTest method evaluateNull.

@Test
public void evaluateNull() {
    final KiePMMLConstant kiePMMLConstant = new KiePMMLConstant("NAME", Collections.emptyList(), "WRONG-CONSTANT", null);
    final KiePMMLDerivedField kiePMMLDerivedField = KiePMMLDerivedField.builder("ANOTHER_FIELD", Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant).build();
    final List<KiePMMLDerivedField> derivedFields = Collections.singletonList(kiePMMLDerivedField);
    final List<KiePMMLNameValue> kiePMMLNameValues = Collections.singletonList(new KiePMMLNameValue("UNKNOWN", "WRONG"));
    final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(FIELD_NAME, Collections.emptyList(), null);
    ProcessingDTO processingDTO = getProcessingDTO(derivedFields, kiePMMLNameValues);
    final Object retrieved = kiePMMLFieldRef.evaluate(processingDTO);
    assertNull(retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 22 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class KiePMMLTextIndexTest method evaluateTextIndex1Normalizations.

@Test
public void evaluateTextIndex1Normalizations() {
    // <TextIndexNormalization inField="string" outField="stem" regexField="regex">
    // <InlineTable>
    // <row>
    // <string>interfaces?</string>
    // <stem>interface</stem>
    // <regex>true</regex>
    // </row>
    // <row>
    // <string>is|are|seem(ed|s?)|were</string>
    // <stem>be</stem>
    // <regex>true</regex>
    // </row>
    // <row>
    // <string>user friendl(y|iness)</string>
    // <stem>user_friendly</stem>
    // <regex>true</regex>
    // </row>
    // </InlineTable>
    // </TextIndexNormalization>
    Map<String, Object> columnValues = new HashMap<>();
    columnValues.put("string", "interfaces?");
    columnValues.put("stem", "interface");
    columnValues.put("regex", "true");
    KiePMMLRow row0_0 = new KiePMMLRow(columnValues);
    columnValues = new HashMap<>();
    columnValues.put("string", "is|are|seem(ed|s?)|were");
    columnValues.put("stem", "be");
    columnValues.put("regex", "true");
    KiePMMLRow row0_1 = new KiePMMLRow(columnValues);
    columnValues = new HashMap<>();
    columnValues.put("string", "user friendl(y|iness)");
    columnValues.put("stem", "user_friendly");
    columnValues.put("regex", "true");
    KiePMMLRow row0_2 = new KiePMMLRow(columnValues);
    KiePMMLInlineTable inlineTable0 = new KiePMMLInlineTable("inlineTable0", Collections.emptyList(), Arrays.asList(row0_0, row0_1, row0_2));
    KiePMMLTextIndexNormalization indexNormalization0 = KiePMMLTextIndexNormalization.builder("indexNormalization0", Collections.emptyList()).withInField("string").withOutField("stem").withRegexField("regex").withKiePMMLInlineTable(inlineTable0).build();
    // <TextIndexNormalization inField="re" outField="feature" regexField="regex">
    // <InlineTable>
    // <row>
    // <re>interface be (user_friendly|well designed|excellent)</re>
    // <feature>ui_good</feature>
    // <regex>true</regex>
    // </row>
    // </InlineTable>
    // </TextIndexNormalization>
    columnValues = new HashMap<>();
    columnValues.put("re", "interface be (user_friendly|well designed|excellent)");
    columnValues.put("feature", "ui_good");
    columnValues.put("regex", "true");
    KiePMMLRow row1_0 = new KiePMMLRow(columnValues);
    KiePMMLInlineTable inlineTable1 = new KiePMMLInlineTable("inlineTable1", Collections.emptyList(), Collections.singletonList(row1_0));
    KiePMMLTextIndexNormalization indexNormalization1 = KiePMMLTextIndexNormalization.builder("indexNormalization1", Collections.emptyList()).withInField("re").withOutField("feature").withRegexField("regex").withKiePMMLInlineTable(inlineTable1).build();
    // <FieldRef field="term"/>
    KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef("term", Collections.emptyList(), null);
    KiePMMLTextIndex kiePMMLTextIndex = KiePMMLTextIndex.builder("reviewText", Collections.emptyList(), kiePMMLFieldRef).withMaxLevenshteinDistance(2).withLocalTermWeights(BINARY).withIsCaseSensitive(false).withTextIndexNormalizations(Arrays.asList(indexNormalization0, indexNormalization1)).build();
    List<KiePMMLNameValue> kiePMMLNameValues = Arrays.asList(new KiePMMLNameValue("term", TERM_1), new KiePMMLNameValue("reviewText", NOT_NORMALIZED_TEXT_1));
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    assertEquals(1.0, kiePMMLTextIndex.evaluate(processingDTO));
}
Also used : HashMap(java.util.HashMap) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Test(org.junit.Test)

Example 23 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class KiePMMLNormDiscreteTest method evaluateDifferentValue.

@Test
public void evaluateDifferentValue() {
    String fieldName = "fieldName";
    String fieldValue = "fieldValue";
    Number mapMissingTo = null;
    KiePMMLNormDiscrete kiePMMLNormContinuous = getKiePMMLNormDiscrete(fieldName, fieldValue, mapMissingTo);
    ProcessingDTO processingDTO = getProcessingDTO(Collections.singletonList(new KiePMMLNameValue(fieldName, "anotherValue")));
    Object retrieved = kiePMMLNormContinuous.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(0.0, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 24 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class KiePMMLNormDiscreteTest method evaluateSameValue.

@Test
public void evaluateSameValue() {
    String fieldName = "fieldName";
    String fieldValue = "fieldValue";
    Number mapMissingTo = null;
    KiePMMLNormDiscrete kiePMMLNormContinuous = getKiePMMLNormDiscrete(fieldName, fieldValue, mapMissingTo);
    ProcessingDTO processingDTO = getProcessingDTO(Collections.singletonList(new KiePMMLNameValue(fieldName, fieldValue)));
    Object retrieved = kiePMMLNormContinuous.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(1.0, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 25 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class PostProcessTest method populateTransformedOutputFieldWithFieldRef.

@Test
public void populateTransformedOutputFieldWithFieldRef() {
    final String mapMissingTo = "mapMissingTo";
    final String variableName = "variableName";
    final Object variableValue = 543.65434;
    KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(variableName, Collections.emptyList(), mapMissingTo);
    KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).withKiePMMLExpression(kiePMMLFieldRef).build();
    KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
    ProcessingDTO processingDTO = buildProcessingDTOWithNameValues(kiePMMLModel, new KiePMMLNameValue(variableName, variableValue));
    PMML4Result toUpdate = new PMML4Result();
    PostProcess.populateOutputFields(toUpdate, processingDTO);
    assertFalse(toUpdate.getResultVariables().isEmpty());
    assertTrue(toUpdate.getResultVariables().containsKey(OUTPUT_NAME));
    assertEquals(variableValue, toUpdate.getResultVariables().get(OUTPUT_NAME));
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Aggregations

KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)44 Test (org.junit.Test)37 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)19 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)19 LinkedHashMap (java.util.LinkedHashMap)16 ArrayList (java.util.ArrayList)8 List (java.util.List)8 HashMap (java.util.HashMap)7 PMML4Result (org.kie.api.pmml.PMML4Result)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)6 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)6 Collections (java.util.Collections)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Arrays (java.util.Arrays)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)4