Search in sources :

Example 1 with FieldValue

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;
}
Also used : InputField(org.jpmml.evaluator.InputField) EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) FieldValue(org.jpmml.evaluator.FieldValue) FieldName(org.dmg.pmml.FieldName) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 FieldName (org.dmg.pmml.FieldName)1 FieldValue (org.jpmml.evaluator.FieldValue)1 InputField (org.jpmml.evaluator.InputField)1 BatchEvaluationResponse (org.openscoring.common.BatchEvaluationResponse)1 EvaluationResponse (org.openscoring.common.EvaluationResponse)1