Search in sources :

Example 11 with KiePMMLDefineFunction

use of org.kie.pmml.commons.transformations.KiePMMLDefineFunction in project drools by kiegroup.

the class PostProcessTest method populateTransformedOutputFieldWithApplyDefineFunctionFromFieldRef.

@Test
public void populateTransformedOutputFieldWithApplyDefineFunctionFromFieldRef() {
    // <DerivedField name="CUSTOM_REF_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_REF_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant1).build();
    // <DefineFunction name="CUSTOM_FUNCTION" optype="continuous" dataType="double">
    // <FieldRef>CUSTOM_REF_FIELD</FieldRef>
    // </DefineFunction>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(CUSTOM_REF_FIELD, Collections.emptyList(), null);
    final KiePMMLDefineFunction defineFunction = new KiePMMLDefineFunction(CUSTOM_FUNCTION, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, Collections.emptyList(), kiePMMLFieldRef1);
    // <Apply function="CUSTOM_FUNCTION">
    // <Constant>5.0</Constant>
    // </Apply>
    final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), value2, null);
    KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), CUSTOM_FUNCTION).withKiePMMLExpressions(Collections.singletonList(kiePMMLConstant2)).build();
    KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).withKiePMMLExpression(kiePMMLApply).build();
    // From TransformationDictionary
    KiePMMLTransformationDictionary transformationDictionary = KiePMMLTransformationDictionary.builder("transformationDictionary", Collections.emptyList()).withDefineFunctions(Collections.singletonList(defineFunction)).withDerivedFields(Collections.singletonList(derivedField)).build();
    KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).withKiePMMLTransformationDictionary(transformationDictionary).build();
    ProcessingDTO processingDTO = buildProcessingDTOWithEmptyNameValues(kiePMMLModel);
    PMML4Result toUpdate = new PMML4Result();
    PostProcess.populateOutputFields(toUpdate, processingDTO);
    assertFalse(toUpdate.getResultVariables().isEmpty());
    assertTrue(toUpdate.getResultVariables().containsKey(OUTPUT_NAME));
    assertEquals(value1, 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) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) KiePMMLTransformationDictionary(org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary) Test(org.junit.Test)

Example 12 with KiePMMLDefineFunction

use of org.kie.pmml.commons.transformations.KiePMMLDefineFunction in project drools by kiegroup.

the class KiePMMLApplyTest method getDefineFunctionApplyFromFieldRef.

private KiePMMLDefineFunction getDefineFunctionApplyFromFieldRef() {
    // <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>
    final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_1, Collections.emptyList(), value1, null);
    final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLConstant1, kiePMMLFieldRef)).build();
    final KiePMMLParameterField parameterField1 = KiePMMLParameterField.builder(PARAM_1, Collections.emptyList()).build();
    final KiePMMLParameterField parameterField2 = KiePMMLParameterField.builder(PARAM_2, Collections.emptyList()).build();
    return new KiePMMLDefineFunction(CUSTOM_FUNCTION, Collections.emptyList(), null, OP_TYPE.CONTINUOUS, Arrays.asList(parameterField1, parameterField2), kiePMMLApply);
}
Also used : KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField)

Example 13 with KiePMMLDefineFunction

use of org.kie.pmml.commons.transformations.KiePMMLDefineFunction in project drools by kiegroup.

the class KiePMMLApplyTest method getDefineFunctionApplyFromCustomFunction.

private KiePMMLDefineFunction getDefineFunctionApplyFromCustomFunction() {
    // <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>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLFieldRef kiePMMLFieldRef2 = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), CUSTOM_FUNCTION).withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef1, kiePMMLFieldRef2)).build();
    final KiePMMLParameterField parameterField1 = KiePMMLParameterField.builder(PARAM_1, Collections.emptyList()).build();
    final KiePMMLParameterField parameterField2 = KiePMMLParameterField.builder(PARAM_2, Collections.emptyList()).build();
    return new KiePMMLDefineFunction(OUTER_FUNCTION, Collections.emptyList(), null, OP_TYPE.CONTINUOUS, Arrays.asList(parameterField1, parameterField2), kiePMMLApply);
}
Also used : KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField)

Aggregations

KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)13 Test (org.junit.Test)7 KiePMMLParameterField (org.kie.pmml.commons.transformations.KiePMMLParameterField)7 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)6 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)5 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)5 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)5 KiePMMLTransformationDictionary (org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary)5 List (java.util.List)4 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)4 KiePMMLOutputField (org.kie.pmml.commons.model.KiePMMLOutputField)4 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)4 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3 DefineFunction (org.dmg.pmml.DefineFunction)3 PMML4Result (org.kie.api.pmml.PMML4Result)3 IntStream (java.util.stream.IntStream)2 DerivedField (org.dmg.pmml.DerivedField)2