use of org.kie.kogito.explainability.model.ModelIdentifier in project kogito-runtimes by kiegroup.
the class SpringBootExplainableResourceTest method createInput.
private PredictInput createInput(int speedLimit) {
String resourceId = String.format("%s:%s", MODEL_NAMESPACE, MODEL_NAME);
Map<String, Object> driver = new HashMap<>();
driver.put("Age", 25);
driver.put("Points", 100);
Map<String, Object> violation = new HashMap<>();
violation.put("Type", "speed");
violation.put("Actual Speed", 120);
violation.put("Speed Limit", speedLimit);
Map<String, Object> payload = new HashMap<>();
payload.put("Driver", driver);
payload.put("Violation", violation);
ModelIdentifier modelIdentifier = new ModelIdentifier("dmn", resourceId);
return new PredictInput(modelIdentifier, payload);
}
use of org.kie.kogito.explainability.model.ModelIdentifier in project kogito-runtimes by kiegroup.
the class DecisionExplainabilityResourceExecutorTest method testAcceptRequest.
@Test
public void testAcceptRequest() {
DecisionExplainabilityResourceExecutor executor = new DecisionExplainabilityResourceExecutor();
ModelIdentifier notADMNModelIdentifier = new ModelIdentifier("notAdmn", String.format("%s%s%s", "namespace", RESOURCE_ID_SEPARATOR, "name"));
ModelIdentifier DMNModelIdentifier = new ModelIdentifier("dmn", String.format("%s%s%s", "namespace", RESOURCE_ID_SEPARATOR, "name"));
PredictInput notADMNModelPredictInput = new PredictInput(notADMNModelIdentifier, null);
PredictInput DMNModelPredictInput = new PredictInput(DMNModelIdentifier, null);
Assertions.assertFalse(executor.acceptRequest(notADMNModelPredictInput));
Assertions.assertTrue(executor.acceptRequest(DMNModelPredictInput));
}
use of org.kie.kogito.explainability.model.ModelIdentifier in project kogito-runtimes by kiegroup.
the class DecisionExplainabilityResourceExecutorTest method testGetDecisionModel.
@ParameterizedTest
@MethodSource("getDecisionModelTestProvider")
public void testGetDecisionModel(String[] args) {
String namespace = args[0];
String name = args[1];
DecisionExplainabilityResourceExecutor executor = new DecisionExplainabilityResourceExecutor();
DecisionModels decisionModels = mock(DecisionModels.class);
DecisionModel model = new DmnDecisionModel(generateDMNRuntime(namespace, name), namespace, name);
when(decisionModels.getDecisionModel(eq(namespace), eq(name))).thenReturn(model);
ModelIdentifier modelIdentifier = new ModelIdentifier("dmn", String.format("%s%s%s", namespace, RESOURCE_ID_SEPARATOR, name));
DecisionModel decisionModelResponse = executor.getDecisionModel(decisionModels, modelIdentifier);
Assertions.assertNotNull(decisionModelResponse);
Assertions.assertEquals(namespace, decisionModelResponse.getDMNModel().getNamespace());
Assertions.assertEquals(name, decisionModelResponse.getDMNModel().getName());
}
use of org.kie.kogito.explainability.model.ModelIdentifier in project kogito-runtimes by kiegroup.
the class ExplainabilityServiceTest method testPerturbedExecution.
@Test
public void testPerturbedExecution() {
DecisionModels decisionModels = (namespace, name) -> {
if (MODEL_NAMESPACE.equals(namespace) && MODEL_NAME.equals(name)) {
return decisionModel;
}
throw new RuntimeException("Model " + namespace + ":" + name + " not found.");
};
Map<String, Object> perturbedRequest = createRequest();
PredictInput predictInput = new PredictInput(new ModelIdentifier("dmn", String.format("%s%s%s", MODEL_NAMESPACE, RESOURCE_ID_SEPARATOR, MODEL_NAME)), perturbedRequest);
StaticApplication application = new StaticApplication(null, null, null, decisionModels, null);
ExplainabilityService explainabilityService = ExplainabilityService.INSTANCE;
List<PredictOutput> predictOutputs = explainabilityService.processRequest(application, singletonList(predictInput));
Assertions.assertEquals(1, predictOutputs.size());
PredictOutput predictOutput = predictOutputs.get(0);
Assertions.assertNotNull(predictOutput);
Assertions.assertNotNull(predictOutput.getResult());
Map<String, Object> perturbedResult = predictOutput.getResult();
Assertions.assertTrue(perturbedResult.containsKey("Should the driver be suspended?"));
Assertions.assertEquals("No", perturbedResult.get("Should the driver be suspended?"));
Assertions.assertTrue(perturbedResult.containsKey("Fine"));
Assertions.assertNull(perturbedResult.get("Fine"));
Assertions.assertTrue(decisionModel.getEvaluationSkipMonitoringHistory().stream().allMatch(x -> x.equals(true)));
}
Aggregations