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);
}
}
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());
}
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);
}
}
}
}
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;
}
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;
}
Aggregations