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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations