use of org.kie.pmml.commons.model.expressions.KiePMMLConstant 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));
}
use of org.kie.pmml.commons.model.expressions.KiePMMLConstant in project drools by kiegroup.
the class KiePMMLDefineFunctionTest method evaluateFromConstant.
@Test
public void evaluateFromConstant() {
// <DefineFunction name="CUSTOM_FUNCTION" optype="continuous" dataType="double">
// <Constant>100.0</Constant>
// </DefineFunction>
final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_1, Collections.emptyList(), value1, null);
final KiePMMLDefineFunction defineFunction = new KiePMMLDefineFunction(CUSTOM_FUNCTION, Collections.emptyList(), null, OP_TYPE.CONTINUOUS, Collections.emptyList(), kiePMMLConstant1);
ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
Object retrieved = defineFunction.evaluate(processingDTO, Collections.emptyList());
assertEquals(value1, retrieved);
}
use of org.kie.pmml.commons.model.expressions.KiePMMLConstant in project drools by kiegroup.
the class KiePMMLOutputFieldTest method getOutputFields.
private List<KiePMMLOutputField> getOutputFields() {
// <OutputField name="PARAM_1" optype="continuous" dataType="double" feature="transformedValue">
// <Constant>100.0</Constant>
// </OutputField>
final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_1, Collections.emptyList(), value1, null);
final KiePMMLOutputField outputField1 = KiePMMLOutputField.builder(PARAM_1, Collections.emptyList()).withKiePMMLExpression(kiePMMLConstant1).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).build();
// <OutputField name="PARAM_1" optype="continuous" dataType="double" feature="transformedValue">
// <Constant>5.0</Constant>
// </OutputField>
final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), value2, null);
final KiePMMLOutputField outputField2 = KiePMMLOutputField.builder(PARAM_2, Collections.emptyList()).withKiePMMLExpression(kiePMMLConstant2).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).build();
return Arrays.asList(outputField1, outputField2);
}
use of org.kie.pmml.commons.model.expressions.KiePMMLConstant in project drools by kiegroup.
the class KiePMMLAttributeTest method getDerivedFields.
private List<KiePMMLDerivedField> getDerivedFields() {
// <DerivedField name="PARAM_1" optype="continuous" dataType="double">
// <Constant>100.0</Constant>
// </DerivedField>
final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_1, Collections.emptyList(), value1, null);
final KiePMMLDerivedField derivedField1 = KiePMMLDerivedField.builder(PARAM_1, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant1).build();
// <DerivedField name="PARAM_1" optype="continuous" dataType="double">
// <Constant>5.0</Constant>
// </DerivedField>
final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), value2, null);
final KiePMMLDerivedField derivedField2 = KiePMMLDerivedField.builder(PARAM_2, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant2).build();
return Arrays.asList(derivedField1, derivedField2);
}
Aggregations