use of org.jpmml.evaluator.Evaluator in project openscoring by openscoring.
the class ModelRegistry method store.
public void store(Model model, OutputStream os) throws JAXBException {
Evaluator evaluator = model.getEvaluator();
if (evaluator instanceof HasPMML) {
HasPMML hasPMML = (HasPMML) evaluator;
PMML pmml = hasPMML.getPMML();
marshal(pmml, os);
}
}
use of org.jpmml.evaluator.Evaluator in project openscoring by openscoring.
the class ModelResource method doEvaluate.
@SuppressWarnings(value = "resource")
private List<EvaluationResponse> doEvaluate(String id, List<EvaluationRequest> requests, boolean allOrNothing, String method) {
Model model = this.modelRegistry.get(id, true);
if (model == null) {
throw new NotFoundException("Model \"" + id + "\" not found");
}
List<EvaluationResponse> responses = new ArrayList<>();
Timer timer = this.metricRegistry.timer(createName(id, method));
Timer.Context context = timer.time();
try {
Evaluator evaluator = model.getEvaluator();
if (evaluator instanceof HasGroupFields) {
HasGroupFields hasGroupFields = (HasGroupFields) evaluator;
List<InputField> groupFields = hasGroupFields.getGroupFields();
if (groupFields.size() == 1) {
InputField groupField = groupFields.get(0);
requests = aggregateRequests(groupField.getName(), requests);
} else if (groupFields.size() > 1) {
throw new EvaluationException("Too many group fields");
}
}
for (EvaluationRequest request : requests) {
EvaluationResponse response;
try {
response = evaluate(evaluator, request);
} catch (Exception e) {
if (allOrNothing) {
throw e;
}
response = new EvaluationResponse(request.getId());
response.setMessage(e.toString());
}
responses.add(response);
}
} catch (Exception e) {
logger.error("Failed to evaluate", e);
throw new BadRequestException(e);
}
context.stop();
Counter counter = this.metricRegistry.counter(createName(id, "records"));
counter.inc(responses.size());
return responses;
}
use of org.jpmml.evaluator.Evaluator in project storm by apache.
the class JpmmlModelOutputs method create.
// ======
private static ModelOutputs create(PMML pmmlModel, List<String> streams) {
final Set<String> fieldNames = new LinkedHashSet<>();
final Evaluator evaluator = JpmmlFactory.newEvaluator(pmmlModel);
for (FieldName predictedField : evaluator.getPredictedFields()) {
fieldNames.add(predictedField.getValue());
}
for (FieldName outputField : evaluator.getOutputFields()) {
fieldNames.add(outputField.getValue());
}
final Map<String, Fields> toDeclare = streams.stream().collect(Collectors.toMap(Function.identity(), (x) -> new Fields(new ArrayList<>(fieldNames))));
return new JpmmlModelOutputs(toDeclare);
}
Aggregations