1
16 package gate.creole.ml;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21
22 import org.jdom.Element;
23
24 import gate.util.GateException;
25
26
29
30 public class Attribute implements Serializable{
31
32 public Attribute(Element jdomElement) throws GateException {
33 Element anElement = jdomElement.getChild("NAME");
35 if(anElement == null) throw new GateException(
36 "Required element \"NAME\" not present in attribute:\n" +
37 jdomElement.toString() + "!");
38 else name = anElement.getTextTrim();
39
40 anElement = jdomElement.getChild("TYPE");
42 if(anElement == null) throw new GateException(
43 "Required element \"TYPE\" not present in attribute:\n" +
44 jdomElement.toString() + "!");
45 else type = anElement.getTextTrim();
46
47 anElement = jdomElement.getChild("FEATURE");
49 if(anElement != null)feature = anElement.getTextTrim();
50
51 anElement = jdomElement.getChild("POSITION");
53 if(anElement == null) position = 0;
54 else position = Integer.parseInt(anElement.getTextTrim());
55
56 anElement = jdomElement.getChild("WEIGHTING");
58 if (anElement == null) weighting = 1.0;
59 else weighting = Double.parseDouble(anElement.getTextTrim());
60
61 isClass = jdomElement.getChild("CLASS") != null;
63
64 anElement = jdomElement.getChild("VALUES");
66 if(anElement == null) values = null;
67 else{
68 values = new ArrayList();
69 Iterator valuesIter = anElement.getChildren("VALUE").iterator();
70 while(valuesIter.hasNext()){
71 values.add(((Element)valuesIter.next()).getTextTrim());
72 }
73 }
74 }
75
76 public Attribute(){
77 name = null;
78 type =null;
79 feature = null;
80 isClass = false;
81 position = 0;
82 values = null;
83 weighting = 1.0;
84 }
85
86 public String toString(){
87 StringBuffer res = new StringBuffer();
88 res.append("Name: " + name + "\n");
89 res.append("Type: " + type + "\n");
90 res.append("Feature: " + feature + "\n");
91 res.append("Weighting: "+ weighting + "\n");
92 Iterator valIter = values.iterator();
93 while(valIter.hasNext()){
94 res.append(" Value:" + valIter.next().toString() + "\n");
95 }
96 return res.toString();
97 }
98
99 public boolean isClass(){
100 return isClass;
101 }
102
103 public void setName(String name) {
104 this.name = name;
105 }
106
107 public String getName() {
108 return name;
109 }
110
111 public void setType(String type) {
112 this.type = type;
113 }
114
115 public String getType() {
116 return type;
117 }
118
119 public void setFeature(String feature) {
120 this.feature = feature;
121 }
122
123 public String getFeature() {
124 return feature;
125 }
126
127 public void setWeighting(double weighting) {
128 this.weighting = weighting;
129 }
130
131 public double getWeighting() {
132 return weighting;
133 }
134
135 public java.util.List getValues() {
136 return values;
137 }
138
139 public int getPosition() {
140 return position;
141 }
142
143 public void setClass(boolean isClass) {
144 this.isClass = isClass;
145 }
146
147 public void setValues(java.util.List values) {
148 this.values = values;
149 }
150
151 public void setPosition(int position) {
152 this.position = position;
153 }
154
155
160 public int semanticType() {
161 if (feature==null)
165 return BOOLEAN;
166 if (values==null)
167 return NUMERIC;
168 return NOMINAL;
169 }
170
171 public static final int NOMINAL=1;
173 public static final int NUMERIC=2;
174 public static final int BOOLEAN=3;
175
176 boolean isClass = false;
177 private String name;
178 private String type;
179 private String feature;
180 private java.util.List values;
181 private int position;
182 private double weighting;
187 }