use of org.kie.kogito.dmn.DmnDecisionModel in project kogito-runtimes by kiegroup.
the class DecisionTracingListenerTest method testWithRealRuntime.
private static List<EvaluateEvent> testWithRealRuntime(Map<String, Object> contextVariables, int expectedEvents, BiConsumer<DecisionModel, DMNContext> modelConsumer) {
final DMNRuntime runtime = createDMNRuntime();
Consumer<EvaluateEvent> eventConsumer = mock(Consumer.class);
DecisionTracingListener listener = new DecisionTracingListener(eventConsumer);
runtime.addListener(listener);
final DecisionModel model = new DmnDecisionModel(runtime, MODEL_NAMESPACE, MODEL_NAME, () -> TEST_EXECUTION_ID_2);
final DMNContext context = model.newContext(contextVariables);
modelConsumer.accept(model, context);
ArgumentCaptor<EvaluateEvent> eventCaptor = ArgumentCaptor.forClass(EvaluateEvent.class);
verify(eventConsumer, times(expectedEvents)).accept(eventCaptor.capture());
return eventCaptor.getAllValues();
}
use of org.kie.kogito.dmn.DmnDecisionModel in project kogito-runtimes by kiegroup.
the class RuleSetTest method createProcess.
private RuleFlowProcess createProcess(String namespace, String modelName, String decisionName) {
DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(RuleSetTest.class.getResourceAsStream("/org/jbpm/process/PersonDecisions.dmn")));
DmnDecisionModel dmnDecisionModel = new DmnDecisionModel(dmnRuntime, namespace, modelName);
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.process");
process.setName("Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable1 = new Variable();
variable1.setName("person");
variable1.setType(new ObjectDataType(Person.class.getName()));
variables.add(variable1);
Variable variable2 = new Variable();
variable2.setName("isAdult");
variable2.setType(new BooleanDataType());
variables.add(variable2);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
RuleSetNode ruleSetNode = new RuleSetNode();
ruleSetNode.setName("RuleSetNode");
ruleSetNode.setId(2);
ruleSetNode.setRuleType(RuleSetNode.RuleType.decision(namespace, modelName, decisionName));
ruleSetNode.setLanguage(RuleSetNode.DMN_LANG);
ruleSetNode.setDecisionModel(() -> dmnDecisionModel);
ruleSetNode.getIoSpecification().addInputMapping("person", "Person");
ruleSetNode.getIoSpecification().addOutputMapping("isAdult", "isAdult");
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
connect(startNode, ruleSetNode);
connect(ruleSetNode, endNode);
process.addNode(startNode);
process.addNode(ruleSetNode);
process.addNode(endNode);
return process;
}
use of org.kie.kogito.dmn.DmnDecisionModel in project kogito-apps by kiegroup.
the class TrafficViolationDmnLimeExplainerTest method getModel.
private PredictionProvider getModel() {
DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(getClass().getResourceAsStream("/dmn/TrafficViolation.dmn")));
assertEquals(1, dmnRuntime.getModels().size());
final String TRAFFIC_VIOLATION_NS = "https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF";
final String TRAFFIC_VIOLATION_NAME = "Traffic Violation";
DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, TRAFFIC_VIOLATION_NS, TRAFFIC_VIOLATION_NAME);
return new DecisionModelWrapper(decisionModel);
}
use of org.kie.kogito.dmn.DmnDecisionModel in project kogito-apps by kiegroup.
the class TrafficViolationDmnPDPExplainerTest method testTrafficViolationDMNExplanation.
@Test
void testTrafficViolationDMNExplanation() throws ExecutionException, InterruptedException, TimeoutException {
DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(getClass().getResourceAsStream("/dmn/TrafficViolation.dmn")));
assertEquals(1, dmnRuntime.getModels().size());
final String TRAFFIC_VIOLATION_NS = "https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF";
final String TRAFFIC_VIOLATION_NAME = "Traffic Violation";
DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, TRAFFIC_VIOLATION_NS, TRAFFIC_VIOLATION_NAME);
PredictionProvider model = new DecisionModelWrapper(decisionModel);
List<PredictionInput> inputs = DmnTestUtils.randomTrafficViolationInputs();
List<PredictionOutput> predictionOutputs = model.predictAsync(inputs).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
List<Prediction> predictions = new ArrayList<>();
for (int i = 0; i < predictionOutputs.size(); i++) {
predictions.add(new SimplePrediction(inputs.get(i), predictionOutputs.get(i)));
}
PartialDependencePlotExplainer partialDependencePlotExplainer = new PartialDependencePlotExplainer();
List<PartialDependenceGraph> pdps = partialDependencePlotExplainer.explainFromPredictions(model, predictions);
AssertionsForClassTypes.assertThat(pdps).isNotNull();
Assertions.assertThat(pdps).hasSize(8);
}
use of org.kie.kogito.dmn.DmnDecisionModel in project kogito-apps by kiegroup.
the class LoanEligibilityDmnCounterfactualExplainerTest method getModel.
private PredictionProvider getModel() {
DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(Objects.requireNonNull(getClass().getResourceAsStream("/dmn/LoanEligibility.dmn"))));
assertEquals(1, dmnRuntime.getModels().size());
final String FRAUD_NS = "https://github.com/kiegroup/kogito-examples/dmn-quarkus-listener-example";
final String FRAUD_NAME = "LoanEligibility";
DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, FRAUD_NS, FRAUD_NAME);
return new DecisionModelWrapper(decisionModel, List.of("Judgement"));
}
Aggregations