Search in sources :

Example 11 with ProcessingDTO

use of org.kie.pmml.commons.model.ProcessingDTO 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 12 with ProcessingDTO

use of org.kie.pmml.commons.model.ProcessingDTO 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 13 with ProcessingDTO

use of org.kie.pmml.commons.model.ProcessingDTO 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 14 with ProcessingDTO

use of org.kie.pmml.commons.model.ProcessingDTO 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 15 with ProcessingDTO

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

the class KiePMMLDefineFunctionTest method evaluateNoParamValues.

@Test(expected = IllegalArgumentException.class)
public void evaluateNoParamValues() {
    final KiePMMLParameterField parameterField1 = KiePMMLParameterField.builder(PARAM_1, Collections.emptyList()).build();
    final KiePMMLParameterField parameterField2 = KiePMMLParameterField.builder(PARAM_2, Collections.emptyList()).build();
    final KiePMMLDefineFunction defineFunction = new KiePMMLDefineFunction(CUSTOM_FUNCTION, Collections.emptyList(), null, OP_TYPE.CONTINUOUS, Arrays.asList(parameterField1, parameterField2), null);
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
    defineFunction.evaluate(processingDTO, null);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Test(org.junit.Test)

Aggregations

ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)48 Test (org.junit.Test)44 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)41 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)19 PMML4Result (org.kie.api.pmml.PMML4Result)15 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)15 KiePMMLOutputField (org.kie.pmml.commons.model.KiePMMLOutputField)13 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)13 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)12 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)11 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)9 KiePMMLTransformationDictionary (org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary)7 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)6 Collections (java.util.Collections)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3