Search in sources :

Example 1 with CSVLoader

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();
    }
}
Also used : Instances(weka.core.Instances) CSVLoader(weka.core.converters.CSVLoader) ArffSaver(weka.core.converters.ArffSaver) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Instances (weka.core.Instances)1 ArffSaver (weka.core.converters.ArffSaver)1 CSVLoader (weka.core.converters.CSVLoader)1