Skip to content
Snippets Groups Projects
Commit 91639b42 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add code documentation and some small design things

parent 749f0b2c
No related branches found
No related tags found
No related merge requests found
Showing
with 83 additions and 54 deletions
......@@ -39,6 +39,10 @@ public class RuleIdentifier implements Serializable {
this.decisionName = decisionName;
}
public String getTableName() {
return decisionName != null ? decisionName : decisionKey;
}
@XmlElement
public String getRuleId() {
return ruleId;
......
......@@ -13,7 +13,8 @@ public enum VerifierType {
Equivalent("Checking for synonyms in columns.", EquivalentRules.class),
Overlap("Checking for overlapping rules.", OverlappingRules.class),
Missing("Checking for missing rules.", MissingRules.class),
PartialReduction("Checking for partial reduction of rules (combination).", PartialReductionRules.class);
PartialReduction(
"Checking for partial reduction of rules (combination).", PartialReductionRules.class);
private final Class<? extends AbstractVerifier> verifierClass;
private String description;
......
......@@ -28,7 +28,7 @@ public class EquivalentRules extends AbstractVerifier {
protected void verifyDecision(DmnDecision d) {
if (d.isDecisionTable()) {
for (Type t : ruleMap.getAllTypesFromDecisionKey(d.getKey())) {
// only check strings
// only check strings for equvalent rules (input + output)
if (t.getDataType() == DataType.STRING) {
// ensure expression is not null and not empty
List<Value> values =
......@@ -41,6 +41,7 @@ public class EquivalentRules extends AbstractVerifier {
&& !v.getOrgExpression().isEmpty()
&& !v.getOrgExpression().equals("\"\""))
.collect(Collectors.toList());
// Check all combinations for synonyms, if found -> add both rules to the message
for (int i = 0; i < values.size() - 1; i++) {
for (int u = i + 1; u < values.size(); u++) {
String val1 = values.get(i).getOrgExpression().replace("\"", "");
......@@ -50,7 +51,12 @@ public class EquivalentRules extends AbstractVerifier {
VerificationResult.getBuilder()
.addRule(values.get(i).getRuleIdentifier())
.addRule(values.get(u).getRuleIdentifier())
.withMessage("%s and %s: equal meaning? Are they synonyms?", val1, val2)
.withMessage(
"In rule (%d) string \"%s\" and in rule (%d) string \"%s\": equal meaning? Are they synonyms?",
values.get(i).getRuleIdentifier().getRowNumber(),
val1,
values.get(u).getRuleIdentifier().getRowNumber(),
val2)
.build());
}
}
......
......@@ -89,7 +89,7 @@ public class IdenticalRules extends AbstractVerifier {
.map(c -> c.getRowNumber().toString())
.collect(Collectors.joining(", ")));
sb.append(" in table ");
sb.append(currentRuleIdentifiers.get(0).getDecisionName());
sb.append(currentRuleIdentifiers.get(0).getTableName());
sb.append(" are identical.");
return sb.toString();
}
......
......@@ -4,6 +4,7 @@ import de.unikoblenz.fgbks.dmn.core.models.RuleIdentifier;
import de.unikoblenz.fgbks.dmn.core.models.VerificationResult;
import de.unikoblenz.fgbks.dmn.core.models.VerifierType;
import de.unikoblenz.fgbks.dmn.core.verifier.helper.Boundary;
import de.unikoblenz.fgbks.dmn.core.verifier.helper.DataType;
import de.unikoblenz.fgbks.dmn.core.verifier.helper.Type;
import de.unikoblenz.fgbks.dmn.core.verifier.helper.Value;
import java.util.ArrayList;
......@@ -35,48 +36,50 @@ public class MissingRules extends AbstractVerifier {
int i,
List<RuleIdentifier> currentRuleIdentifiers,
List<Boundary> missingIntervals) {
if (inputs.get(i).getDataType() == DataType.NUMBER) {
List<Value> sortedBounds =
new ArrayList<>(ruleMap.getValuesFromInputType(inputs.get(i), currentRuleIdentifiers));
sortedBounds.sort(Comparator.comparing(Value::getBoundary));
List<Value> sortedBounds =
new ArrayList<>(ruleMap.getValuesFromInputType(inputs.get(i), currentRuleIdentifiers));
sortedBounds.sort(Comparator.comparing(Value::getBoundary));
Value lastBound = null;
for (Value currentBound : sortedBounds) {
if (lastBound == null) {
if (currentBound.getBoundary().getLowerBound() != Double.MIN_VALUE) {
missingIntervals.add(currentBound.getBoundary().getNewBoundaryLower().get());
Value lastBound = null;
for (Value currentBound : sortedBounds) {
if (lastBound == null) {
if (currentBound.getBoundary().getLowerBound() != Double.MIN_VALUE) {
missingIntervals.add(currentBound.getBoundary().getNewBoundaryLower().get());
}
} else {
Optional<Boundary> newBound =
lastBound.getBoundary().getNewBoundaryBetween(currentBound.getBoundary());
newBound.ifPresent(missingIntervals::add);
}
if (lastBound == null
|| !lastBound
.getBoundary()
.isNumberInRange(
currentBound.getBoundary().getUpperBound(),
currentBound.getBoundary().getUpperBoundType())) {
lastBound = currentBound;
}
} else {
Optional<Boundary> newBound =
lastBound.getBoundary().getNewBoundaryBetween(currentBound.getBoundary());
newBound.ifPresent(missingIntervals::add);
}
if (lastBound == null
|| !lastBound
.getBoundary()
.isNumberInRange(
currentBound.getBoundary().getUpperBound(),
currentBound.getBoundary().getUpperBoundType())) {
lastBound = currentBound;
if (lastBound != null) {
if (lastBound.getBoundary().getUpperBound() != Double.MAX_VALUE) {
missingIntervals.add(lastBound.getBoundary().getNewBoundaryUpper().get());
}
}
}
if (lastBound != null) {
if (lastBound.getBoundary().getUpperBound() != Double.MAX_VALUE) {
missingIntervals.add(lastBound.getBoundary().getNewBoundaryUpper().get());
for (Boundary b : missingIntervals) {
addVerification(
VerificationResult.getBuilder()
.addRule(
RuleIdentifier.getBuilder()
.withRowNumber(999)
.withDecision(d)
.withRuleId("a")
.build())
.withMessage("Missing interval: %s", b.toString())
.build());
}
}
for (Boundary b : missingIntervals) {
addVerification(
VerificationResult.getBuilder()
.addRule(
RuleIdentifier.getBuilder()
.withRowNumber(999)
.withDecision(d)
.withRuleId("a")
.build())
.withMessage("Missing interval: %s", b.toString())
.build());
}
}
@Override
......
......@@ -48,7 +48,7 @@ public class OverlappingRules extends AbstractVerifier {
if (lastBound != null) {
boolean isOverlap =
currentBound.getBoundary().isBoundaryOverlapping(lastBound.getBoundary());
if (isOverlap || currentBound.getBoundary().isBoundaryEquals(lastBound.getBoundary())) {
if (isOverlap || ! currentBound.getBoundary().isBoundaryNotInContact(lastBound.getBoundary())) {
currentBounds.add(lastBound);
if (isOverlap) {
foundOverlap = true;
......
......@@ -6,17 +6,14 @@ import org.camunda.bpm.dmn.engine.DmnDecision;
public class PartialReductionRules extends AbstractVerifier {
public PartialReductionRules() {
super(VerifierType.Missing);
super(VerifierType.PartialReduction);
}
@Override
protected void beforeVerifyDecision() {}
@Override
protected void verifyDecision(DmnDecision d) {
}
protected void verifyDecision(DmnDecision d) {}
@Override
protected void afterVerifyDecision() {}
......
......@@ -37,6 +37,7 @@ public class SubsumptionRules extends AbstractVerifier {
boolean hasSubsumption,
Value currentRootSubsumptionElement) {
if (i == inputs.size()) {
// finish, if subsumption was found previously, than add the rules
if (hasSubsumption) {
VerificationResult.Builder vBuilder =
VerificationResult.getBuilder()
......@@ -45,13 +46,20 @@ public class SubsumptionRules extends AbstractVerifier {
addVerification(vBuilder.build());
}
} else {
// get all input values from the current column, and filter with the prev. iteration
List<Value> selectedBounds =
new ArrayList<>(ruleMap.getValuesFromInputType(inputs.get(i), currentRuleIdentifiers));
List<Set<Value>> clusters = new ArrayList<>();
List<Boolean> subsumptions = new ArrayList<>();
List<Value> subsumptionValue = new ArrayList<>();
List<Set<Value>> clusters = new ArrayList<>(); // clusters of subsumptions
List<Boolean> subsumptions =
new ArrayList<>(); // is the value in selectedBounds a subsubmption?
List<Value> subsumptionValue =
new ArrayList<>(); // save the subsumption value of the current cluster
// if previously a rule was found, which has a subsumption, than it must be also the element,
// which subsume the other elements.
// First, build clusters, which contain a subsumption set
if (currentRootSubsumptionElement != null) {
// get the value from the subsumption rule
Value nValue =
ruleMap
.getValuesFromInputType(
......@@ -74,6 +82,8 @@ public class SubsumptionRules extends AbstractVerifier {
subsumptionValue.add(nValue);
}
} else {
// no subsumption was found yet
// --> build all clusters, where one rule subsume other rules
for (Value cb1 : selectedBounds) {
Set<Value> c1 = new HashSet<>();
c1.add(cb1);
......@@ -92,7 +102,7 @@ public class SubsumptionRules extends AbstractVerifier {
}
}
}
// check for subsets, that includes other subsets
// check for subsets, that includes other subsets and remove them
for (int x = 0; x < clusters.size(); x++) {
if (clusters.get(x) != null) {
Set<Value> c1 = clusters.get(x);
......@@ -106,7 +116,7 @@ public class SubsumptionRules extends AbstractVerifier {
}
}
}
// recursively search next row for subsumption with all clusters
for (int x = 0; x < clusters.size(); x++) {
if (clusters.get(x) != null) {
Set<Value> vals = clusters.get(x);
......@@ -126,9 +136,16 @@ public class SubsumptionRules extends AbstractVerifier {
private String getMessageText(
List<RuleIdentifier> currentRuleIdentifiers, Value subsumptionRule) {
StringBuilder sb = new StringBuilder("Rule ");
StringBuilder sb = new StringBuilder();
sb.append("In table ");
sb.append(subsumptionRule.getRuleIdentifier().getTableName());
sb.append(" rule ");
sb.append(subsumptionRule.getRuleIdentifier().getRowNumber());
sb.append(" subsumes the rules ");
sb.append(" subsumes the rule");
if (currentRuleIdentifiers.size() > 2) {
sb.append("s");
}
sb.append(" ");
sb.append(
currentRuleIdentifiers
.stream()
......
......@@ -28,7 +28,8 @@ html, body {
}
.highlight {
background-color: red;
background-color: darkred;
color:white;
}
.dmn-button {
......@@ -83,4 +84,4 @@ html, body {
.editor-tabs .tab:hover {
border-bottom: solid 3px #79818d;
margin-bottom: 0;
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment