List of usage examples for weka.core.converters MatlabSaver MatlabSaver
public MatlabSaver()
From source file:adams.data.io.output.MatlabSpreadSheetWriter.java
License:Open Source License
/** * Returns an instance of the file loader. * /*from w w w. j av a 2 s . c o m*/ * @return the file loader */ @Override protected AbstractFileSaver newSaver() { return new MatlabSaver(); }
From source file:gate.plugin.learningframework.data.CorpusRepresentationWeka.java
/** * Export the data. If parms is null then default ARFF format is used. In addition, parms can * contain the parameter -format fmt and additional parameters specific to the format. If format * is/* w w w . j a v a 2 s . com*/ * <ul> * <li> "csv": -F fieldSeparator (default is tab) -M missingValueString (default is ?) -N * (suppress header row, default is no) * <li> " * * @param directory * @param format */ public void export(File directory, String parms) { if (parms == null || parms.isEmpty()) { System.err.println("EXPORTING using ArffSaver"); ArffSaver saver = new ArffSaver(); saver.setInstances(data); File outFile = new File(directory, "data.arff"); try { saver.setFile(outFile); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } try { saver.writeBatch(); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } } else { // first parse the parms to see if we have a -format value Parms ps = new Parms(parms, "f:format:s"); String format = (String) ps.getValueOrElse("format", ""); if (format.equals("csv")) { ps = new Parms(parms, "F:F:s", "M:M:s", "N:N:b"); String fieldSep = gate.util.Strings.unescape((String) ps.getValueOrElse("F", "\\t")); String mv = gate.util.Strings.unescape((String) ps.getValueOrElse("M", "?")); boolean noHeader = (boolean) ps.getValueOrElse("N", true); CSVSaver saver = new CSVSaver(); saver.setInstances(data); File outFile = new File(directory, "data.csv"); try { saver.setFile(outFile); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } try { saver.writeBatch(); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } } else if (format.equals("json")) { File outFile = new File(directory, "data.json"); JSONSaver saver = new JSONSaver(); saver.setInstances(data); try { saver.setFile(outFile); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } try { saver.writeBatch(); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } } else if (format.equals("libsvm")) { File outFile = new File(directory, "data.libsvm"); LibSVMSaver saver = new LibSVMSaver(); saver.setInstances(data); try { saver.setFile(outFile); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } try { saver.writeBatch(); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } } else if (format.equals("svmlight")) { File outFile = new File(directory, "data.svmlight"); SVMLightSaver saver = new SVMLightSaver(); saver.setInstances(data); try { saver.setFile(outFile); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } try { saver.writeBatch(); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } } else if (format.equals("matlab")) { File outFile = new File(directory, "data.m"); MatlabSaver saver = new MatlabSaver(); saver.setInstances(data); try { saver.setFile(outFile); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } try { saver.writeBatch(); } catch (IOException ex) { throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex); } } else { throw new GateRuntimeException("Unknown format for exporting Weka representation: " + format); } } }