List of usage examples for weka.core.converters LibSVMSaver LibSVMSaver
public LibSVMSaver()
From source file:adams.data.io.output.LibSVMSpreadSheetWriter.java
License:Open Source License
/** * Returns an instance of the file loader. * /* w w w . j a v a 2s .c o m*/ * @return the file loader */ @Override protected AbstractFileSaver newSaver() { return new LibSVMSaver(); }
From source file:com.sliit.normalize.NormalizeDataset.java
public boolean saveAsLibSVMFormat() { System.out.println("saveAsLibSVMFormat"); boolean status = false; try {//from w ww . j av a 2s . com String fileName = csvFile.getName(); File svm = new File(csvFile.getParent() + "/" + fileName + "lib_svm"); if (!svm.exists()) { svm.createNewFile(); } LibSVMSaver saver = new LibSVMSaver(); saver.setFile(svm); Instances instances = csv.getDataSet(); saver.setInstances(instances); saver.writeBatch(); status = true; } catch (IOException e) { log.error("Error occurred:" + e.getMessage()); } return status; }
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//from ww w . j a va 2 s . c o m * <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); } } }