Search in sources :

Example 1 with DDTAInputEntry

use of org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry in project drools by kiegroup.

the class DMNDTAnalyser method compileTableRules.

private void compileTableRules(DecisionTable dt, DDTATable ddtaTable) {
    for (int jRowIdx = 0; jRowIdx < dt.getRule().size(); jRowIdx++) {
        DecisionRule r = dt.getRule().get(jRowIdx);
        DDTARule ddtaRule = new DDTARule();
        int jColIdx = 0;
        for (UnaryTests ie : r.getInputEntry()) {
            ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(ie.getText(), FEEL.newCompilerContext());
            UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
            UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
            DDTAInputClause ddtaInputClause = ddtaTable.getInputs().get(jColIdx);
            DDTAInputEntry ddtaInputEntry = new DDTAInputEntry(utln.getElements(), toIntervals(utln.getElements(), utln.isNegated(), ddtaInputClause.getDomainMinMax(), ddtaInputClause.getDiscreteValues(), jRowIdx + 1, jColIdx + 1));
            for (Interval interval : ddtaInputEntry.getIntervals()) {
                Interval domainMinMax = ddtaTable.getInputs().get(jColIdx).getDomainMinMax();
                if (!domainMinMax.includes(interval)) {
                    throw new IllegalStateException(MsgUtil.createMessage(Msg.DTANALYSIS_ERROR_RULE_OUTSIDE_DOMAIN, jRowIdx + 1, interval, domainMinMax, jColIdx + 1));
                }
            }
            ddtaRule.getInputEntry().add(ddtaInputEntry);
            jColIdx++;
        }
        for (LiteralExpression oe : r.getOutputEntry()) {
            ProcessedExpression compile = (ProcessedExpression) FEEL.compile(oe.getText(), FEEL.newCompilerContext());
            InterpretedExecutableExpression interpreted = compile.getInterpreted();
            BaseNode outputEntryNode = (BaseNode) interpreted.getASTNode();
            Comparable<?> value = valueFromNode(outputEntryNode, outputClauseVisitor);
            ddtaRule.getOutputEntry().add(value);
            jColIdx++;
        }
        ddtaTable.addRule(ddtaRule);
    }
}
Also used : DDTARule(org.kie.dmn.validation.dtanalysis.model.DDTARule) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ProcessedUnaryTest(org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest) ProcessedExpression(org.kie.dmn.feel.codegen.feel11.ProcessedExpression) UnaryTestInterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression) InterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.InterpretedExecutableExpression) DecisionRule(org.kie.dmn.model.api.DecisionRule) DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry) UnaryTestInterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression) UnaryTestListNode(org.kie.dmn.feel.lang.ast.UnaryTestListNode) DDTAInputClause(org.kie.dmn.validation.dtanalysis.model.DDTAInputClause) UnaryTests(org.kie.dmn.model.api.UnaryTests) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 2 with DDTAInputEntry

use of org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry in project drools by kiegroup.

the class MCDCAnalyser method combinatorialValuesForRule.

private List<Object[]> combinatorialValuesForRule(int ruleIdx, Object[] knownValues, List<List<?>> allEnumValues) {
    List<Object[]> result = new ArrayList<>();
    List<DDTAInputEntry> inputEntry = ddtaTable.getRule().get(ruleIdx).getInputEntry();
    List<List<?>> validEnumValues = new ArrayList<>();
    for (int i = 0; i < inputEntry.size(); i++) {
        List<Object> enumForI = new ArrayList<>();
        if (knownValues[i] == null) {
            DDTAInputEntry ddtaInputEntry = inputEntry.get(i);
            List<?> enumValues = allEnumValues.get(i);
            for (Object object : enumValues) {
                if (ddtaInputEntry.getIntervals().stream().anyMatch(interval -> interval.asRangeIncludes(object))) {
                    enumForI.add(object);
                }
            }
        } else {
            enumForI.add(knownValues[i]);
        }
        validEnumValues.add(enumForI);
    }
    List<List<Object>> combinatorial = new ArrayList<>();
    combinatorial.add(new ArrayList<>());
    for (int i = 0; i < inputEntry.size(); i++) {
        List<List<Object>> combining = new ArrayList<>();
        for (List<Object> existing : combinatorial) {
            for (Object enumForI : validEnumValues.get(i)) {
                List<Object> building = new ArrayList<>(existing);
                building.add(enumForI);
                combining.add(building);
            }
        }
        combinatorial = combining;
    }
    return combinatorial.stream().map(List::toArray).collect(Collectors.toList());
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry)

Example 3 with DDTAInputEntry

use of org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry in project drools by kiegroup.

the class MCDCAnalyser method calculateElseRuleIdx.

private void calculateElseRuleIdx() {
    if (dt.getHitPolicy() == HitPolicy.PRIORITY) {
        // calculate "else" rule if present.
        for (int ruleIdx = ddtaTable.getRule().size() - 1; ruleIdx >= 0 && !elseRuleIdx.isPresent(); ruleIdx--) {
            DDTARule rule = ddtaTable.getRule().get(ruleIdx);
            List<DDTAInputEntry> ie = rule.getInputEntry();
            boolean checkAll = true;
            for (int colIdx = 0; colIdx < ie.size() && checkAll; colIdx++) {
                DDTAInputEntry ieIDX = ie.get(colIdx);
                boolean idIDXsize1 = ieIDX.getIntervals().size() == 1;
                Interval ieIDXint0 = ieIDX.getIntervals().get(0);
                Interval domainMinMax = ddtaTable.getInputs().get(colIdx).getDomainMinMax();
                boolean equals = ieIDXint0.equals(domainMinMax);
                checkAll &= idIDXsize1 && equals;
            }
            if (checkAll) {
                LOG.debug("I believe P table with else rule: {}", ruleIdx + 1);
                elseRuleIdx = Optional.of(ruleIdx);
            }
        }
    }
}
Also used : DDTARule(org.kie.dmn.validation.dtanalysis.model.DDTARule) DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 4 with DDTAInputEntry

use of org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry in project drools by kiegroup.

the class MCDCAnalyser method findValuesForRule.

private Object[] findValuesForRule(int ruleIdx, List<List<?>> allEnumValues) {
    Object[] result = new Object[ddtaTable.getInputs().size()];
    List<DDTAInputEntry> inputEntry = ddtaTable.getRule().get(ruleIdx).getInputEntry();
    for (int i = 0; i < inputEntry.size(); i++) {
        if (result[i] == null) {
            DDTAInputEntry ddtaInputEntry = inputEntry.get(i);
            List<?> enumValues = allEnumValues.get(i);
            for (Object object : enumValues) {
                if (ddtaInputEntry.getIntervals().stream().anyMatch(interval -> interval.asRangeIncludes(object))) {
                    result[i] = object;
                    break;
                }
            }
        }
    }
    return result;
}
Also used : DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry)

Example 5 with DDTAInputEntry

use of org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry in project drools by kiegroup.

the class MCDCAnalyser method findValuesForRule.

private Object[] findValuesForRule(int ruleIdx, Object[] knownValues, List<List<?>> allEnumValues) {
    Object[] result = Arrays.copyOf(knownValues, knownValues.length);
    List<DDTAInputEntry> inputEntry = ddtaTable.getRule().get(ruleIdx).getInputEntry();
    for (int i = 0; i < inputEntry.size(); i++) {
        if (result[i] == null) {
            DDTAInputEntry ddtaInputEntry = inputEntry.get(i);
            List<?> enumValues = allEnumValues.get(i);
            Interval interval0 = ddtaInputEntry.getIntervals().get(0);
            if (interval0.isSingularity()) {
                result[i] = interval0.getLowerBound().getValue();
            } else if (interval0.getLowerBound().getBoundaryType() == RangeBoundary.CLOSED && interval0.getLowerBound().getValue() != Interval.NEG_INF) {
                result[i] = interval0.getLowerBound().getValue();
            } else if (interval0.getUpperBound().getBoundaryType() == RangeBoundary.CLOSED && interval0.getUpperBound().getValue() != Interval.POS_INF) {
                result[i] = interval0.getUpperBound().getValue();
            }
            if (!enumValues.contains(result[i])) {
                // invalidating if the chosen enum is not part of the plausible ones
                result[i] = null;
            }
            if (result[i] == null) {
                for (Object object : enumValues) {
                    if (ddtaInputEntry.getIntervals().stream().anyMatch(interval -> interval.asRangeIncludes(object))) {
                        result[i] = object;
                        break;
                    }
                }
            }
        }
    }
    return result;
}
Also used : DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Aggregations

DDTAInputEntry (org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry)5 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)3 DDTARule (org.kie.dmn.validation.dtanalysis.model.DDTARule)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProcessedExpression (org.kie.dmn.feel.codegen.feel11.ProcessedExpression)1 ProcessedUnaryTest (org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest)1 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)1 UnaryTestListNode (org.kie.dmn.feel.lang.ast.UnaryTestListNode)1 InterpretedExecutableExpression (org.kie.dmn.feel.lang.impl.InterpretedExecutableExpression)1 UnaryTestInterpretedExecutableExpression (org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression)1 DecisionRule (org.kie.dmn.model.api.DecisionRule)1 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)1 UnaryTests (org.kie.dmn.model.api.UnaryTests)1 DDTAInputClause (org.kie.dmn.validation.dtanalysis.model.DDTAInputClause)1