Search in sources :

Example 6 with KiePMMLOutputField

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

the class PostProcessTest method populateTransformedOutputFieldWithConstant.

@Test
public void populateTransformedOutputFieldWithConstant() {
    KiePMMLConstant kiePMMLConstant = new KiePMMLConstant("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 = buildProcessingDTOWithEmptyNameValues(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));
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Test(org.junit.Test)

Example 7 with KiePMMLOutputField

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

the class PostProcessTest method populateTransformedOutputFieldWithFieldRef.

@Test
public void populateTransformedOutputFieldWithFieldRef() {
    final String mapMissingTo = "mapMissingTo";
    final String variableName = "variableName";
    final Object variableValue = 543.65434;
    KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(variableName, Collections.emptyList(), mapMissingTo);
    KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).withKiePMMLExpression(kiePMMLFieldRef).build();
    KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
    ProcessingDTO processingDTO = buildProcessingDTOWithNameValues(kiePMMLModel, new KiePMMLNameValue(variableName, variableValue));
    PMML4Result toUpdate = new PMML4Result();
    PostProcess.populateOutputFields(toUpdate, processingDTO);
    assertFalse(toUpdate.getResultVariables().isEmpty());
    assertTrue(toUpdate.getResultVariables().containsKey(OUTPUT_NAME));
    assertEquals(variableValue, 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) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Example 8 with KiePMMLOutputField

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

the class PostProcessTest method populatePredictedOutputField2.

@Test
public void populatePredictedOutputField2() {
    KiePMMLNameValue kiePMMLNameValue = new KiePMMLNameValue("targetField", 54346.32454);
    KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.PREDICTED_VALUE).withTargetField(kiePMMLNameValue.getName()).build();
    KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
    ProcessingDTO processingDTO = buildProcessingDTOWithNameValues(kiePMMLModel, kiePMMLNameValue);
    PMML4Result toUpdate = new PMML4Result();
    PostProcess.populateOutputFields(toUpdate, processingDTO);
    assertFalse(toUpdate.getResultVariables().isEmpty());
    assertTrue(toUpdate.getResultVariables().containsKey(OUTPUT_NAME));
    assertEquals(kiePMMLNameValue.getValue(), 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) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Test(org.junit.Test)

Example 9 with KiePMMLOutputField

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

the class PostProcessTest method populateTransformedOutputFieldWithApplyWithConstants.

@Test
public void populateTransformedOutputFieldWithApplyWithConstants() {
    // <Apply function="/">
    // <Constant>100.0</Constant>
    // <Constant>5.0</Constant>
    // </Apply>
    KiePMMLConstant kiePMMLConstant1 = new KiePMMLConstant(PARAM_1, Collections.emptyList(), value1, null);
    KiePMMLConstant kiePMMLConstant2 = new KiePMMLConstant(PARAM_2, Collections.emptyList(), value2, null);
    KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLConstant1, kiePMMLConstant2)).build();
    KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).withKiePMMLExpression(kiePMMLApply).build();
    KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).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 / value2, 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) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Test(org.junit.Test)

Example 10 with KiePMMLOutputField

use of org.kie.pmml.commons.model.KiePMMLOutputField 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));
}
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) KiePMMLOutputField(org.kie.pmml.commons.model.KiePMMLOutputField) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) KiePMMLLocalTransformations(org.kie.pmml.commons.transformations.KiePMMLLocalTransformations) 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)

Aggregations

KiePMMLOutputField (org.kie.pmml.commons.model.KiePMMLOutputField)17 Test (org.junit.Test)15 PMML4Result (org.kie.api.pmml.PMML4Result)13 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)13 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)13 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)13 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)9 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)7 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)7 KiePMMLTransformationDictionary (org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary)6 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)4 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)3 KiePMMLLocalTransformations (org.kie.pmml.commons.transformations.KiePMMLLocalTransformations)3 RESULT_FEATURE (org.kie.pmml.api.enums.RESULT_FEATURE)2 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)2 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 CastExpr (com.github.javaparser.ast.expr.CastExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1