Created
January 7, 2012 15:44
-
-
Save muuki88/1575081 to your computer and use it in GitHub Desktop.
Load Instances via PatientService and store into XML (XRFF)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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