/** SAVE MODEL */ public void saveDataset(String arffilename, String dsfilename) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(arffilename), "UTF-8")); ArffReader arff = new ArffReader(reader); Instances dataset = arff.getData(); reader.close(); FileOutputStream dsOutFile = new FileOutputStream(dsfilename); ObjectOutputStream dsOutObjectFile = new ObjectOutputStream(dsOutFile); dsOutObjectFile.writeObject(dataset); dsOutObjectFile.flush(); dsOutObjectFile.close(); } catch (Exception e) {System.out.println("File not found: "+e.getMessage());} } // end save dataset
@Override public Instances getDataSet() throws IOException { if (m_sourceReader == null) { throw new IOException("No source has been specified"); } if (getRetrieval() == INCREMENTAL) { throw new IOException( "Cannot mix getting instances in both incremental and batch modes"); } setRetrieval(BATCH); if (m_structure == null) { getStructure(); } while (readData(true)) { ; } m_dataDumper.flush(); m_dataDumper.close(); // make final structure makeStructure(); Reader sr = new BufferedReader(new FileReader(m_tempFile)); ArffReader initialArff = new ArffReader(sr, m_structure, 0, m_fieldSeparatorAndEnclosures); Instances initialInsts = initialArff.getData(); sr.close(); initialArff = null; return initialInsts; }
@Override public Instances getDataSet() throws IOException { if (m_sourceReader == null) { throw new IOException("No source has been specified"); } if (getRetrieval() == INCREMENTAL) { throw new IOException( "Cannot mix getting instances in both incremental and batch modes"); } setRetrieval(BATCH); if (m_structure == null) { getStructure(); } while (readData(true)) { ; } m_dataDumper.flush(); m_dataDumper.close(); // make final structure makeStructure(); Reader sr = new BufferedReader(new FileReader(m_tempFile)); ArffReader initialArff = new ArffReader(sr, m_structure, 0, m_fieldSeparatorAndEnclosures); Instances initialInsts = initialArff.getData(); sr.close(); initialArff = null; return initialInsts; }
try { ArffReader arff = new ArffReader(new StringReader(m_Tokenizer.sval), m_Data .attribute(i).relation(), 0); Instances data = arff.getData();
ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
new ArffReader(batchReader, m_structure, 0, 0, m_fieldSeparatorAndEnclosures);
new ArffReader(batchReader, m_structure, 0, 0, m_fieldSeparatorAndEnclosures);
ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
public static void main(String[] args) throws Exception { Path datapath= Paths.get("./src/main/resources/Qald6Logs.arff"); BufferedReader reader = new BufferedReader(new FileReader(datapath.toString())); ArffReader arff = new ArffReader(reader); Instances data = arff.getData(); data.setClassIndex(6);
ArffReader arff = new ArffReader(reader);
/** * Determines and returns (if possible) the structure (internally the header) * of the data set as an empty set of instances. * * @return the structure of the data set as an empty set of Instances * @throws IOException if an error occurs */ @Override public Instances getStructure() throws IOException { if (m_structure == null) { if (m_sourceReader == null) { throw new IOException("No source has been specified"); } try { m_ArffReader = new ArffReader(m_sourceReader, 1, (getRetrieval() == BATCH)); m_ArffReader.setRetainStringValues(getRetainStringVals()); m_structure = m_ArffReader.getStructure(); } catch (Exception ex) { throw new IOException("Unable to determine structure as arff (Reason: " + ex.toString() + ")."); } } return new Instances(m_structure, 0); }
/** * Reads a single instance from the reader and appends it to the dataset. * Automatically expands the dataset if it is not large enough to hold the * instance. This method does not check for carriage return at the end of the * line. * * @param reader the reader * @return false if end of file has been reached * @throws IOException if the information is not read successfully * @deprecated instead of using this method in conjunction with the * <code>readInstance(Reader)</code> method, one should use the * <code>ArffLoader</code> or <code>DataSource</code> class * instead. * @see weka.core.converters.ArffLoader * @see weka.core.converters.ConverterUtils.DataSource */ @Deprecated public boolean readInstance(Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, this, m_Lines, 1); Instance inst = arff.readInstance(arff.getData(), false); m_Lines = arff.getLineNo(); if (inst != null) { add(inst); return true; } else { return false; } }
/** * Reads a single instance from the reader and appends it to the dataset. * Automatically expands the dataset if it is not large enough to hold the * instance. This method does not check for carriage return at the end of the * line. * * @param reader the reader * @return false if end of file has been reached * @throws IOException if the information is not read successfully * @deprecated instead of using this method in conjunction with the * <code>readInstance(Reader)</code> method, one should use the * <code>ArffLoader</code> or <code>DataSource</code> class * instead. * @see weka.core.converters.ArffLoader * @see weka.core.converters.ConverterUtils.DataSource */ @Deprecated public boolean readInstance(Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, this, m_Lines, 1); Instance inst = arff.readInstance(arff.getData(), false); m_Lines = arff.getLineNo(); if (inst != null) { add(inst); return true; } else { return false; } }
/** * Determines and returns (if possible) the structure (internally the header) * of the data set as an empty set of instances. * * @return the structure of the data set as an empty set of Instances * @throws IOException if an error occurs */ @Override public Instances getStructure() throws IOException { if (m_structure == null) { if (m_sourceReader == null) { throw new IOException("No source has been specified"); } try { m_ArffReader = new ArffReader(m_sourceReader, 1, (getRetrieval() == BATCH)); m_ArffReader.setRetainStringValues(getRetainStringVals()); m_structure = m_ArffReader.getStructure(); } catch (Exception ex) { throw new IOException("Unable to determine structure as arff (Reason: " + ex.toString() + ")."); } } return new Instances(m_structure, 0); }
/** * Reads the header of an ARFF file from a reader and reserves space for the * given number of instances. Lets the class index be undefined (negative). * * @param reader the reader * @param capacity the capacity * @throws IllegalArgumentException if the header is not read successfully or * the capacity is negative. * @throws IOException if there is a problem with the reader. * @deprecated instead of using this method in conjunction with the * <code>readInstance(Reader)</code> method, one should use the * <code>ArffLoader</code> or <code>DataSource</code> class * instead. * @see weka.core.converters.ArffLoader * @see weka.core.converters.ConverterUtils.DataSource */ // @ requires capacity >= 0; // @ ensures classIndex() == -1; @Deprecated public Instances(/* @non_null@ */Reader reader, int capacity) throws IOException { ArffReader arff = new ArffReader(reader, 0); Instances header = arff.getStructure(); initialize(header, capacity); m_Lines = arff.getLineNo(); }
/** * Reads the header of an ARFF file from a reader and reserves space for the * given number of instances. Lets the class index be undefined (negative). * * @param reader the reader * @param capacity the capacity * @throws IllegalArgumentException if the header is not read successfully or * the capacity is negative. * @throws IOException if there is a problem with the reader. * @deprecated instead of using this method in conjunction with the * <code>readInstance(Reader)</code> method, one should use the * <code>ArffLoader</code> or <code>DataSource</code> class * instead. * @see weka.core.converters.ArffLoader * @see weka.core.converters.ConverterUtils.DataSource */ // @ requires capacity >= 0; // @ ensures classIndex() == -1; @Deprecated public Instances(/* @non_null@ */Reader reader, int capacity) throws IOException { ArffReader arff = new ArffReader(reader, 0); Instances header = arff.getStructure(); initialize(header, capacity); m_Lines = arff.getLineNo(); }
/** * Reads an ARFF file from a reader, and assigns a weight of one to each * instance. Lets the index of the class attribute be undefined (negative). * * @param reader the reader * @throws IOException if the ARFF file is not read successfully */ public Instances(/* @non_null@ */Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, 1000, false); initialize(arff.getData(), 1000); arff.setRetainStringValues(true); Instance inst; while ((inst = arff.readInstance(this)) != null) { m_Instances.add(inst); } compactify(); }
/** * Reads an ARFF file from a reader, and assigns a weight of one to each * instance. Lets the index of the class attribute be undefined (negative). * * @param reader the reader * @throws IOException if the ARFF file is not read successfully */ public Instances(/* @non_null@ */Reader reader) throws IOException { ArffReader arff = new ArffReader(reader, 1000, false); initialize(arff.getData(), 1000); arff.setRetainStringValues(true); Instance inst; while ((inst = arff.readInstance(this)) != null) { m_Instances.add(inst); } compactify(); }