use of org.kie.pmml.commons.transformations.KiePMMLLocalTransformations in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputFieldWithApplyDerivedFieldFromFieldRef.
@Test
public void populateTransformedOutputFieldWithApplyDerivedFieldFromFieldRef() {
// <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 derivedField1 = KiePMMLDerivedField.builder(CUSTOM_REF_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant1).build();
// <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
// <FieldRef>CUSTOM_REF_FIELD</FieldRef>
// </DerivedField>
final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(CUSTOM_REF_FIELD, Collections.emptyList(), null);
final KiePMMLDerivedField derivedField2 = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLFieldRef).build();
// <Apply function="/">
// <FieldRef>CUSTOM_FIELD</FieldRef>
// <Constant>5.0</Constant>
// </Apply>
final KiePMMLFieldRef kiePMMLFieldRef2 = 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(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef2, 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()).withDerivedFields(Arrays.asList(derivedField1, derivedField2)).build();
KiePMMLTestingModel kiePMMLModel1 = testingModelBuilder(outputField).withKiePMMLTransformationDictionary(transformationDictionary).build();
ProcessingDTO processingDTO1 = buildProcessingDTOWithEmptyNameValues(kiePMMLModel1);
PMML4Result toUpdate1 = new PMML4Result();
PostProcess.populateOutputFields(toUpdate1, processingDTO1);
assertFalse(toUpdate1.getResultVariables().isEmpty());
assertTrue(toUpdate1.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(value1 / value2, toUpdate1.getResultVariables().get(OUTPUT_NAME));
// From LocalTransformations
KiePMMLLocalTransformations localTransformations = KiePMMLLocalTransformations.builder("localTransformations", Collections.emptyList()).withDerivedFields(Arrays.asList(derivedField1, derivedField2)).build();
KiePMMLTestingModel kiePMMLModel2 = testingModelBuilder(outputField).withKiePMMLLocalTransformations(localTransformations).build();
ProcessingDTO processingDTO2 = buildProcessingDTOWithEmptyNameValues(kiePMMLModel2);
PMML4Result toUpdate2 = new PMML4Result();
PostProcess.populateOutputFields(toUpdate2, processingDTO2);
assertFalse(toUpdate2.getResultVariables().isEmpty());
assertTrue(toUpdate2.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(value1 / value2, toUpdate2.getResultVariables().get(OUTPUT_NAME));
}
use of org.kie.pmml.commons.transformations.KiePMMLLocalTransformations in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputFieldWithApplyDerivedFieldFromApply.
@Test
public void populateTransformedOutputFieldWithApplyDerivedFieldFromApply() {
// <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
// <Apply function="+">
// <Constant>64.0</Constant>
// <Constant>36.0</Constant>
// </Apply>
// </DerivedField>
final KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), 64.0, null);
final KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), 36, null);
final KiePMMLApply kiePMMLApplyRef = KiePMMLApply.builder("NAMEREF", Collections.emptyList(), "+").withKiePMMLExpressions(Arrays.asList(kiePMMLConstant1, kiePMMLConstant2)).build();
final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLApplyRef).build();
// <Apply function="/">
// <FieldRef>CUSTOM_FIELD</FieldRef>
// <Constant>5.0</Constant>
// </Apply>
final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(CUSTOM_FIELD, Collections.emptyList(), null);
final KiePMMLConstant kiePMMLConstant3 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), value2, null);
KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef, kiePMMLConstant3)).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()).withDerivedFields(Collections.singletonList(derivedField)).build();
KiePMMLTestingModel kiePMMLModel1 = testingModelBuilder(outputField).withKiePMMLTransformationDictionary(transformationDictionary).build();
ProcessingDTO processingDTO1 = buildProcessingDTOWithEmptyNameValues(kiePMMLModel1);
PMML4Result toUpdate1 = new PMML4Result();
PostProcess.populateOutputFields(toUpdate1, processingDTO1);
assertFalse(toUpdate1.getResultVariables().isEmpty());
assertTrue(toUpdate1.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(value1 / value2, toUpdate1.getResultVariables().get(OUTPUT_NAME));
// From LocalTransformations
KiePMMLLocalTransformations localTransformations = KiePMMLLocalTransformations.builder("localTransformations", Collections.emptyList()).withDerivedFields(Collections.singletonList(derivedField)).build();
KiePMMLTestingModel kiePMMLModel2 = testingModelBuilder(outputField).withKiePMMLLocalTransformations(localTransformations).build();
ProcessingDTO processingDTO2 = buildProcessingDTOWithEmptyNameValues(kiePMMLModel2);
PMML4Result toUpdate2 = new PMML4Result();
PostProcess.populateOutputFields(toUpdate2, processingDTO2);
assertFalse(toUpdate2.getResultVariables().isEmpty());
assertTrue(toUpdate2.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(value1 / value2, toUpdate2.getResultVariables().get(OUTPUT_NAME));
}
use of org.kie.pmml.commons.transformations.KiePMMLLocalTransformations in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputFieldWithApplyDerivedFieldFromConstant.
@Test
public void populateTransformedOutputFieldWithApplyDerivedFieldFromConstant() {
// <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();
// <Apply 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(), "/").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()).withDerivedFields(Collections.singletonList(derivedField)).build();
KiePMMLTestingModel kiePMMLModel1 = testingModelBuilder(outputField).withKiePMMLTransformationDictionary(transformationDictionary).build();
ProcessingDTO processingDTO1 = buildProcessingDTOWithEmptyNameValues(kiePMMLModel1);
PMML4Result toUpdate1 = new PMML4Result();
PostProcess.populateOutputFields(toUpdate1, processingDTO1);
assertFalse(toUpdate1.getResultVariables().isEmpty());
assertTrue(toUpdate1.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(value1 / value2, toUpdate1.getResultVariables().get(OUTPUT_NAME));
// From LocalTransformations
KiePMMLLocalTransformations localTransformations = KiePMMLLocalTransformations.builder("localTransformations", Collections.emptyList()).withDerivedFields(Collections.singletonList(derivedField)).build();
KiePMMLTestingModel kiePMMLModel2 = testingModelBuilder(outputField).withKiePMMLLocalTransformations(localTransformations).build();
ProcessingDTO processingDTO2 = buildProcessingDTOWithEmptyNameValues(kiePMMLModel2);
PMML4Result toUpdate2 = new PMML4Result();
PostProcess.populateOutputFields(toUpdate2, processingDTO2);
assertFalse(toUpdate2.getResultVariables().isEmpty());
assertTrue(toUpdate2.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(value1 / value2, toUpdate2.getResultVariables().get(OUTPUT_NAME));
}
use of org.kie.pmml.commons.transformations.KiePMMLLocalTransformations in project drools by kiegroup.
the class KiePMMLLocalTransformationsInstanceFactoryTest method getKiePMMLLocalTransformations.
@Test
public void getKiePMMLLocalTransformations() {
final LocalTransformations toConvert = getRandomLocalTransformations();
KiePMMLLocalTransformations retrieved = KiePMMLLocalTransformationsInstanceFactory.getKiePMMLLocalTransformations(toConvert, Collections.emptyList());
assertNotNull(retrieved);
List<DerivedField> derivedFields = toConvert.getDerivedFields();
List<KiePMMLDerivedField> derivedFieldsToVerify = retrieved.getDerivedFields();
assertEquals(derivedFields.size(), derivedFieldsToVerify.size());
derivedFields.forEach(derivedFieldSource -> {
Optional<KiePMMLDerivedField> derivedFieldToVerify = derivedFieldsToVerify.stream().filter(param -> param.getName().equals(derivedFieldSource.getName().getValue())).findFirst();
assertTrue(derivedFieldToVerify.isPresent());
commonVerifyKiePMMLDerivedField(derivedFieldToVerify.get(), derivedFieldSource);
});
}
Aggregations