Skip to content

Commit 8ffe07f

Browse files
committed
RUL-96: Conditions printed in the order they had been added to the rule.
1 parent 9bfa1ac commit 8ffe07f

16 files changed

+119
-82
lines changed

adaa.analytics.rules/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ codeQuality {
2727
}
2828

2929
sourceCompatibility = 1.8
30-
version = '1.7.19'
30+
version = '1.7.20'
3131

3232

3333
jar {

adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/representation/CompoundCondition.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ protected void internalEvaluate(ExampleSet set, Set<Integer> outIndices) {
106106
*/
107107
public String toString() {
108108
String s = "";
109-
String op = operator == LogicalOperator.ALTERNATIVE ? " OR " : " AND ";
110-
109+
String op = operator == LogicalOperator.ALTERNATIVE ? " OR " : " AND ";
110+
111+
/*
111112
Map<String, ElementaryCondition> shortened = new HashMap<String, ElementaryCondition>();
112113
Set<ConditionBase> unshortened = new LinkedHashSet<>();
113114
@@ -135,8 +136,37 @@ public String toString() {
135136
// add shortened conditions
136137
for (ConditionBase cnd : shortened.values()) {
137138
s += cnd.toString() + op;
139+
}*/
140+
141+
List<ConditionBase> outConditions = new ArrayList<>();
142+
Map<String, Integer> attr2position = new HashMap<>();
143+
144+
for (ConditionBase cnd : subconditions) {
145+
if (cnd instanceof ElementaryCondition && cnd.isPrunable()) {
146+
ElementaryCondition ec = (ElementaryCondition)cnd;
147+
String attr = ec.getAttribute();
148+
149+
if (attr2position.containsKey(attr)) {
150+
// if condition built upon current attribute exists - replace with intersection
151+
int pos = attr2position.get(attr);
152+
ElementaryCondition parent = (ElementaryCondition) outConditions.get(pos);
153+
outConditions.set(pos, parent.intersect(ec));
154+
} else {
155+
// otherwise - add condition and save positon of the attribute
156+
attr2position.put(attr, outConditions.size());
157+
outConditions.add(ec);
158+
}
159+
} else {
160+
// if not elementary condition - add it as it is
161+
outConditions.add(cnd);
162+
}
138163
}
139-
164+
165+
for (ConditionBase cnd : outConditions) {
166+
s += cnd.toString() + op;
167+
}
168+
169+
140170
s = s.substring(0, Math.max(0, s.length() - op.length()));
141171

142172
if (type == Type.FORCED) {

adaa.analytics.rules/test/resources/reports/ClassificationExpertSnCTest/test_seismic-bumps.guided-c2, gimpuls_750 extended.seismic-bumps-train-minimal.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
Rules
44
IF [gimpuls = (-inf, 1350.50)] THEN class = {0}
5-
IF goenergy = <-32.50, inf) AND gimpuls = (-inf, 2784) AND goimpuls = <-39, 111) AND nbumps = (-inf, 5.50) THEN class = {0}
6-
IF [gimpuls = <408.50, inf)] AND ghazard = {a} AND goenergy = (-inf, 94.50) AND maxenergy = (-inf, 6500) AND genergy = <35165, 294530) AND senergy = (-inf, 8750) AND nbumps3 = (-inf, 2.50) THEN class = {1}
5+
IF gimpuls = (-inf, 2784) AND nbumps = (-inf, 5.50) AND goimpuls = <-39, 111) AND goenergy = <-32.50, inf) THEN class = {0}
6+
IF [gimpuls = <408.50, inf)] AND genergy = <35165, 294530) AND goenergy = (-inf, 94.50) AND ghazard = {a} AND senergy = (-inf, 8750) AND nbumps3 = (-inf, 2.50) AND maxenergy = (-inf, 6500) THEN class = {1}

adaa.analytics.rules/test/resources/reports/ClassificationExpertSnCTest/test_seismic-bumps.guided-c3, gimpuls_genergy_senergy.seismic-bumps-train-minimal.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Rules
44
IF [gimpuls = (-inf, 1350.50)] AND [senergy = (-inf, 5750)] AND nbumps = (-inf, 1.50) THEN class = {0}
5-
IF [gimpuls = (-inf, 1350.50)] AND [senergy = (-inf, 5750)] AND goenergy = <-73.50, inf) AND nbumps = (-inf, 2.50) THEN class = {0}
6-
IF [gimpuls = (-inf, 1350.50)] AND [genergy = (-inf, 122140)] AND goenergy = <-73.50, inf) AND nbumps = (-inf, 5.50) THEN class = {0}
5+
IF [gimpuls = (-inf, 1350.50)] AND [senergy = (-inf, 5750)] AND nbumps = (-inf, 2.50) AND goenergy = <-73.50, inf) THEN class = {0}
6+
IF [gimpuls = (-inf, 1350.50)] AND [genergy = (-inf, 122140)] AND nbumps = (-inf, 5.50) AND goenergy = <-73.50, inf) THEN class = {0}
77
IF [gimpuls = (-inf, 2784)] AND [senergy = (-inf, 5750)] AND goenergy = <-73.50, inf) AND goimpuls = (-inf, 107.50) THEN class = {0}
8-
IF [genergy = <18890, inf)] AND [senergy = <950, inf)] AND ghazard = {a} AND goenergy = (-inf, 12) AND maxenergy = (-inf, 6500) AND gimpuls = (-inf, 1845.50) AND goimpuls = (-inf, 10.50) AND shift = {W} AND nbumps3 = <0.50, inf) THEN class = {1}
8+
IF [genergy = <18890, inf)] AND [senergy = <950, inf)] AND goimpuls = (-inf, 10.50) AND maxenergy = (-inf, 6500) AND shift = {W} AND goenergy = (-inf, 12) AND gimpuls = (-inf, 1845.50) AND nbumps3 = <0.50, inf) AND ghazard = {a} THEN class = {1}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22

33
Rules
4-
IF [seismic = {a}] AND goenergy = <-73.50, inf) AND nbumps3 = (-inf, 0.50) THEN class = {0}
5-
IF [seismic = {a}] AND goenergy = <-73.50, inf) AND nbumps = (-inf, 1.50) THEN class = {0}
4+
IF [seismic = {a}] AND nbumps3 = (-inf, 0.50) AND goenergy = <-73.50, inf) THEN class = {0}
5+
IF [seismic = {a}] AND nbumps = (-inf, 1.50) AND goenergy = <-73.50, inf) THEN class = {0}
66
IF [seismic = {a}] AND goenergy = <-37.50, inf) AND goimpuls = <-39, inf) THEN class = {0}
77
IF [ghazard = {b}] THEN class = {0}
88
IF [seismoacoustic = {a}] AND genergy = (-inf, 18890) THEN class = {0}
99
IF [seismoacoustic = {a}] AND gimpuls = (-inf, 1350.50) AND goimpuls = <-39.50, inf) THEN class = {0}
10-
IF genergy = (-inf, 25125) AND nbumps = (-inf, 1.50) THEN class = {0}
11-
IF goenergy = <-73.50, inf) AND gimpuls = (-inf, 1350.50) AND nbumps = (-inf, 2.50) THEN class = {0}
12-
IF [seismic = {b}] AND ghazard = {a} AND goenergy = <-39, 94.50) AND maxenergy = (-inf, 45000) AND genergy = <25125, inf) AND goimpuls = <-15.50, inf) THEN class = {1}
10+
IF nbumps = (-inf, 1.50) AND genergy = (-inf, 25125) THEN class = {0}
11+
IF gimpuls = (-inf, 1350.50) AND nbumps = (-inf, 2.50) AND goenergy = <-73.50, inf) THEN class = {0}
12+
IF [seismic = {b}] AND genergy = <25125, inf) AND goenergy = <-39, 94.50) AND goimpuls = <-15.50, inf) AND ghazard = {a} AND maxenergy = (-inf, 45000) THEN class = {1}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22

33
Rules
4-
IF goenergy = <-73.50, inf) AND nbumps3 = (-inf, 0.50) AND nbumps4 = (-inf, 1.50) THEN class = {0}
4+
IF nbumps4 = (-inf, 1.50) AND nbumps3 = (-inf, 0.50) AND goenergy = <-73.50, inf) THEN class = {0}
55
IF goenergy = <-73.50, inf) AND nbumps = (-inf, 1.50) THEN class = {0}
6-
IF goenergy = <-73.50, inf) AND genergy = (-inf, 117615) AND nbumps2 = (-inf, 1.50) THEN class = {0}
6+
IF genergy = (-inf, 117615) AND goenergy = <-73.50, inf) AND nbumps2 = (-inf, 1.50) THEN class = {0}
77
IF nbumps = (-inf, 5.50) THEN class = {0}
8-
IF goenergy = (-inf, 9) AND maxenergy = (-inf, 6500) AND genergy = <18890, 314675) AND shift = {W} AND nbumps3 = <0.50, inf) THEN class = {1}
8+
IF genergy = <18890, 314675) AND goenergy = (-inf, 9) AND nbumps3 = <0.50, inf) AND shift = {W} AND maxenergy = (-inf, 6500) THEN class = {1}

adaa.analytics.rules/test/resources/reports/ClassificationExpertSnCTest/test_seismic-bumps.guided-c6, +seismoacoustic +shift +genergy +gimpuls +genergy +goimpuls +ghazard.seismic-bumps-train-minimal.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
Rules
44
IF gimpuls = (-inf, 1350.50) THEN class = {0}
5-
IF goenergy = <-32.50, inf) AND gimpuls = (-inf, 2784) AND goimpuls = <-39, 111) THEN class = {0}
6-
IF ghazard = {a} AND goenergy = <-38.50, 9) AND gimpuls = <263, 1878) AND genergy = <24830, 314675) AND goimpuls = (-inf, 17.50) AND shift = {W} THEN class = {1}
5+
IF gimpuls = (-inf, 2784) AND goimpuls = <-39, 111) AND goenergy = <-32.50, inf) THEN class = {0}
6+
IF goenergy = <-38.50, 9) AND genergy = <24830, 314675) AND goimpuls = (-inf, 17.50) AND ghazard = {a} AND gimpuls = <263, 1878) AND shift = {W} THEN class = {1}
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11

22

33
Rules
4-
IF Payment Method = {credit card} AND Age = (-inf, 30.50) THEN Future Customer = {yes}
5-
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 32.50) THEN Future Customer = {yes}
6-
IF Gender = {male} AND Age = <18.50, 21.50) THEN Future Customer = {yes}
7-
IF Gender = {male} AND Age = <17.50, 22.50) THEN Future Customer = {yes}
8-
IF Gender = {male} AND Age = (-inf, 25.50) THEN Future Customer = {yes}
9-
IF Gender = {male} AND Age = <18.50, 27.50) THEN Future Customer = {yes}
10-
IF Gender = {male} AND Age = <20.50, 30.50) THEN Future Customer = {yes}
11-
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 34.50) THEN Future Customer = {yes}
12-
IF Gender = {male} AND Age = (-inf, 34.50) THEN Future Customer = {yes}
13-
IF Gender = {male} AND Age = (-inf, 35.50) THEN Future Customer = {yes}
14-
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 36.50) THEN Future Customer = {yes}
15-
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 72.50) THEN Future Customer = {yes}
16-
IF Gender = {female} AND Age = <34.50, inf) THEN Future Customer = {no}
17-
IF Payment Method = {cash} AND Age = <37.50, inf) THEN Future Customer = {no}
4+
IF Age = <34.50, inf) AND Gender = {female} THEN Future Customer = {no}
5+
IF Age = <37.50, inf) AND Payment Method = {cash} THEN Future Customer = {no}
186
IF Age = <72.50, inf) THEN Future Customer = {no}
19-
IF Payment Method = {cheque} AND Age = <54.50, 71.50) THEN Future Customer = {no}
20-
IF Payment Method = {cheque} AND Age = <41.50, 55.50) THEN Future Customer = {no}
21-
IF Gender = {female} AND Age = <32.50, inf) THEN Future Customer = {no}
7+
IF Age = <54.50, 71.50) AND Payment Method = {cheque} THEN Future Customer = {no}
8+
IF Age = <41.50, 55.50) AND Payment Method = {cheque} THEN Future Customer = {no}
9+
IF Age = <32.50, inf) AND Gender = {female} THEN Future Customer = {no}
2210
IF Age = <31.50, 42.50) THEN Future Customer = {no}
2311
IF Gender = {female} AND Age = <27.50, inf) THEN Future Customer = {no}
2412
IF Gender = {female} AND Age = <24.50, inf) THEN Future Customer = {no}
2513
IF Gender = {female} AND Age = <19.50, inf) THEN Future Customer = {no}
14+
IF Gender = {female} THEN Future Customer = {no}
15+
IF Age = (-inf, 30.50) AND Payment Method = {credit card} THEN Future Customer = {yes}
16+
IF Age = (-inf, 32.50) AND Payment Method = {credit card} AND Gender = {male} THEN Future Customer = {yes}
17+
IF Age = <18.50, 21.50) AND Gender = {male} THEN Future Customer = {yes}
18+
IF Age = <17.50, 22.50) AND Gender = {male} THEN Future Customer = {yes}
19+
IF Age = (-inf, 25.50) AND Gender = {male} THEN Future Customer = {yes}
20+
IF Age = <18.50, 27.50) AND Gender = {male} THEN Future Customer = {yes}
21+
IF Age = <20.50, 30.50) AND Gender = {male} THEN Future Customer = {yes}
22+
IF Age = (-inf, 34.50) AND Payment Method = {credit card} AND Gender = {male} THEN Future Customer = {yes}
23+
IF Age = (-inf, 34.50) AND Gender = {male} THEN Future Customer = {yes}
24+
IF Age = (-inf, 35.50) AND Gender = {male} THEN Future Customer = {yes}
25+
IF Age = (-inf, 36.50) AND Gender = {male} AND Payment Method = {credit card} THEN Future Customer = {yes}
26+
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 72.50) THEN Future Customer = {yes}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11

22

33
Rules
4-
IF Payment Method = {credit card} AND Age = (-inf, 32.50) THEN Future Customer = {yes}
5-
IF Age = (-inf, 34.50) THEN Future Customer = {yes}
6-
IF Gender = {male} AND Age = (-inf, 36.50) THEN Future Customer = {yes}
7-
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 72.50) THEN Future Customer = {yes}
8-
IF Gender = {female} AND Age = <34.50, inf) THEN Future Customer = {no}
4+
IF Age = <34.50, inf) AND Gender = {female} THEN Future Customer = {no}
95
IF Age = <34.50, inf) THEN Future Customer = {no}
10-
IF Gender = {female} AND Age = <32.50, inf) THEN Future Customer = {no}
6+
IF Age = <32.50, inf) AND Gender = {female} THEN Future Customer = {no}
117
IF Gender = {female} AND Age = <28.50, inf) THEN Future Customer = {no}
128
IF Gender = {female} AND Age = <23.50, inf) THEN Future Customer = {no}
139
IF Gender = {female} AND Age = <17.50, inf) THEN Future Customer = {no}
10+
IF Gender = {female} THEN Future Customer = {no}
11+
IF Age = (-inf, 32.50) AND Payment Method = {credit card} THEN Future Customer = {yes}
12+
IF Age = (-inf, 34.50) THEN Future Customer = {yes}
13+
IF Age = (-inf, 36.50) AND Gender = {male} THEN Future Customer = {yes}
14+
IF Gender = {male} AND Payment Method = {credit card} AND Age = (-inf, 72.50) THEN Future Customer = {yes}

adaa.analytics.rules/test/resources/reports/RegressionExpertSnCTest/test_methane.guided-r1, PD=0 or PD=1.methane-train-minimal.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Rules
44
IF [PD = (-inf, 0.50)] AND MM31 = (-inf, 0.22) THEN MM116_pred = {0.40}
55
IF [PD = (-inf, 0.50)] AND PG072 = <1.75, 1.95) AND BA13 = <1074.50, 1075.50) THEN MM116_pred = {0.50}
6-
IF [PD = (-inf, 0.50)] AND MM116 = (-inf, 0.65) AND MM31 = <0.23, 0.28) THEN MM116_pred = {0.50}
6+
IF [PD = (-inf, 0.50)] AND MM31 = <0.23, 0.28) AND MM116 = (-inf, 0.65) THEN MM116_pred = {0.50}
77
IF [PD = <0.50, inf)] AND MM116 = <1.25, inf) THEN MM116_pred = {1.40}
88
IF [PD = <0.50, inf)] AND MM116 = <1.05, inf) THEN MM116_pred = {1.20}
99
IF [PD = <0.50, inf)] AND MM116 = <0.95, inf) THEN MM116_pred = {1.10}
1010
IF MM116 = (-inf, 0.75) AND MM31 = <0.23, inf) THEN MM116_pred = {0.60}
11-
IF MM116 = (-inf, 0.85) AND DMM116 = <-0.05, inf) AND AS038 = (-inf, 2.45) AND MM31 = (-inf, 0.33) THEN MM116_pred = {0.50}
11+
IF MM31 = (-inf, 0.33) AND MM116 = (-inf, 0.85) AND DMM116 = <-0.05, inf) AND AS038 = (-inf, 2.45) THEN MM116_pred = {0.50}
1212
IF PD = (-inf, 0.50) AND MM116 = <0.75, inf) THEN MM116_pred = {0.90}
13-
IF MM116 = (-inf, 0.95) AND MM31 = <0.32, inf) THEN MM116_pred = {0.80}
13+
IF MM31 = <0.32, inf) AND MM116 = (-inf, 0.95) THEN MM116_pred = {0.80}

0 commit comments

Comments
 (0)