Package weka.core.converters

# Interface Loader

All Superinterfaces:
  `RevisionHandler`, `Serializable`

All Known Implementing Classes:
  `AbstractFileLoader`, `AbstractLoader`, `ArffLoader`, `C45Loader`, `CSVLoader`, `DatabaseLoader`, `LibSVMLoader`, `SerializedInstancesLoader`, `SVMLightLoader`, `TextDirectoryLoader`, `XRFFLoader`

public interface Loader extends Serializable, RevisionHandler
Interface to something that can load Instances from an input source in some format.

Version:
  $Revision: 7454 $
Author:
  Mark Hall (mhall@cs.waikato.ac.nz)

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`BATCH`
`static final int`
`INCREMENTAL`
`static final int`
`NONE`
The retrieval modes

## Method Summary

Modifier and Type
Method
Description
`Instances`
`getDataSet()`
Return the full data set.
`Instance`
`getNextInstance(Instances structure)`
Read the data set incrementally---get the next instance in the data set or returns null if there are no more instances to get.
`Instances`
`getStructure()`
Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.
`void`
`reset()`
Resets the Loader object ready to begin loading.
`void`
`setRetrieval(int mode)`
Sets the retrieval mode.
`void`
`setSource(File file)`
Resets the Loader object and sets the source of the data set to be the supplied File object.
`void`
`setSource(InputStream input)`
Resets the Loader object and sets the source of the data set to be the supplied InputStream.

### Methods inherited from interface weka.core.RevisionHandler

`getRevision`

## Field Details

### NONE

static final int NONE
The retrieval modes

See Also:
  - Constant Field Values

### BATCH

static final int BATCH

See Also:
  - Constant Field Values

### INCREMENTAL

static final int INCREMENTAL

See Also:
  - Constant Field Values

## Method Details

### setRetrieval

void setRetrieval(int mode)
Sets the retrieval mode. Note: Some loaders may not be able to implement incremental loading.

Parameters:
  `mode` - the retrieval mode

### reset

void reset() throws Exception
Resets the Loader object ready to begin loading. If there is an existing source, implementations should attempt to reset in such a fashion as to be able to load from the beginning of the source.

Throws:
  `Exception` - if Loader can't be reset for some reason.

### setSource

void setSource(File file) throws IOException
Resets the Loader object and sets the source of the data set to be the supplied File object.

Parameters:
  `file` - the File
Throws:
  `IOException` - if an error occurs support loading from a File.

      <jml>
          public_normal_behavior
            requires: file != null
                      invalid input: '&'invalid input: '&' (* file exists *);
            modifiable: model_sourceSupplied, model_structureDetermined;
            ensures: model_sourceSupplied == true
                     invalid input: '&'invalid input: '&' model_structureDetermined == false;
        also
          public_exceptional_behavior
            requires: file == null
                      || (* file does not exist *);
          signals: (IOException);
       </jml>

### setSource

void setSource(InputStream input) throws IOException
Resets the Loader object and sets the source of the data set to be the supplied InputStream.

Parameters:
  `input` - the source InputStream
Throws:
  `IOException` - if this Loader doesn't support loading from a File.

### getStructure

Instances getStructure() throws IOException
Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.

Returns:
  the structure of the data set as an empty set of Instances
Throws:
  `IOException` - if there is no source or parsing fails

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

### getDataSet

Instances getDataSet() throws IOException
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.

Returns:
  the full data set as an Instances object
Throws:
  `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).

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

### getNextInstance

Instance getNextInstance(Instances structure) throws IOException
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.

Parameters:
  `structure` - the dataset header information, will get updated in case of string or relational attributes
Returns:
  the next instance in the data set as an Instance object or null if there are no more instances to be read
Throws:
  `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).