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.| Modifier and Type | Field and Description |
|---|---|
protected Instances |
m_BatchBuffer
the batch buffer.
|
protected int |
m_BatchCounter
the instance counter for the batch case.
|
protected java.io.File |
m_File
the file to load.
|
protected boolean |
m_Incremental
whether the loader is incremental.
|
protected Instance |
m_IncrementalBuffer
the last internally read instance.
|
protected Loader |
m_Loader
the loader.
|
protected java.net.URL |
m_URL
the URL to load.
|
| Constructor 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.
|
protected void |
initBatchBuffer()
initializes the batch buffer if necessary, i.e., for non-incremental
loaders.
|
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.
|
protected java.io.File m_File
protected java.net.URL m_URL
protected Loader m_Loader
protected boolean m_Incremental
protected int m_BatchCounter
protected Instance m_IncrementalBuffer
protected Instances m_BatchBuffer
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 useprotected void initBatchBuffer()
public 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