com.github.TKnudsen.ComplexDataObject.model.io.writers.WekaWriterTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
package com.github.TKnudsen.ComplexDataObject.model.io.writers;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataContainer;
import com.github.TKnudsen.ComplexDataObject.data.complexDataObject.ComplexDataObject;
import com.github.TKnudsen.ComplexDataObject.model.tools.WekaConversion;
import weka.core.Instances;
import weka.core.converters.ArffSaver;
/**
*
* Title: WekaWriterTools
*
*
*
* Description: Tools easing the output of Weka-associated data structures.
*
*
*
* Copyright: Copyright (c) 2016
*
*
* @author Juergen Bernard
* @version 1.0
*/
public class WekaWriterTools {
/**
* simple Weka writer routine. Inspired by Weka's tutorial:
* https://weka.wikispaces.com/Save+Instances+to+an+ARFF+File
*
* @param instances
* @param fileName
* @throws IOException
*/
public static void writeToFile(ComplexDataObject object, String fileName) throws IOException {
ComplexDataContainer container = new ComplexDataContainer(Arrays.asList(object));
Instances instances = WekaConversion.getInstances(container);
writeToFile(instances, fileName);
}
/**
* simple Weka writer routine. Inspired by Weka's tutorial:
* https://weka.wikispaces.com/Save+Instances+to+an+ARFF+File
*
* @param instances
* @param fileName
* @throws IOException
*/
public static void writeToFile(List objects, String fileName) throws IOException {
ComplexDataContainer container = new ComplexDataContainer(objects);
Instances instances = WekaConversion.getInstances(container);
writeToFile(instances, fileName);
}
/**
* simple Weka writer routine. Inspired by Weka's tutorial:
* https://weka.wikispaces.com/Save+Instances+to+an+ARFF+File
*
* @param container
* @param fileName
* @throws IOException
*/
public static void writeToFile(ComplexDataContainer container, String fileName) throws IOException {
Instances instances = WekaConversion.getInstances(container);
writeToFile(instances, fileName);
}
/**
* simple Weka writer routine. Inspired by Weka's tutorial:
* https://weka.wikispaces.com/Save+Instances+to+an+ARFF+File
*
* @param instances
* @param fileName
* @throws IOException
*/
public static void writeToFile(Instances instances, String fileName) throws IOException {
ArffSaver saver = new ArffSaver();
saver.setInstances(instances);
saver.setFile(new File(fileName));
saver.writeBatch();
}
}