Search in sources :

Example 26 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class DecisionServiceImpl method evaluate.

@Override
public ExtendedDataContext evaluate(LocalId decisionId, DataContext inputContext) {
    LocalDecisionId localDecisionId;
    LocalDecisionServiceId decisionServiceId = null;
    if (decisionId instanceof LocalDecisionId) {
        localDecisionId = (LocalDecisionId) decisionId;
    } else if (decisionId instanceof LocalDecisionServiceId) {
        decisionServiceId = (LocalDecisionServiceId) decisionId;
        localDecisionId = (LocalDecisionId) decisionServiceId.decisionId();
    } else {
        // LocalDecisionId.parse(decisionId);
        throw new IllegalArgumentException("Not a valid decision id " + decisionId.toLocalId().asLocalUri());
    }
    DecisionModel decisionModel = decisionModels.getDecisionModel(localDecisionId.namespace(), localDecisionId.name());
    ExtendedDataContext extendedDataContext = inputContext.as(ExtendedDataContext.class);
    Map<String, Object> map = extendedDataContext.data().as(MapDataContext.class).toMap();
    DMNContext ctx = DMNJSONUtils.ctx(decisionModel, map);
    MetaDataContext inputMeta = extendedDataContext.meta();
    MapDataContext mapInputMeta = MapDataContext.from(inputMeta);
    DMNMetadata metadata = ctx.getMetadata();
    for (Map.Entry<String, Object> kv : mapInputMeta.toMap().entrySet()) {
        metadata.set(kv.getKey(), kv.getValue());
    }
    DMNResult dmnResult;
    if (decisionServiceId == null) {
        dmnResult = decisionModel.evaluateAll(ctx);
    } else {
        dmnResult = decisionModel.evaluateDecisionService(ctx, decisionServiceId.serviceId());
    }
    MapDataContext meta = MapDataContext.of(dmnResult.getContext().getMetadata().asMap());
    MapDataContext data = MapDataContext.of(dmnResult.getContext().getAll());
    return ExtendedDataContext.of(meta, data);
}
Also used : LocalDecisionId(org.kie.kogito.incubation.decisions.LocalDecisionId) DMNResult(org.kie.dmn.api.core.DMNResult) MapDataContext(org.kie.kogito.incubation.common.MapDataContext) MetaDataContext(org.kie.kogito.incubation.common.MetaDataContext) ExtendedDataContext(org.kie.kogito.incubation.common.ExtendedDataContext) DMNContext(org.kie.dmn.api.core.DMNContext) LocalDecisionServiceId(org.kie.kogito.incubation.decisions.LocalDecisionServiceId) DecisionModel(org.kie.kogito.decision.DecisionModel) DMNMetadata(org.kie.dmn.api.core.DMNMetadata) Map(java.util.Map)

Example 27 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class EventDrivenDecisionController method processRequest.

private EvaluationContext processRequest(EvaluationContext ctx) {
    if (!ctx.isValidRequest()) {
        ctx.setResponseError(DecisionResponseError.BAD_REQUEST);
        return ctx;
    }
    Optional<DecisionModel> optDecisionModel = getDecisionModel(ctx.getRequestModelNamespace(), ctx.getRequestModelName());
    if (!optDecisionModel.isPresent()) {
        ctx.setResponseError(DecisionResponseError.MODEL_NOT_FOUND);
        return ctx;
    }
    DecisionModel model = optDecisionModel.get();
    DMNContext context = DMNJSONUtils.ctx(model, ctx.getRequestData());
    DMNResult apiResult = ctx.isEvaluateDecisionServiceRequest() ? model.evaluateDecisionService(context, ctx.getRequestDecisionServiceToEvaluate()) : model.evaluateAll(context);
    ctx.setResponseDmnResult(apiResult);
    return ctx;
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) KogitoDMNResult(org.kie.kogito.dmn.rest.KogitoDMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DecisionModel(org.kie.kogito.decision.DecisionModel)

Example 28 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class DecisionExplainabilityResourceExecutor method processRequest.

@Override
public PredictOutput processRequest(Application application, PredictInput predictInput) {
    DecisionModel decisionModel = getDecisionModel(application.get(DecisionModels.class), predictInput.getModelIdentifier());
    DMNContext dmnContext = decisionModel.newContext(convertDMNInput(predictInput));
    dmnContext.getMetadata().set(SKIP_TRACING, true);
    dmnContext.getMetadata().set(SKIP_MONITORING, true);
    return convertDMNOutput(decisionModel.evaluateAll(dmnContext), predictInput);
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) DecisionModel(org.kie.kogito.decision.DecisionModel) DecisionModels(org.kie.kogito.decision.DecisionModels)

Aggregations

DecisionModel (org.kie.kogito.decision.DecisionModel)28 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)22 DmnDecisionModel (org.kie.kogito.dmn.DmnDecisionModel)22 InputStreamReader (java.io.InputStreamReader)15 Test (org.junit.jupiter.api.Test)14 ArrayList (java.util.ArrayList)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 DMNContext (org.kie.dmn.api.core.DMNContext)6 EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)6 HashMap (java.util.HashMap)5 DMNResult (org.kie.dmn.api.core.DMNResult)5 PartialDependencePlotExplainer (org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer)4 PartialDependenceGraph (org.kie.kogito.explainability.model.PartialDependenceGraph)4 Random (java.util.Random)3 LimeConfig (org.kie.kogito.explainability.local.lime.LimeConfig)3 LimeExplainer (org.kie.kogito.explainability.local.lime.LimeExplainer)3