9
9
import ucar .nc2 .util .Misc ;
10
10
import java .util .ArrayList ;
11
11
import java .util .List ;
12
+ import java .util .Set ;
13
+
12
14
import ucar .ma2 .*;
13
15
import ucar .nc2 .*;
14
16
15
17
16
18
public class Classifier implements Enhancement {
17
19
18
-
19
20
private String [] AttCat ;
20
21
private List <int []> rules = new ArrayList <>();
21
22
22
23
private static String name = "Classifier" ;
23
-
24
-
24
+ private static final String ATTRIBUTE_NAME = "classify" ;
25
25
26
26
public Classifier () {
27
27
this .AttCat = new String [0 ];
@@ -35,13 +35,12 @@ public Classifier(String[] AttCat) {
35
35
}
36
36
37
37
// Factory method to create a Classifier from a Variable
38
-
39
38
public static Classifier createFromVariable (VariableDS var ) {
40
39
List <Attribute > attributes = var .attributes ().getAttributes ();
41
40
42
41
for (Attribute attribute : attributes ) {
43
42
// check like this, or something else?
44
- if (attribute == var .attributes ().findAttribute (CDM . CLASSIFY )) {
43
+ if (attribute == var .attributes ().findAttribute (ATTRIBUTE_NAME )) {
45
44
String [] sets = attribute .getStringValue ().split (";" );
46
45
for (int i = 0 ; i < sets .length ; i ++) {
47
46
// trim and clean so it's ready
@@ -52,11 +51,8 @@ public static Classifier createFromVariable(VariableDS var) {
52
51
}
53
52
54
53
return new Classifier ();
55
-
56
54
}
57
55
58
-
59
-
60
56
public int [] classifyWithAttributes (Array arr ) {
61
57
int [] classifiedArray = new int [(int ) arr .getSize ()];
62
58
IndexIterator iterArr = arr .getIndexIterator ();
@@ -73,8 +69,6 @@ public int[] classifyWithAttributes(Array arr) {
73
69
return classifiedArray ;
74
70
}
75
71
76
-
77
-
78
72
public int classifyArrayAttribute (double val ) {
79
73
for (int [] rule : rules ) {
80
74
if (val > rule [0 ] && val <= rule [1 ] + Misc .defaultMaxRelativeDiffFloat ) {
@@ -126,9 +120,15 @@ public static int[] stringToIntArray(String str) {
126
120
}
127
121
128
122
public static class Provider implements EnhancementProvider {
123
+
124
+ @ Override
125
+ public String getAttributeName () {
126
+ return ATTRIBUTE_NAME ;
127
+ }
128
+
129
129
@ Override
130
- public boolean appliesTo (Enhance enhance , AttributeContainer attributes , DataType dt ) {
131
- return enhance == Enhance . ApplyClassifier && attributes . findAttribute ( CDM . CLASSIFY ) != null && dt .isNumeric ();
130
+ public boolean appliesTo (Set < Enhance > enhance , DataType dt ) {
131
+ return dt .isNumeric ();
132
132
}
133
133
134
134
@ Override
0 commit comments