* @param att the JSON object to turn into an Attribute
* @param classAtt for storing whether the attribute is the class attribute
* @return the Attribute, null in case of an error
*/
protected static Attribute toAttribute(JSONNode att, boolean[] classAtt) {
Attribute result;
String name;
String type;
String dateformat;
JSONNode labels;
ArrayList<String> values;
int i;
double weight;
name = (String) att.getChild(NAME).getValue("noname");
type = (String) att.getChild(TYPE).getValue("");
weight = (Double) att.getChild(WEIGHT).getValue(new Double(1.0));
if (type.equals(Attribute.typeToString(Attribute.NUMERIC))) {
result = new Attribute(name);
}
else if (type.equals(Attribute.typeToString(Attribute.NOMINAL))) {
labels = att.getChild(LABELS);
values = new ArrayList<String>();
for (i = 0; i < labels.getChildCount(); i++)
values.add((String)((JSONNode) labels.getChildAt(i)).getValue());
result = new Attribute(name, values);
}
else if (type.equals(Attribute.typeToString(Attribute.DATE))) {
dateformat = (String) att.getChild(TYPE).getValue("yyyy-MM-dd'T'HH:mm:ss");
result = new Attribute(name, dateformat);
}
else if (type.equals(Attribute.typeToString(Attribute.STRING))) {
result = new Attribute(name, (ArrayList<String>) null);
}
else {
System.err.println("Unhandled attribute type '" + type + "'!");
return null;
}
result.setWeight(weight);
return result;
}