Search in sources :

Example 11 with DmnDecisionModel

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();
}
Also used : DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNContext(org.kie.dmn.api.core.DMNContext) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionTestUtils.createDMNRuntime(org.kie.kogito.dmn.DecisionTestUtils.createDMNRuntime) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)

Example 12 with DmnDecisionModel

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;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) Variable(org.jbpm.process.core.context.variable.Variable) InputStreamReader(java.io.InputStreamReader) EndNode(org.jbpm.workflow.core.node.EndNode) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) ArrayList(java.util.ArrayList) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 13 with DmnDecisionModel

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 14 with DmnDecisionModel

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);
}
Also used : SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) InputStreamReader(java.io.InputStreamReader) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) Prediction(org.kie.kogito.explainability.model.Prediction) ArrayList(java.util.ArrayList) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) PartialDependencePlotExplainer(org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) PartialDependenceGraph(org.kie.kogito.explainability.model.PartialDependenceGraph) Test(org.junit.jupiter.api.Test)

Example 15 with DmnDecisionModel

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"));
}
Also used : InputStreamReader(java.io.InputStreamReader) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Aggregations

DmnDecisionModel (org.kie.kogito.dmn.DmnDecisionModel)19 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)18 DecisionModel (org.kie.kogito.decision.DecisionModel)18 InputStreamReader (java.io.InputStreamReader)15 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)7 Prediction (org.kie.kogito.explainability.model.Prediction)7 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)7 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)7 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)7 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)7 PartialDependencePlotExplainer (org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer)4 PartialDependenceGraph (org.kie.kogito.explainability.model.PartialDependenceGraph)4 HashMap (java.util.HashMap)3 Random (java.util.Random)3 DMNContext (org.kie.dmn.api.core.DMNContext)3 LimeConfig (org.kie.kogito.explainability.local.lime.LimeConfig)3 LimeExplainer (org.kie.kogito.explainability.local.lime.LimeExplainer)3 DataDistribution (org.kie.kogito.explainability.model.DataDistribution)3 Feature (org.kie.kogito.explainability.model.Feature)3