use of org.kie.kogito.jitexecutor.dmn.responses.JITDMNResult in project kogito-apps by kiegroup.
the class JITDMNServiceImpl method evaluateModel.
@Override
public JITDMNResult evaluateModel(String modelXML, Map<String, Object> context) {
DMNEvaluator dmnEvaluator = DMNEvaluator.fromXML(modelXML);
DMNResult dmnResult = dmnEvaluator.evaluate(context);
return new JITDMNResult(dmnEvaluator.getNamespace(), dmnEvaluator.getName(), dmnResult);
}
use of org.kie.kogito.jitexecutor.dmn.responses.JITDMNResult in project kogito-apps by kiegroup.
the class JITDMNServiceImpl method evaluateModelAndExplain.
public DMNResultWithExplanation evaluateModelAndExplain(DMNEvaluator dmnEvaluator, Map<String, Object> context) {
LocalDMNPredictionProvider localDMNPredictionProvider = new LocalDMNPredictionProvider(dmnEvaluator);
DMNResult dmnResult = dmnEvaluator.evaluate(context);
Prediction prediction = new SimplePrediction(LocalDMNPredictionProvider.toPredictionInput(context), LocalDMNPredictionProvider.toPredictionOutput(dmnResult));
LimeConfig limeConfig = new LimeConfig().withSamples(explainabilityLimeSampleSize).withPerturbationContext(new PerturbationContext(new Random(), explainabilityLimeNoOfPerturbation));
LimeExplainer limeExplainer = new LimeExplainer(limeConfig);
Map<String, Saliency> saliencyMap;
try {
saliencyMap = limeExplainer.explainAsync(prediction, localDMNPredictionProvider).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
} catch (TimeoutException | InterruptedException | ExecutionException e) {
if (e instanceof InterruptedException) {
LOGGER.error("Critical InterruptedException occurred", e);
Thread.currentThread().interrupt();
}
return new DMNResultWithExplanation(new JITDMNResult(dmnEvaluator.getNamespace(), dmnEvaluator.getName(), dmnResult), new SalienciesResponse(EXPLAINABILITY_FAILED, EXPLAINABILITY_FAILED_MESSAGE, null));
}
List<SaliencyResponse> saliencyModelResponse = buildSalienciesResponse(dmnEvaluator.getDmnModel(), saliencyMap);
return new DMNResultWithExplanation(new JITDMNResult(dmnEvaluator.getNamespace(), dmnEvaluator.getName(), dmnResult), new SalienciesResponse(EXPLAINABILITY_SUCCEEDED, null, saliencyModelResponse));
}
use of org.kie.kogito.jitexecutor.dmn.responses.JITDMNResult in project kogito-apps by kiegroup.
the class JITDMNServiceImpl method evaluateModel.
@Override
public JITDMNResult evaluateModel(MultipleResourcesPayload payload, Map<String, Object> context) {
DMNEvaluator dmnEvaluator = DMNEvaluator.fromMultiple(payload);
DMNResult dmnResult = dmnEvaluator.evaluate(context);
return new JITDMNResult(dmnEvaluator.getNamespace(), dmnEvaluator.getName(), dmnResult);
}
use of org.kie.kogito.jitexecutor.dmn.responses.JITDMNResult in project kogito-apps by kiegroup.
the class JITDMNResource method jitdmn.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response jitdmn(JITDMNPayload payload) {
JITDMNResult evaluateAll = payload.getModel() != null ? jitdmnService.evaluateModel(payload.getModel(), payload.getContext()) : jitdmnService.evaluateModel(payload, payload.getContext());
Map<String, Object> restResulk = new HashMap<>();
for (Entry<String, Object> kv : evaluateAll.getContext().getAll().entrySet()) {
restResulk.put(kv.getKey(), MarshallingStubUtils.stubDMNResult(kv.getValue(), String::valueOf));
}
return Response.ok(restResulk).build();
}
use of org.kie.kogito.jitexecutor.dmn.responses.JITDMNResult in project kogito-apps by kiegroup.
the class JITDMNServiceImplTest method testModelEvaluation.
@Test
public void testModelEvaluation() {
Map<String, Object> context = new HashMap<>();
context.put("FICO Score", 800);
context.put("DTI Ratio", .1);
context.put("PITI Ratio", .1);
JITDMNResult dmnResult = jitdmnService.evaluateModel(model, context);
Assertions.assertEquals("xls2dmn", dmnResult.getModelName());
Assertions.assertEquals("xls2dmn_741b355c-685c-4827-b13a-833da8321da4", dmnResult.getNamespace());
Assertions.assertTrue(dmnResult.getMessages().isEmpty());
Assertions.assertEquals("Approved", dmnResult.getDecisionResultByName("Loan Approval").getResult());
}
Aggregations