Search in sources :

Example 1 with ProcessingDTO

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

the class KiePMMLDerivedFieldTest method evaluateFromConstant.

@Test
public void evaluateFromConstant() {
    // <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
    // <Constant>100.0</Constant>
    // </DerivedField>
    final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_1, Collections.emptyList(), value1, null);
    final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant1).build();
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), new ArrayList<>());
    Object retrieved = derivedField.evaluate(processingDTO);
    assertEquals(value1, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Test(org.junit.Test)

Example 2 with ProcessingDTO

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

the class KiePMMLDerivedFieldTest method evaluateFromApplyWithDerivedFields.

@Test
public void evaluateFromApplyWithDerivedFields() {
    // <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
    // <Apply function="/">
    // <FieldRef>PARAM_1</FieldRef>
    // <FieldRef>PARAM_2</FieldRef>
    // </Apply>
    // </DerivedField>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLFieldRef kiePMMLFieldRef2 = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    final KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef1, kiePMMLFieldRef2)).build();
    final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLApply).build();
    ProcessingDTO processingDTO = getProcessingDTO(getDerivedFields(), new ArrayList<>());
    Object retrieved = derivedField.evaluate(processingDTO);
    Object expected = value1 / value2;
    assertEquals(expected, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Example 3 with ProcessingDTO

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

the class KiePMMLDiscretizeTest method evaluateNoInput.

@Test
public void evaluateNoInput() {
    KiePMMLDiscretize kiePMMLDiscretize = getKiePMMLDiscretize(null, null);
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
    Object retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNull(retrieved);
    kiePMMLDiscretize = getKiePMMLDiscretize(MAP_MISSING_TO, null);
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(MAP_MISSING_TO, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Test(org.junit.Test)

Example 4 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 5 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)

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