예제 #1
0
  /**
   * Read the data set incrementally---get the next instance in the data set or returns null if
   * there are no more instances to get. If the structure hasn't yet been determined by a call to
   * getStructure then method should do so before returning the next instance in the data set.
   *
   * @return the next instance in the data set as an Instance object or null if there are no more
   *     instances to be read
   * @exception IOException if there is an error during parsing
   */
  public Instance getNextInstance() throws IOException {

    if (m_structure == null) {
      getStructure();
    }
    if (getRetrieval() == BATCH) {
      throw new IOException("Cannot mix getting Instances in both incremental and batch modes");
    }
    setRetrieval(INCREMENTAL);

    if (!m_structure.readInstance(m_sourceReader)) {
      return null;
    }

    Instance current = m_structure.instance(0);
    m_structure.delete(0);
    return current;
  }
예제 #2
0
  /**
   * Return the full data set. If the structure hasn't yet been determined by a call to getStructure
   * then method should do so before processing the rest of the data set.
   *
   * @return the structure of the data set as an empty set of Instances
   * @exception IOException if there is no source or parsing fails
   */
  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();
    }

    // Read all instances
    // XXX This is inefficient because readInstance creates a new
    // StringTokenizer each time: This will be fixed once all arff reading
    // is moved out of Instances and into this Loader.
    while (m_structure.readInstance(m_sourceReader)) ;

    return m_structure;
  }