use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLMapValuesTest method evaluateKeyNotFound.
@Test
public void evaluateKeyNotFound() {
KiePMMLMapValues kiePMMLMapValues = getKiePMMLMapValues();
ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
assertEquals(MAPMISSINGTO, kiePMMLMapValues.evaluate(processingDTO));
}
use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLNormDiscreteTest method evaluateMissingValue.
@Test
public void evaluateMissingValue() {
String fieldName = "fieldName";
String fieldValue = "fieldValue";
Number mapMissingTo = 1.0;
KiePMMLNormDiscrete kiePMMLNormContinuous = getKiePMMLNormDiscrete(fieldName, fieldValue, mapMissingTo);
ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
Object retrieved = kiePMMLNormContinuous.evaluate(processingDTO);
assertNotNull(retrieved);
assertEquals(mapMissingTo, retrieved);
}
use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLApply method evaluate.
@Override
public Object evaluate(final ProcessingDTO processingDTO) {
if (kiePMMLExpressions == null) {
return null;
}
// <- Insertion order matter
List<Object> expressionValues = new ArrayList<>();
MiningField referredByFieldRef = null;
for (KiePMMLExpression kiePMMLExpression : kiePMMLExpressions) {
expressionValues.add(kiePMMLExpression.evaluate(processingDTO));
if (kiePMMLExpression instanceof KiePMMLFieldRef && BUILTIN_FUNCTIONS.isBUILTIN_FUNCTIONS_VALIDATION(function)) {
String referredField = ((KiePMMLFieldRef) kiePMMLExpression).getName();
referredByFieldRef = processingDTO.getMiningFields().stream().filter(miningField -> referredField.equals(miningField.getName())).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("Missing required field %s", referredField)));
}
}
if (BUILTIN_FUNCTIONS.isBUILTIN_FUNCTIONS(function)) {
BUILTIN_FUNCTIONS builtinFunction = BUILTIN_FUNCTIONS.byName(function);
return builtinFunction.getValue(expressionValues.toArray(new Object[0]), referredByFieldRef);
} else {
final KiePMMLDefineFunction definedFunction = processingDTO.getDefineFunctions().stream().filter(defineFunction -> defineFunction.getName().equals(function)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown function " + function));
return definedFunction.evaluate(processingDTO, expressionValues);
}
}
Aggregations