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);
}
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);
}
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));
}
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);
}
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);
}
Aggregations