Created
February 13, 2011 21:17
-
-
Save happyrobots/825140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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