use of org.kie.pmml.commons.model.KiePMMLOutputField in project drools by kiegroup.
the class PostProcess method populateOutputFields.
/**
* Populated the <code>PMML4Result</code> with <code>OutputField</code> results
* @param toUpdate
* @param processingDTO
*/
static void populateOutputFields(final PMML4Result toUpdate, final ProcessingDTO processingDTO) {
logger.debug("populateOutputFields {} {}", toUpdate, processingDTO);
for (KiePMMLOutputField outputField : processingDTO.getOutputFields()) {
Object variableValue = outputField.evaluate(processingDTO);
if (variableValue != null) {
String variableName = outputField.getName();
toUpdate.addResultVariable(variableName, variableValue);
processingDTO.addKiePMMLNameValue(new KiePMMLNameValue(variableName, variableValue));
}
}
}
use of org.kie.pmml.commons.model.KiePMMLOutputField in project drools by kiegroup.
the class PostProcessTest method populatePredictedOutputField1.
@Test
public void populatePredictedOutputField1() {
KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.PREDICTED_VALUE).build();
KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
ProcessingDTO processingDTO = buildProcessingDTOWithDefaultNameValues(kiePMMLModel);
PMML4Result toUpdate = new PMML4Result();
PostProcess.populateOutputFields(toUpdate, processingDTO);
assertTrue(toUpdate.getResultVariables().isEmpty());
}
use of org.kie.pmml.commons.model.KiePMMLOutputField in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputFieldWithApplyDefineFunctionFromConstant.
@Test
public void populateTransformedOutputFieldWithApplyDefineFunctionFromConstant() {
// <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(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, Collections.emptyList(), kiePMMLConstant1);
// <Apply function="CUSTOM_FUNCTION">
// <FieldRef>CUSTOM_FIELD</FieldRef>
// <Constant>5.0</Constant>
// </Apply>
final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(CUSTOM_FIELD, Collections.emptyList(), null);
final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), value2, null);
KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), CUSTOM_FUNCTION).withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef, 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)).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.KiePMMLOutputField in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputField1.
@Test
public void populateTransformedOutputField1() {
KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).build();
KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
ProcessingDTO processingDTO = buildProcessingDTOWithDefaultNameValues(kiePMMLModel);
PMML4Result toUpdate = new PMML4Result();
PostProcess.populateOutputFields(toUpdate, processingDTO);
assertTrue(toUpdate.getResultVariables().isEmpty());
}
use of org.kie.pmml.commons.model.KiePMMLOutputField in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputField2.
@Test
public void populateTransformedOutputField2() {
KiePMMLConstant kiePMMLConstant = new KiePMMLConstant("CONSTANT_NAME", Collections.emptyList(), "String", null);
KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).withKiePMMLExpression(kiePMMLConstant).build();
KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
ProcessingDTO processingDTO = buildProcessingDTOWithDefaultNameValues(kiePMMLModel);
PMML4Result toUpdate = new PMML4Result();
PostProcess.populateOutputFields(toUpdate, processingDTO);
assertFalse(toUpdate.getResultVariables().isEmpty());
assertTrue(toUpdate.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(kiePMMLConstant.getValue(), toUpdate.getResultVariables().get(OUTPUT_NAME));
}
Aggregations