/** * Saves the data to the specified file. * * @param file the file to save the data to * @param saver the saver to use, determines it automatically if null */ public void save(File file, AbstractFileSaver saver) { if (saver == null) saver = ConverterUtils.getSaverForFile(file); try { log(null, "Saving: " + file); saver.setInstances(m_Data); if ((saver.retrieveFile() == null) || !saver.retrieveFile().equals(file)) saver.setFile(file); saver.writeBatch(); m_CurrentFile = file; log(null, "Saved successfully: " + file); } catch (Exception e) { handleException(null, "Failed to save data to '" + file + "':", e); JOptionPane.showMessageDialog( this, "Failed to save dataset to '" + file + "':\n" + e, "Error saving", JOptionPane.ERROR_MESSAGE); } updateMenu(); }
/** * Gets all the file extensions used for this type of file * * @return the file extensions */ @Override public String[] getFileExtensions() { return new String[] { getFileExtension() }; }
/** * Gets the current settings of the Saver object. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result; result = new Vector<String>(); for (String s : Option .getOptionsForHierarchy(this, AbstractFileSaver.class)) { result.add(s); } if (m_outputFile != null) { result.add("-o"); result.add("" + m_outputFile); } if (getInstances() != null) { result.add("-i"); result.add("" + getInstances().relationName()); } return result.toArray(new String[result.size()]); }
@Override public void run() { try { m_Log.statusMessage("Saving to file..."); saver.setInstances(inst); saver.writeBatch(); m_Log.statusMessage("OK"); } catch (Exception ex) { ex.printStackTrace(); m_Log.logMessage(ex.getMessage()); } m_IOThread = null; } };
String[] tmpOptions = options.clone(); if (Utils.getFlag('h', tmpOptions)) { System.err.println("\nHelp requested\n" + makeOptionStr(saver)); return; saver.setOptions(options); } catch (Exception ex) { System.err.println(makeOptionStr(saver)); System.exit(1); saver.writeBatch(); } catch (Exception ex) { ex.printStackTrace();
saver = new ArffSaver(); saver.setFile(new File(m_sFile)); saver.setInstances(m_Instances); saver.writeBatch();
resetOptions(); File input = new File(inputString); loader.setFile(input); setInstances(loader.getDataSet()); } catch (Exception ex) { ex.printStackTrace(); for (String ext : getFileExtensions()) { if (outputString.endsWith(ext)) { validExt = true; setFile(output); } catch (Exception ex) { throw new IOException("Cannot create output file (Reason: "
((weka.core.converters.AbstractFileSaver) saver).retrieveFile(); prefix = ((weka.core.converters.AbstractFileSaver) saver).filePrefix(); dir = ((weka.core.converters.AbstractFileSaver) saver).retrieveDir();
/** * Set the environment variables to use. * * @param env the environment variables to use */ @Override public void setEnvironment(Environment env) { m_env = env; if (m_outputFile != null) { try { // try and resolve any new environment variables setFile(m_outputFile); } catch (IOException ex) { // we won't complain about it here... } } }
/** * Saves the data to the specified file. * * @param file the file to save the data to * @param saver the saver to use, determines it automatically if null */ public void save(File file, AbstractFileSaver saver) { if (saver == null) saver = ConverterUtils.getSaverForFile(file); try { saver.setFile(file); saver.writeBatch(); m_CurrentFile = file; } catch (Exception e) { System.err.println("Failed to save data to '" + file + "':"); e.printStackTrace(); JOptionPane.showMessageDialog( this, "Failed to save dataset to '" + file + "':\n" + e, "Error saving", JOptionPane.ERROR_MESSAGE); } updateMenu(); }
/** * Returns the Capabilities of this saver. * * @return the capabilities of this object * @see Capabilities */ @Override public Capabilities getCapabilities() { Capabilities result = super.getCapabilities(); // attributes result.enable(Capability.NUMERIC_ATTRIBUTES); // class result.enable(Capability.NUMERIC_CLASS); result.enable(Capability.NO_CLASS); return result; }
/** * Sets instances that should be stored. * * @param instances the instances */ @Override public void setInstances(Instances instances) { if (m_ClassIndex.getSingleIndex().length() != 0) { m_ClassIndex.setUpper(instances.numAttributes() - 1); instances.setClassIndex(m_ClassIndex.getIndex()); } super.setInstances(instances); }
/** * returns the options of the current setup. * * @return the current options */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-c"); result.add(getClassIndex()); Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
saver = new ArffSaver(); saver.setFile(new File(m_sFile)); saver.setInstances(m_Instances); saver.writeBatch();
@Override public void run() { try { m_Log.statusMessage("Saving to file..."); saver.setInstances(inst); saver.writeBatch(); m_Log.statusMessage("OK"); } catch (Exception ex) { ex.printStackTrace(); m_Log.logMessage(ex.getMessage()); } m_IOThread = null; } };
resetOptions(); File input = new File(inputString); loader.setFile(input); setInstances(loader.getDataSet()); } catch (Exception ex) { ex.printStackTrace(); for (String ext : getFileExtensions()) { if (outputString.endsWith(ext)) { validExt = true; setFile(output); } catch (Exception ex) { throw new IOException("Cannot create output file (Reason: "
((weka.core.converters.AbstractFileSaver) saver).retrieveFile(); prefix = ((weka.core.converters.AbstractFileSaver) saver).filePrefix(); dir = ((weka.core.converters.AbstractFileSaver) saver).retrieveDir();
/** * Set the environment variables to use. * * @param env the environment variables to use */ @Override public void setEnvironment(Environment env) { m_env = env; if (m_outputFile != null) { try { // try and resolve any new environment variables setFile(m_outputFile); } catch (IOException ex) { // we won't complain about it here... } } }
String[] tmpOptions = options.clone(); if (Utils.getFlag('h', tmpOptions)) { System.err.println("\nHelp requested\n" + makeOptionStr(saver)); return; saver.setOptions(options); } catch (Exception ex) { System.err.println(makeOptionStr(saver)); System.exit(1); saver.writeBatch(); } catch (Exception ex) { ex.printStackTrace();