/** * Main method. * * @param args should contain the options of a Saver. */ public static void main(String[] args) { runFileSaver(new C45Saver(), args); } }
/** Constructor */ public C45Saver() { resetOptions(); }
int writeMode = getWriteMode(); Instances structure = getInstances(); PrintWriter outW = null; if (getRetrieval() == BATCH || getRetrieval() == NONE) { throw new IOException("Batch and incremental saving cannot be mixed."); if (retrieveFile() == null || getWriter() == null) { throw new IOException( "C4.5 format requires two files. Therefore no output to standard out can be generated.\nPlease specifiy output files using the -o option."); outW = new PrintWriter(getWriter()); setWriteMode(CANCEL); if (inst != null) { System.err setWriteMode(STRUCTURE_READY); writeMode = getWriteMode(); cancel(); setWriteMode(WRITE); writeMode = getWriteMode(); String out = retrieveFile().getAbsolutePath(); setFileExtension(".data");
Instances instances = getInstances(); if (getRetrieval() == INCREMENTAL) { throw new IOException("Batch and incremental saving cannot be mixed."); setRetrieval(BATCH); if (retrieveFile() == null || getWriter() == null) { throw new IOException( "C4.5 format requires two files. Therefore no output to standard out can be generated.\nPlease specifiy output files using the -o option."); setWriteMode(WRITE); setFileExtension(".names"); PrintWriter outW = new PrintWriter(getWriter()); for (int i = 0; i < instances.attribute(instances.classIndex()).numValues(); i++) { outW.write(instances.attribute(instances.classIndex()).value(i)); String out = retrieveFile().getAbsolutePath(); setFileExtension(".data"); out = out.substring(0, out.lastIndexOf('.')) + getFileExtension(); File namesFile = new File(out); try { setFile(namesFile); } catch (Exception ex) { throw new IOException( if (retrieveFile() == null || getWriter() == null) { throw new IOException("Cannot create data file, only names file created.");
resetOptions(); inst.setClassIndex(index); setInstances(inst); } catch (Exception ex) { throw new IOException( if (!outputString.endsWith(getFileExtension())) { if (outputString.lastIndexOf('.') != -1) { outputString = (outputString.substring(0, outputString.lastIndexOf('.'))) + getFileExtension(); } else { outputString = outputString + getFileExtension(); setFile(output); } catch (Exception ex) { throw new IOException("Cannot create output file."); index = getInstances().numAttributes() - 1; getInstances().setClassIndex(index);
/** * returns the saver used in the tests * * @return the configured saver */ public AbstractSaver getSaver() { return new C45Saver(); }
/** * Gets the current settings of the C45Saver object. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); if (retrieveFile() != null) { options.add("-o"); options.add("" + retrieveFile()); } else { options.add("-o"); options.add(""); } if (getInstances() != null) { options.add("-i"); options.add("" + getInstances().relationName()); options.add("-c"); options.add("" + getInstances().classIndex()); } else { options.add("-i"); options.add(""); options.add("-c"); options.add(""); } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
int writeMode = getWriteMode(); Instances structure = getInstances(); PrintWriter outW = null; if (getRetrieval() == BATCH || getRetrieval() == NONE) { throw new IOException("Batch and incremental saving cannot be mixed."); if (retrieveFile() == null || getWriter() == null) { throw new IOException( "C4.5 format requires two files. Therefore no output to standard out can be generated.\nPlease specifiy output files using the -o option."); outW = new PrintWriter(getWriter()); setWriteMode(CANCEL); if (inst != null) { System.err setWriteMode(STRUCTURE_READY); writeMode = getWriteMode(); cancel(); setWriteMode(WRITE); writeMode = getWriteMode(); String out = retrieveFile().getAbsolutePath(); setFileExtension(".data");
Instances instances = getInstances(); if (getRetrieval() == INCREMENTAL) { throw new IOException("Batch and incremental saving cannot be mixed."); setRetrieval(BATCH); if (retrieveFile() == null || getWriter() == null) { throw new IOException( "C4.5 format requires two files. Therefore no output to standard out can be generated.\nPlease specifiy output files using the -o option."); setWriteMode(WRITE); setFileExtension(".names"); PrintWriter outW = new PrintWriter(getWriter()); for (int i = 0; i < instances.attribute(instances.classIndex()).numValues(); i++) { outW.write(instances.attribute(instances.classIndex()).value(i)); String out = retrieveFile().getAbsolutePath(); setFileExtension(".data"); out = out.substring(0, out.lastIndexOf('.')) + getFileExtension(); File namesFile = new File(out); try { setFile(namesFile); } catch (Exception ex) { throw new IOException( if (retrieveFile() == null || getWriter() == null) { throw new IOException("Cannot create data file, only names file created.");
resetOptions(); inst.setClassIndex(index); setInstances(inst); } catch (Exception ex) { throw new IOException( if (!outputString.endsWith(getFileExtension())) { if (outputString.lastIndexOf('.') != -1) { outputString = (outputString.substring(0, outputString.lastIndexOf('.'))) + getFileExtension(); } else { outputString = outputString + getFileExtension(); setFile(output); } catch (Exception ex) { throw new IOException("Cannot create output file."); index = getInstances().numAttributes() - 1; getInstances().setClassIndex(index);
/** * returns the saver used in the tests * * @return the configured saver */ public AbstractSaver getSaver() { return new C45Saver(); }
/** * Gets the current settings of the C45Saver object. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); if (retrieveFile() != null) { options.add("-o"); options.add("" + retrieveFile()); } else { options.add("-o"); options.add(""); } if (getInstances() != null) { options.add("-i"); options.add("" + getInstances().relationName()); options.add("-c"); options.add("" + getInstances().classIndex()); } else { options.add("-i"); options.add(""); options.add("-c"); options.add(""); } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
/** * Main method. * * @param args should contain the options of a Saver. */ public static void main(String[] args) { runFileSaver(new C45Saver(), args); } }
/** Constructor */ public C45Saver() { resetOptions(); }