PDA

View Full Version : read arff string into instances?



Christian Seifert
01-11-2008, 02:33 PM
Hi there, I was wondering whether it is possible to read an arff string into an instances object directly in memory? Currently what I am doing is to write out the string into a file and then reading it with via the Instances constructor, like this:

String features = ...; //my arff data
File featureFile = new File("tmp.arff");
if (featureFile.exists()) {
featureFile.delete();
featureFile.createNewFile();
}
FileWriter fw = new FileWriter(featureFile);
fw.write(features);
fw.flush();
fw.close();

Instances unlabeled = new Instances(
new BufferedReader(
new FileReader(featureFile)));


Well this is not very efficient and I am wondering whether there is an easier way...
Thanks-
Christian

Taqua
01-11-2008, 02:58 PM
Use a java.io.StringReader and java.io.StringWriter.

Your code does not contain anything complicated, so replacing the FileReader/Writer with the String version should not cause any troubles, as long as the ARFF data is not too big. The internal buffer-management of the StringWriter tends to allocate large arrays, which can become a problem once you try to work on 30 or 40 MB of data.