use of weka.core.converters.CSVLoader in project 490 by pauleibye.
the class MainFrame method createCSVandArff.
// convert our weird arraylist to a sick ARFF file and save it
public void createCSVandArff(FeatureExtractor FE) {
try {
File file = new File("csv.txt");
if (!file.exists()) {
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
for (String s : FE.getFileFeatures()) {
writer.println(s);
}
writer.close();
}
File arff = new File("data.arff");
if (!arff.exists()) {
CSVLoader loader = new CSVLoader();
loader.setSource(file);
Instances data = loader.getDataSet();
ArffSaver saver = new ArffSaver();
saver.setInstances(data);
saver.setFile(arff);
saver.writeBatch();
}
} catch (IOException e) {
System.out.println("Exception Occurred:");
e.printStackTrace();
}
}
Aggregations