Skip to content

Instantly share code, notes, and snippets.

@happyrobots
Created February 13, 2011 21:17
Show Gist options
  • Save happyrobots/825140 to your computer and use it in GitHub Desktop.
Save happyrobots/825140 to your computer and use it in GitHub Desktop.
Instances dataSet = // ...
// Showing attribute-type pairs of dataSet
// Analogy with SQL: print field and field type of a table
Enumeration attributes = dataSet.enumerateAttributes();
while (attributes.hasMoreElements()) {
Attribute attribute = (Attribute) attributes.nextElement();
System.out.println(attribute.name() + ": " +
Attribute.typeToString(attribute.type()));
}
// Listing each instance's attribute-value pairs of dataSet
// Analogy with SQL: print all records of a table
Enumeration instances = dataSet.enumerateInstances();
while (instances.hasMoreElements()) {
Instance instance = (Instance) instances.nextElement();
Enumeration instanceAttribute = instance.enumerateAttributes();
while (instanceAttribute.hasMoreElements()) {
Attribute a = (Attribute) instanceAttribute.nextElement();
System.out.println(a.name() + ": " + instance.toString(a));
}
System.out.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment