Search in sources :

Example 6 with ProcessingDTO

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

the class KiePMMLDiscretizeTest method evaluateDefaultValue.

@Test
public void evaluateDefaultValue() {
    KiePMMLDiscretize kiePMMLDiscretize = getKiePMMLDiscretize(null, null);
    ProcessingDTO processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 20)));
    Object retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNull(retrieved);
    kiePMMLDiscretize = getKiePMMLDiscretize(MAP_MISSING_TO, DEFAULTVALUE);
    processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 20)));
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(DEFAULTVALUE, retrieved);
    processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 21)));
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(DEFAULTVALUE, retrieved);
    processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 40)));
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(DEFAULTVALUE, 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 7 with ProcessingDTO

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

the class KiePMMLMapValuesTest method evaluateKeyFoundMatching.

@Test
public void evaluateKeyFoundMatching() {
    KiePMMLMapValues kiePMMLMapValues = getKiePMMLMapValues();
    List<KiePMMLNameValue> kiePMMLNameValues = IntStream.range(0, 2).mapToObj(i -> new KiePMMLNameValue("FIELD-" + i, "VALUE-1-" + i)).collect(Collectors.toList());
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    Object retrieved = kiePMMLMapValues.evaluate(processingDTO);
    assertNotNull(retrieved);
}
Also used : IntStream(java.util.stream.IntStream) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) List(java.util.List) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Assert.assertNotNull(org.junit.Assert.assertNotNull) Map(java.util.Map) Test(org.junit.Test) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) 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 8 with ProcessingDTO

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

the class KiePMMLMapValuesTest method evaluateKeyFoundNotMatching.

@Test
public void evaluateKeyFoundNotMatching() {
    KiePMMLMapValues kiePMMLMapValues = getKiePMMLMapValues();
    List<KiePMMLNameValue> kiePMMLNameValues = IntStream.range(0, 2).mapToObj(i -> new KiePMMLNameValue("FIELD-" + i, "NOT-VALUE-1-" + i)).collect(Collectors.toList());
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    assertEquals(DEFAULTVALUE, kiePMMLMapValues.evaluate(processingDTO));
}
Also used : IntStream(java.util.stream.IntStream) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) List(java.util.List) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Assert.assertNotNull(org.junit.Assert.assertNotNull) Map(java.util.Map) Test(org.junit.Test) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) 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 9 with ProcessingDTO

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

the class KiePMMLApplyTest method evaluateUnknownFunction.

@Test(expected = IllegalArgumentException.class)
public void evaluateUnknownFunction() {
    // <Apply function="UNKNOWN">
    // <Constant>33.0</Constant>
    // <Constant>27.0</Constant>
    // </Apply>
    String name = "name";
    String function = "UNKNOWN";
    String defaultValue = null;
    String mapMissingTo = null;
    String invalidTreatmentValue = null;
    final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant("NAME-1", Collections.emptyList(), value1, null);
    final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant("NAME-1", Collections.emptyList(), value2, null);
    KiePMMLApply kiePMMLApply = KiePMMLApply.builder(name, Collections.emptyList(), function).withKiePMMLExpressions(Arrays.asList(kiePMMLConstant1, kiePMMLConstant2)).withDefaultValue(defaultValue).withMapMissingTo(mapMissingTo).withInvalidValueTreatmentMethod(invalidTreatmentValue).build();
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    kiePMMLApply.evaluate(processingDTO);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Test(org.junit.Test)

Example 10 with ProcessingDTO

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

the class KiePMMLApplyTest method evaluateFromDefineFunction.

@Test
public void evaluateFromDefineFunction() {
    Double valueA = 33.0;
    Double valueB = 27.0;
    // <Apply function="CUSTOM_FUNCTION">
    // <Constant>33.0</Constant>
    // <Constant>27.0</Constant>
    // </Apply>
    // <DefineFunction name="CUSTOM_FUNCTION" optype="continuous" dataType="double">
    // <ParameterField name="PARAM_1"/>
    // <ParameterField field="PARAM_2"/>
    // <Apply function="/">
    // <Constant>100.0</Constant>
    // <Constant>5.0</Constant>
    // </Apply>
    // </DefineFunction>
    final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant("NAME-1", Collections.emptyList(), valueA, null);
    final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant("NAME-1", Collections.emptyList(), valueB, null);
    KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), CUSTOM_FUNCTION).withKiePMMLExpressions(Arrays.asList(kiePMMLConstant1, kiePMMLConstant2)).build();
    List<KiePMMLDefineFunction> defineFunctions = Collections.singletonList(getDefineFunctionApplyFromConstant());
    ProcessingDTO processingDTO = getProcessingDTO(defineFunctions, Collections.emptyList(), new ArrayList<>(), Collections.emptyList());
    Object retrieved = kiePMMLApply.evaluate(processingDTO);
    assertEquals(expected, retrieved);
    // 
    // Apply with a Constant and a FieldRef: returns kiePMMLConstant1 divided evaluation of FieldRef from
    // kiePMMLNameValues
    // <Apply function="CUSTOM_FUNCTION">
    // <Constant>33.0</Constant>
    // <Constant>27.0</Constant>
    // </Apply>
    // <DefineFunction name="CUSTOM_FUNCTION" optype="continuous" dataType="double">
    // <ParameterField name="PARAM_1"/>
    // <ParameterField field="PARAM_2"/>
    // <Apply function="/">
    // <Constant>100.0</Constant>
    // <FieldRef field="PARAM_2"/>
    // </Apply>
    // </DefineFunction>
    defineFunctions = Collections.singletonList(getDefineFunctionApplyFromFieldRef());
    processingDTO = getProcessingDTO(defineFunctions, Collections.emptyList(), new ArrayList<>(), Collections.emptyList());
    retrieved = kiePMMLApply.evaluate(processingDTO);
    Double locallyExpected = value1 / valueB;
    assertEquals(locallyExpected, retrieved);
    // 
    // Apply invoking another custom function
    // <Apply function="OUTER_FUNCTION">
    // <Constant>33.0</Constant>
    // <Constant>27.0</Constant>
    // </Apply>
    // <DefineFunction name="OUTER_FUNCTION" optype="continuous" dataType="double">
    // <ParameterField name="PARAM_1"/>
    // <ParameterField field="PARAM_2"/>
    // <Apply function="CUSTOM_FUNCTION">
    // <FieldRef field="PARAM_1"/>
    // <FieldRef field="PARAM_2"/>
    // </Apply>
    // </DefineFunction>
    // <DefineFunction name="CUSTOM_FUNCTION" optype="continuous" dataType="double">
    // <ParameterField name="PARAM_1"/>
    // <ParameterField field="PARAM_2"/>
    // <Apply function="/">
    // <Constant>100.0</Constant>
    // <FieldRef field="PARAM_2"/>
    // </Apply>
    // </DefineFunction>
    kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), OUTER_FUNCTION).withKiePMMLExpressions(Arrays.asList(kiePMMLConstant1, kiePMMLConstant2)).build();
    defineFunctions = Arrays.asList(getDefineFunctionApplyFromFieldRef(), getDefineFunctionApplyFromCustomFunction());
    processingDTO = getProcessingDTO(defineFunctions, Collections.emptyList(), new ArrayList<>(), Collections.emptyList());
    retrieved = kiePMMLApply.evaluate(processingDTO);
    assertEquals(locallyExpected, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) ArrayList(java.util.ArrayList) 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