Search in sources :

Example 16 with KiePMMLFieldRef

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

the class KiePMMLDefineFunctionTest method evaluateFromApply.

@Test
public void evaluateFromApply() {
    // <DefineFunction name="CUSTOM_FUNCTION" optype="continuous" dataType="double">
    // <ParameterField name="PARAM_1"/>
    // <ParameterField field="PARAM_2"/>
    // <Apply function="/">
    // <FieldRef>PARAM_1</FieldRef>
    // <FieldRef>PARAM_2</FieldRef>
    // </Apply>
    // </DefineFunction>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLFieldRef kiePMMLFieldRef2 = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    final KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef1, kiePMMLFieldRef2)).build();
    final KiePMMLParameterField parameterField1 = KiePMMLParameterField.builder(PARAM_1, Collections.emptyList()).build();
    final KiePMMLParameterField parameterField2 = KiePMMLParameterField.builder(PARAM_2, Collections.emptyList()).build();
    final KiePMMLDefineFunction defineFunction = new KiePMMLDefineFunction(CUSTOM_FUNCTION, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, Arrays.asList(parameterField1, parameterField2), kiePMMLApply);
    ProcessingDTO processingDTO = getProcessingDTO(new ArrayList<>());
    Object retrieved = defineFunction.evaluate(processingDTO, Arrays.asList(value1, value2));
    Object expected = value1 / value2;
    assertEquals(expected, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Example 17 with KiePMMLFieldRef

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

the class KiePMMLOutputFieldTest method evaluateTransformedValueFromApplyWithOutputFields.

@Test
public void evaluateTransformedValueFromApplyWithOutputFields() {
    // <OutputField name="CUSTOM_FIELD" optype="continuous" dataType="double" feature="transformedValue">
    // <Apply function="/">
    // <FieldRef>PARAM_1</FieldRef>
    // <FieldRef>PARAM_2</FieldRef>
    // </Apply>
    // </OutputField>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLFieldRef kiePMMLFieldRef2 = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    final KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef1, kiePMMLFieldRef2)).build();
    final KiePMMLOutputField outputField = KiePMMLOutputField.builder(CUSTOM_FIELD, Collections.emptyList()).withKiePMMLExpression(kiePMMLApply).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).build();
    ProcessingDTO processingDTO = getProcessingDTO(getOutputFields(), new ArrayList<>(), Collections.emptyList());
    Object retrieved = outputField.evaluate(processingDTO);
    Object expected = value1 / value2;
    assertEquals(expected, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Example 18 with KiePMMLFieldRef

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

the class KiePMMLOutputFieldTest method evaluateTransformedValueFromFieldRef.

@Test
public void evaluateTransformedValueFromFieldRef() {
    // <OutputField name="CUSTOM_FIELD" optype="continuous" dataType="double" feature="transformedValue">
    // <FieldRef field="PARAM_1"/>
    // </OutputField>
    final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLOutputField outputField = KiePMMLOutputField.builder(CUSTOM_FIELD, Collections.emptyList()).withKiePMMLExpression(kiePMMLFieldRef).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).build();
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), Arrays.asList(new KiePMMLNameValue(PARAM_1, value1)), Collections.emptyList());
    Object retrieved = outputField.evaluate(processingDTO);
    assertEquals(value1, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Example 19 with KiePMMLFieldRef

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

the class KiePMMLDerivedFieldTest method evaluateFromApplyWithKiePMMLNameValues.

@Test
public void evaluateFromApplyWithKiePMMLNameValues() {
    // <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
    // <Apply function="/">
    // <FieldRef>PARAM_1</FieldRef>
    // <FieldRef>PARAM_2</FieldRef>
    // </Apply>
    // </DerivedField>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLFieldRef kiePMMLFieldRef2 = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    final KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef1, kiePMMLFieldRef2)).build();
    final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLApply).build();
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), getKiePMMLNameValues());
    Object retrieved = derivedField.evaluate(processingDTO);
    Object expected = value1 / value2;
    assertEquals(expected, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Example 20 with KiePMMLFieldRef

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

the class KiePMMLDerivedFieldTest method evaluateFromFieldRef.

@Test
public void evaluateFromFieldRef() {
    // <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
    // <FieldRef field="PARAM_1"/>
    // </DerivedField>
    final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLFieldRef).build();
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), Arrays.asList(new KiePMMLNameValue(PARAM_1, value1)));
    Object retrieved = derivedField.evaluate(processingDTO);
    assertEquals(value1, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Aggregations

KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)21 Test (org.junit.Test)20 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)15 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)15 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)13 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)8 PMML4Result (org.kie.api.pmml.PMML4Result)7 KiePMMLOutputField (org.kie.pmml.commons.model.KiePMMLOutputField)7 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)7 KiePMMLTransformationDictionary (org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary)7 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)5 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)4 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)4 KiePMMLLocalTransformations (org.kie.pmml.commons.transformations.KiePMMLLocalTransformations)3 KiePMMLParameterField (org.kie.pmml.commons.transformations.KiePMMLParameterField)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1