Skip to content

Instantly share code, notes, and snippets.

@muuki88
Created January 7, 2012 15:44
Show Gist options
  • Save muuki88/1575081 to your computer and use it in GitHub Desktop.
Save muuki88/1575081 to your computer and use it in GitHub Desktop.
Load Instances via PatientService and store into XML (XRFF)
import weka.core.converters.Loader;
import weka.core.converters.Saver;
import weka.core.converters.ArffLoader;
import weka.core.converters.XrffSaver;
IPatientService ps = ... //get IPatientService
Data d = ... //get Data entity
Path pathToArff = locateFile(Data d);
Path pathToXML = ... //get it!
try(InputStream in = Files.newInputStream(pathToArff); OutputStream out = Files.newOutputStream(pathToXML) {
Loader loader = new ArffLoader();
loader.setSource(Files.newInputStream(pathToArff));
Instances dataset = loader.getDataSet();
Saver saver = new XrffSaver();
saver.setInstances(dataset);
//This won't work with Weka 3.7.3, fixed in 3.7.5. Needs update
//saver.setDestination(out);
//As a workaround use
saver.setDestination(pathToXML.toFile());
saver.writeBatch();
} catch(IOException e) {
//handle it!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment