public static class ConverterUtils.DataSource extends java.lang.Object implements java.io.Serializable, RevisionHandler
hasMoreElements
,
nextElement
). Before the
data can be read again, one has to call the reset
method.
The data source can also be initialized with an Instances object, in
order to provide a unified interface to files and already loaded datasets.hasMoreElements(Instances)
,
nextElement(Instances)
,
reset()
,
ConverterUtils.DataSink
,
Serialized FormConstructor and Description |
---|
DataSource(java.io.InputStream stream)
Initializes the datasource with the given input stream.
|
DataSource(Instances inst)
Initializes the datasource with the given dataset.
|
DataSource(Loader loader)
Initializes the datasource with the given Loader.
|
DataSource(java.lang.String location)
Tries to load the data from the file.
|
Modifier and Type | Method and Description |
---|---|
Instances |
getDataSet()
returns the full dataset, can be null in case of an error.
|
Instances |
getDataSet(int classIndex)
returns the full dataset with the specified class index set,
can be null in case of an error.
|
Loader |
getLoader()
returns the determined loader, null if the DataSource was initialized
with data alone and not a file/URL.
|
java.lang.String |
getRevision()
Returns the revision string.
|
Instances |
getStructure()
returns the structure of the data.
|
Instances |
getStructure(int classIndex)
returns the structure of the data, with the defined class index.
|
boolean |
hasMoreElements(Instances structure)
returns whether there are more Instance objects in the data.
|
static boolean |
isArff(java.lang.String location)
returns whether the extension of the location is likely to be of ARFF
format, i.e., ending in ".arff" or ".arff.gz" (case-insensitive).
|
boolean |
isIncremental()
returns whether the loader is an incremental one.
|
static void |
main(java.lang.String[] args)
for testing only - takes a data file as input.
|
Instance |
nextElement(Instances dataset)
returns the next element and sets the specified dataset, null if
none available.
|
static Instances |
read(java.io.InputStream stream)
convencience method for loading a dataset in batch mode from a stream.
|
static Instances |
read(Loader loader)
convencience method for loading a dataset in batch mode.
|
static Instances |
read(java.lang.String location)
convencience method for loading a dataset in batch mode.
|
void |
reset()
resets the loader.
|
public DataSource(java.lang.String location) throws java.lang.Exception
location
- the name of the file to loadjava.lang.Exception
- if initialization failspublic DataSource(Instances inst)
inst
- the dataset to usepublic DataSource(Loader loader)
loader
- the Loader to usepublic DataSource(java.io.InputStream stream)
stream
- the stream to usepublic static boolean isArff(java.lang.String location)
location
- the file location to checkpublic boolean isIncremental()
public Loader getLoader()
public Instances getDataSet() throws java.lang.Exception
java.lang.Exception
- if resetting of loader failspublic Instances getDataSet(int classIndex) throws java.lang.Exception
classIndex
- the class index for the datasetjava.lang.Exception
- if resetting of loader failspublic void reset() throws java.lang.Exception
java.lang.Exception
- if resetting failspublic Instances getStructure() throws java.lang.Exception
java.lang.Exception
- if something goes wrongpublic Instances getStructure(int classIndex) throws java.lang.Exception
classIndex
- the class index for the datasetjava.lang.Exception
- if something goes wrongpublic boolean hasMoreElements(Instances structure)
structure
- the structure of the datasetnextElement(Instances)
public Instance nextElement(Instances dataset)
dataset
- the dataset to set for the instancepublic static Instances read(java.lang.String location) throws java.lang.Exception
location
- the dataset to loadjava.lang.Exception
- if loading failspublic static Instances read(java.io.InputStream stream) throws java.lang.Exception
stream
- the stream to load the dataset fromjava.lang.Exception
- if loading failspublic static Instances read(Loader loader) throws java.lang.Exception
loader
- the loader to get the dataset fromjava.lang.Exception
- if loading failspublic static void main(java.lang.String[] args) throws java.lang.Exception
args
- the commandline argumentsjava.lang.Exception
- if something goes wrongpublic java.lang.String getRevision()
getRevision
in interface RevisionHandler