23
23
import adaa .analytics .rules .logic .representation .rule .RegressionRule ;
24
24
import adaa .analytics .rules .logic .representation .rule .Rule ;
25
25
import adaa .analytics .rules .logic .representation .rule .SurvivalRule ;
26
- import adaa .analytics .rules .logic .representation .valueset .IValueSet ;
27
- import adaa .analytics .rules .logic .representation .valueset .Interval ;
28
- import adaa .analytics .rules .logic .representation .valueset .SingletonSet ;
29
- import adaa .analytics .rules .logic .representation .valueset .Universum ;
26
+ import adaa .analytics .rules .logic .representation .valueset .*;
30
27
import adaa .analytics .rules .utils .Logger ;
31
28
import org .apache .commons .lang3 .math .NumberUtils ;
32
29
33
30
import java .util .ArrayList ;
31
+ import java .util .Collections ;
34
32
import java .util .List ;
35
33
import java .util .logging .Level ;
36
34
import java .util .regex .Matcher ;
@@ -57,10 +55,7 @@ public static Rule parseRule(String s, IAttributes meta) {
57
55
Pattern pattern = Pattern .compile ("IF\\ s+(?<premise>.+)\\ s+THEN(?<consequence>\\ s+.*|\\ s*)" );
58
56
Matcher matcher = pattern .matcher (s );
59
57
60
- boolean isSurvival = false ;
61
- if (meta .getColumnByRoleUnsafe (SurvivalRule .SURVIVAL_TIME_ROLE ) != null ) {
62
- isSurvival = true ;
63
- }
58
+ boolean isSurvival = (meta .getColumnByRoleUnsafe (SurvivalRule .SURVIVAL_TIME_ROLE ) != null );
64
59
65
60
if (matcher .find ()) {
66
61
String pre = matcher .group ("premise" );
@@ -70,24 +65,28 @@ public static Rule parseRule(String s, IAttributes meta) {
70
65
CompoundCondition premise = parseCompoundCondition (pre , meta );
71
66
72
67
if (con == null || con .trim ().length () == 0 ) {
73
- if (! meta . getLabelUnsafe (). isNumerical () ) {
74
- Logger . log ( "Empty conclusion for nominal label" + " \n " , Level . WARNING );
75
- } else {
76
- consequence = new ElementaryCondition (meta .getLabelUnsafe ().getName (), new SingletonSet (NaN , null ));
68
+ if (isSurvival ) {
69
+ consequence = new ElementaryCondition ( meta . getLabelUnsafe (). getName (), new UndefinedSet () );
70
+ } else if ( meta . getLabelUnsafe (). isNumerical ()) {
71
+ consequence = new ElementaryCondition (meta .getLabelUnsafe ().getName (), new SingletonSet (NaN , null ));
77
72
consequence .setAdjustable (false );
78
- consequence .setDisabled ( false );
73
+ consequence .setDisabled (false );
74
+ } else {
75
+ Logger .log ("Empty conclusion for nominal label" + "\n " , Level .WARNING );
79
76
}
80
77
} else {
81
78
consequence = parseElementaryCondition (con , meta );
82
79
}
83
80
84
81
if (premise != null && consequence != null ) {
85
82
86
- rule = meta .getLabelUnsafe ().isNominal ()
87
- ? new ClassificationRule (premise , consequence )
88
- : (isSurvival
89
- ? new SurvivalRule (premise , consequence )
90
- : new RegressionRule (premise , consequence ));
83
+ if (isSurvival ) {
84
+ rule = new SurvivalRule (premise , consequence );
85
+ } else {
86
+ rule = meta .getLabelUnsafe ().isNominal ()
87
+ ? new ClassificationRule (premise , consequence )
88
+ : new RegressionRule (premise , consequence );
89
+ }
91
90
}
92
91
}
93
92
@@ -158,9 +157,11 @@ public static ElementaryCondition parseElementaryCondition(String s, IAttributes
158
157
}
159
158
160
159
IValueSet valueSet = null ;
160
+ IAttribute attributeMeta = meta .get (attribute );
161
+
162
+ boolean isSurvival = (meta .getColumnByRole (SurvivalRule .SURVIVAL_TIME_ROLE ) != null ) && (meta .getLabel () == attributeMeta );
161
163
162
- IAttribute attributeMeta = meta .get (attribute );
163
- if (attributeMeta == null ) {
164
+ if (attributeMeta == null ) {
164
165
Logger .log ("Attribute <" + attribute + "> not found" + "\n " , Level .WARNING );
165
166
return null ;
166
167
}
@@ -176,13 +177,19 @@ public static ElementaryCondition parseElementaryCondition(String s, IAttributes
176
177
matcher = regex .matcher (valueString );
177
178
if (matcher .find ()) {
178
179
String value = matcher .group ("discrete" );
179
- List <String > mapping = new ArrayList <String >(attributeMeta .getMapping ().getValues ());
180
- double v = mapping .indexOf (value );
181
- if (v == -1 ) {
182
- Logger .log ("Invalid value <" + value + "> of the nominal attribute <" + attribute + ">" + "\n " , Level .WARNING );
183
- return null ;
184
- }
185
- valueSet = new SingletonSet (v , mapping );
180
+
181
+ if (value .equals ("NaN" ) && isSurvival ) {
182
+ valueSet = new UndefinedSet ();
183
+ } else {
184
+
185
+ List <String > mapping = new ArrayList <String >(attributeMeta .getMapping ().getValues ());
186
+ double v = mapping .indexOf (value );
187
+ if (v == -1 ) {
188
+ Logger .log ("Invalid value <" + value + "> of the nominal attribute <" + attribute + ">" + "\n " , Level .WARNING );
189
+ return null ;
190
+ }
191
+ valueSet = new SingletonSet (v , mapping );
192
+ }
186
193
187
194
}
188
195
} else if (attributeMeta .isNumerical ()) {
@@ -191,8 +198,11 @@ public static ElementaryCondition parseElementaryCondition(String s, IAttributes
191
198
//
192
199
if (matcher .find ()) {
193
200
String value = matcher .group ("discrete" );
194
- double v = value .equals ("NaN" ) ? Double .NaN : Double .parseDouble (value );
195
- valueSet = new SingletonSet (v , null );
201
+ if (value .equals ("NaN" )) {
202
+ valueSet = new UndefinedSet ();
203
+ } else {
204
+ valueSet = new SingletonSet (Double .parseDouble (value ), null );
205
+ }
196
206
} else {
197
207
boolean leftClosed = Pattern .compile ("\\ <.+" ).matcher (valueString ).find ();
198
208
boolean rightClosed = Pattern .compile (".+\\ >" ).matcher (valueString ).find ();
0 commit comments