Search in sources :

Example 6 with KiePMMLDerivedField

use of org.kie.pmml.commons.transformations.KiePMMLDerivedField 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)

Example 7 with KiePMMLDerivedField

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

the class KiePMMLComplexPartialScoreTest 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);
}
Also used : KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant)

Example 8 with KiePMMLDerivedField

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

the class KiePMMLDerivedFieldInstanceFactoryTest method getKiePMMLDerivedField.

@Test
public void getKiePMMLDerivedField() {
    final String fieldName = "fieldName";
    final DerivedField toConvert = getDerivedField(fieldName);
    KiePMMLDerivedField retrieved = KiePMMLDerivedFieldInstanceFactory.getKiePMMLDerivedField(toConvert, Collections.emptyList());
    commonVerifyKiePMMLDerivedField(retrieved, toConvert);
}
Also used : InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField) PMMLModelTestUtils.getDerivedField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDerivedField) DerivedField(org.dmg.pmml.DerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) Test(org.junit.Test)

Example 9 with KiePMMLDerivedField

use of org.kie.pmml.commons.transformations.KiePMMLDerivedField 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);
    });
}
Also used : InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField) LocalTransformations(org.dmg.pmml.LocalTransformations) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) KiePMMLLocalTransformations(org.kie.pmml.commons.transformations.KiePMMLLocalTransformations) List(java.util.List) DerivedField(org.dmg.pmml.DerivedField) PMMLModelTestUtils.getRandomLocalTransformations(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomLocalTransformations) Optional(java.util.Optional) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) LocalTransformations(org.dmg.pmml.LocalTransformations) KiePMMLLocalTransformations(org.kie.pmml.commons.transformations.KiePMMLLocalTransformations) PMMLModelTestUtils.getRandomLocalTransformations(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomLocalTransformations) InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) KiePMMLLocalTransformations(org.kie.pmml.commons.transformations.KiePMMLLocalTransformations) InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLDerivedField) DerivedField(org.dmg.pmml.DerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) Test(org.junit.Test)

Example 10 with KiePMMLDerivedField

use of org.kie.pmml.commons.transformations.KiePMMLDerivedField 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));
}
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

KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)15 Test (org.junit.Test)12 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)9 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)8 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)7 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)6 KiePMMLTransformationDictionary (org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary)6 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)5 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)5 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)5 PMML4Result (org.kie.api.pmml.PMML4Result)4 KiePMMLOutputField (org.kie.pmml.commons.model.KiePMMLOutputField)4 KiePMMLLocalTransformations (org.kie.pmml.commons.transformations.KiePMMLLocalTransformations)4 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 DerivedField (org.dmg.pmml.DerivedField)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)3