use of org.jpmml.evaluator.FieldValue in project openscoring by openscoring.
the class ModelResource method evaluate.
protected static EvaluationResponse evaluate(Evaluator evaluator, EvaluationRequest request) {
logger.info("Received {}", request);
Map<String, ?> requestArguments = request.getArguments();
EvaluationResponse response = new EvaluationResponse(request.getId());
Map<FieldName, FieldValue> arguments = new LinkedHashMap<>();
List<InputField> inputFields = evaluator.getInputFields();
for (InputField inputField : inputFields) {
FieldName inputName = inputField.getName();
String key = inputName.getValue();
Object value = requestArguments.get(key);
if (value == null && !requestArguments.containsKey(key)) {
logger.warn("Evaluation request {} does not specify an input field {}", request.getId(), key);
}
FieldValue inputValue = inputField.prepare(value);
arguments.put(inputName, inputValue);
}
logger.debug("Evaluation request {} has prepared arguments: {}", request.getId(), arguments);
Map<FieldName, ?> result = evaluator.evaluate(arguments);
// Jackson does not support the JSON serialization of <code>null</code> map keys
result = replaceNullKey(result);
logger.debug("Evaluation response {} has result: {}", response.getId(), result);
response.setResult(EvaluatorUtil.decode(result));
logger.info("Returned {}", response);
return response;
}
Aggregations