use of org.kie.pmml.api.enums.BUILTIN_FUNCTIONS 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