weka.core.converters
Class AbstractLoader

java.lang.Object
  extended byweka.core.converters.AbstractLoader
All Implemented Interfaces:
Loader, java.io.Serializable
Direct Known Subclasses:
ArffLoader, C45Loader, CSVLoader, SerializedInstancesLoader, TreeLoader

public abstract class AbstractLoader
extends java.lang.Object
implements Loader

Abstract class gives default implementation of setSource methods. All other methods must be overridden.

Version:
$Revision: 1.6 $
Author:
Richard Kirkby (rkirkby@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
protected static int BATCH
           
protected static int INCREMENTAL
           
protected  int m_retrieval
          The current retrieval mode
protected static int NONE
          The retrieval modes
 
Constructor Summary
AbstractLoader()
           
 
Method Summary
abstract  Instances getDataSet()
          Return the full data set.
abstract  Instance getNextInstance()
          Read the data set incrementally---get the next instance in the data set or returns null if there are no more instances to get.
protected  int getRetrieval()
          Gets the retrieval mode.
abstract  Instances getStructure()
          Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.
protected  void setRetrieval(int mode)
          Sets the retrieval mode.
 void setSource(java.io.File file)
          Default implementation throws an IOException.
 void setSource(java.io.InputStream input)
          Default implementation throws an IOException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

protected static final int NONE
The retrieval modes

See Also:
Constant Field Values

BATCH

protected static final int BATCH
See Also:
Constant Field Values

INCREMENTAL

protected static final int INCREMENTAL
See Also:
Constant Field Values

m_retrieval

protected int m_retrieval
The current retrieval mode

Constructor Detail

AbstractLoader

public AbstractLoader()
Method Detail

setRetrieval

protected void setRetrieval(int mode)
Sets the retrieval mode.

Parameters:
mode - the retrieval mode

getRetrieval

protected int getRetrieval()
Gets the retrieval mode.

Returns:
the retrieval mode

setSource

public void setSource(java.io.File file)
               throws java.io.IOException
Default implementation throws an IOException.

Specified by:
setSource in interface Loader
Parameters:
file - the File
Throws:
java.io.IOException - always

setSource

public void setSource(java.io.InputStream input)
               throws java.io.IOException
Default implementation throws an IOException.

Specified by:
setSource in interface Loader
Parameters:
input - the input stream
Throws:
java.io.IOException - always

getStructure

public abstract Instances getStructure()
                                throws java.io.IOException
Description copied from interface: Loader
Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.

Specified by:
getStructure in interface Loader
Returns:
the structure of the data set as an empty set of Instances
Throws:
java.io.IOException - if there is no source or parsing fails

    public_normal_behavior
      requires: model_sourceSupplied == true
                && model_structureDetermined == false
                && (* successful parse *);
      modifiable: model_structureDetermined;
      ensures: \result != null
               && \result.numInstances() == 0
               && model_structureDetermined == true;
  also
    public_exceptional_behavior
      requires: model_sourceSupplied == false
                || (* unsuccessful parse *);
      signals: (IOException);
 

getDataSet

public abstract Instances getDataSet()
                              throws java.io.IOException
Description copied from interface: Loader
Return the full data set. If the structure hasn't yet been determined by a call to getStructure then the method should do so before processing the rest of the data set.

Specified by:
getDataSet in interface Loader
Returns:
the full data set as an Instances object
Throws:
java.io.IOException - if there is an error during parsing or if getNextInstance has been called on this source (either incremental or batch loading can be used, not both).

    public_normal_behavior
      requires: model_sourceSupplied == true
                && (* successful parse *);
      modifiable: model_structureDetermined;
      ensures: \result != null
               && \result.numInstances() >= 0
               && model_structureDetermined == true;
  also
    public_exceptional_behavior
      requires: model_sourceSupplied == false
                || (* unsuccessful parse *);
      signals: (IOException);
 

getNextInstance

public abstract Instance getNextInstance()
                                  throws java.io.IOException
Description copied from interface: Loader
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. If it is not possible to read the data set incrementally (ie. in cases where the data set structure cannot be fully established before all instances have been seen) then an exception should be thrown.

Specified by:
getNextInstance in interface Loader
Returns:
the next instance in the data set as an Instance object or null if there are no more instances to be read
Throws:
java.io.IOException - if there is an error during parsing or if getDataSet has been called on this source (either incremental or batch loading can be used, not both).

    public_normal_behavior
    {|
       requires: model_sourceSupplied == true
                 && (* successful parse *);
       modifiable: model_structureDetermined;
       ensures: model_structureDetermined == true
                && \result != null;
     also
       requires: model_sourceSupplied == true
                 && (* no further input *);
       modifiable: model_structureDetermined;
       ensures: model_structureDetermined == true
                && \result == null;
    |}
  also
    public_exceptional_behavior
    {|
       requires: model_sourceSupplied == false
                 || (* unsuccessful parse *);
       signals: (IOException);
     also
       requires: (* unable to process data set incrementally *);
       signals: (IOException);
    |}