use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class DMNDTAnalyser method findGaps.
private static void findGaps(DTAnalysis analysis, DDTATable ddtaTable, int jColIdx, Interval[] currentIntervals, Collection<Integer> activeRules) {
LOG.debug("findGaps jColIdx {}, currentIntervals {}, activeRules {}", jColIdx, currentIntervals, activeRules);
if (jColIdx < ddtaTable.inputCols()) {
findBoundsSorted(ddtaTable, jColIdx, activeRules);
List<Bound> bounds = findBoundsSorted(ddtaTable, jColIdx, activeRules);
Interval domainRange = ddtaTable.getInputs().get(jColIdx).getDomainMinMax();
// from domain start to the 1st bound
if (!domainRange.getLowerBound().equals(bounds.get(0))) {
currentIntervals[jColIdx] = lastDimensionUncoveredInterval(domainRange.getLowerBound(), bounds.get(0), domainRange);
Hyperrectangle gap = new Hyperrectangle(ddtaTable.inputCols(), buildEdgesForHyperrectangleFromIntervals(currentIntervals, jColIdx));
analysis.addGap(gap);
LOG.debug("STARTLEFT GAP DETECTED {}", gap);
}
// cycle rule's interval bounds
List<Interval> activeIntervals = new ArrayList<>();
Bound<?> lastBound = NullBoundImpl.NULL;
for (Bound<?> currentBound : bounds) {
LOG.debug("lastBound {} currentBound {} activeIntervals {} == rules {}", lastBound, currentBound, activeIntervals, activeIntervalsToRules(activeIntervals));
if (activeIntervals.isEmpty() && lastBound != NullBoundImpl.NULL && !Bound.adOrOver(lastBound, currentBound)) {
currentIntervals[jColIdx] = lastDimensionUncoveredInterval(lastBound, currentBound, domainRange);
Hyperrectangle gap = new Hyperrectangle(ddtaTable.inputCols(), buildEdgesForHyperrectangleFromIntervals(currentIntervals, jColIdx));
LOG.debug("GAP DETECTED {}", gap);
analysis.addGap(gap);
}
if (!activeIntervals.isEmpty() && canBeNewCurrInterval(lastBound, currentBound)) {
Interval missingInterval = new Interval(lastBound.isUpperBound() ? Interval.invertBoundary(lastBound.getBoundaryType()) : lastBound.getBoundaryType(), lastBound.getValue(), currentBound.getValue(), currentBound.isLowerBound() ? Interval.invertBoundary(currentBound.getBoundaryType()) : currentBound.getBoundaryType(), 0, 0);
currentIntervals[jColIdx] = missingInterval;
findGaps(analysis, ddtaTable, jColIdx + 1, currentIntervals, activeIntervalsToRules(activeIntervals));
}
if (currentBound.isLowerBound()) {
activeIntervals.add(currentBound.getParent());
} else {
activeIntervals.remove(currentBound.getParent());
}
lastBound = currentBound;
}
// from last Nth bound, to domain end.
if (!lastBound.equals(domainRange.getUpperBound())) {
currentIntervals[jColIdx] = lastDimensionUncoveredInterval(lastBound, domainRange.getUpperBound(), domainRange);
Hyperrectangle gap = new Hyperrectangle(ddtaTable.inputCols(), buildEdgesForHyperrectangleFromIntervals(currentIntervals, jColIdx));
LOG.debug("ENDRIGHT GAP DETECTED {}", gap);
analysis.addGap(gap);
}
// facilitate debugging.
currentIntervals[jColIdx] = null;
}
LOG.debug(".");
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class DTAnalysisMeta method printGaps.
public static Expression printGaps(DTAnalysis analysis) {
Collection<Hyperrectangle> gaps = analysis.getGaps();
MethodCallExpr parseExpression = parseExpression("Arrays.asList()");
for (Hyperrectangle gap : gaps) {
Expression gapAsExpression = hrAsExpression(gap);
parseExpression.addArgument(gapAsExpression);
}
return parseExpression;
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class GapsAndOverlaps1domainOnTableTest method test.
@Test
public void test() {
List<DMNMessage> validate = validator.validate(getReader("GapsAndOverlaps1-domainOnTable.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
DTAnalysis analysis = getAnalysis(validate, "_cd2e0a28-3cc2-456b-90b6-392d9c3574af");
assertThat(analysis.getGaps(), hasSize(11));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("1"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("3"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("4"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("1"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("5"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("7"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("3"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("7"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)))));
assertThat(gaps, hasSize(11));
// Assert GAPs same values
assertThat(analysis.getGaps(), contains(gaps.toArray()));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(1));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(1, 3), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("4"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null))))));
assertThat(overlaps, hasSize(1));
// Assert OVERLAPs same values
assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class GapsOverlapsBooleanTest method test.
@Test
public void test() {
List<DMNMessage> validate = validator.validate(getReader("GapsOverlapsBoolean.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
DTAnalysis analysis = getAnalysis(validate, "_EE34FD37-00D1-47A7-B2F6-CC9BCEF30005");
assertThat(analysis.getGaps(), hasSize(1));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null)))));
assertThat(gaps, hasSize(1));
// Assert GAPS
assertThat(analysis.getGaps(), contains(gaps.toArray()));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(1));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(1, 2), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null))))));
assertThat(overlaps, hasSize(1));
// Assert OVERLAPs same values
assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class MaskTest method test_MaskTest.
@Test
public void test_MaskTest() {
List<DMNMessage> validate = validator.validate(getReader("MaskTest.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
DTAnalysis analysis = getAnalysis(validate, "_BA703D04-803A-44AA-8A31-F5EEDD4FD54E");
assertThat(analysis.getGaps(), hasSize(0));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(1));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(2, 1), new Hyperrectangle(3, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("18"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound("L", RangeBoundary.CLOSED, null), new Bound("M", RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null))))));
assertThat(overlaps, hasSize(1));
// Assert OVERLAPs same values
assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
// MaskedRules count.
assertThat(analysis.getMaskedRules(), hasSize(1));
List<MaskedRule> maskedRules = Arrays.asList(new MaskedRule(1, 2));
assertThat(maskedRules, hasSize(1));
assertThat(analysis.getMaskedRules(), contains(maskedRules.toArray()));
assertTrue("It should contain at least 1 DMNMessage for the MaskedRule", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MASKED_RULE)));
assertTrue("It should not contain DMNMessage for the MisleadingRule", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MISLEADING_RULE)));
}
Aggregations