public class CSVLoader extends AbstractFileLoader implements BatchConverter, IncrementalConverter, OptionHandler
-H No header row present in the data.
-N <range> The range of attributes to force type to be NOMINAL. 'first' and 'last' are accepted as well. Examples: "first-last", "1,4,5-27,50-last" (default: -none-)
-L <nominal label spec> Optional specification of legal labels for nominal attributes. May be specified multiple times. Batch mode can determine this automatically (and so can incremental mode if the first in memory buffer load of instances contains an example of each legal value). The spec contains two parts separated by a ":". The first part can be a range of attribute indexes or a comma-separated list off attruibute names; the second part is a comma-separated list of labels. E.g "1,2,4-6:red,green,blue" or "att1,att2:red,green,blue"
-S <range> The range of attribute to force type to be STRING. 'first' and 'last' are accepted as well. Examples: "first-last", "1,4,5-27,50-last" (default: -none-)
-D <range> The range of attribute to force type to be DATE. 'first' and 'last' are accepted as well. Examples: "first-last", "1,4,5-27,50-last" (default: -none-)
-format <date format> The date formatting string to use to parse date values. (default: "yyyy-MM-dd'T'HH:mm:ss")
-M <str> The string representing a missing value. (default: ?)
-F <separator> The field separator to be used. '\t' can be used as well. (default: ',')
-E <enclosures> The enclosure character(s) to use for strings. Specify as a comma separated list (e.g. ",' (default: ",')
-B <num> The size of the in memory buffer (in rows). (default: 100)
Loader.StructureNotReadyException| Modifier and Type | Field and Description |
|---|---|
static String |
FILE_EXTENSION
the file extension.
|
FILE_EXTENSION_COMPRESSEDBATCH, INCREMENTAL, NONE| Constructor and Description |
|---|
CSVLoader()
default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
String |
bufferSizeTipText()
Returns the tip text for this property.
|
String |
dateAttributesTipText()
Returns the tip text for this property.
|
String |
dateFormatTipText()
Returns the tip text for this property.
|
String |
enclosureCharactersTipText()
Returns the tip text for this property.
|
String |
fieldSeparatorTipText()
Returns the tip text for this property.
|
int |
getBufferSize()
Get the buffer size to use - i.e.
|
Instances |
getDataSet()
Return the full data set.
|
String |
getDateAttributes()
Returns the current attribute range to be forced to type date.
|
String |
getDateFormat()
Get the format to use for parsing date values.
|
String |
getEnclosureCharacters()
Get the character(s) to use/recognize as string enclosures
|
String |
getFieldSeparator()
Returns the character used as column separator.
|
String |
getFileDescription()
Get a one line description of the type of file
|
String |
getFileExtension()
Get the file extension used for this type of file
|
String[] |
getFileExtensions()
Gets all the file extensions used for this type of file
|
String |
getMissingValue()
Returns the current placeholder for missing values.
|
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.
|
boolean |
getNoHeaderRowPresent()
Get whether there is no header row in the data.
|
String |
getNominalAttributes()
Returns the current attribute range to be forced to type nominal.
|
Object[] |
getNominalLabelSpecs()
Get label specifications for nominal attributes.
|
String[] |
getOptions()
Gets the current option settings for the OptionHandler.
|
String |
getRevision()
Returns the revision string.
|
String |
getStringAttributes()
Returns the current attribute range to be forced to type string.
|
Instances |
getStructure()
Determines and returns (if possible) the structure (internally the header)
of the data set as an empty set of instances.
|
String |
globalInfo()
Returns a string describing this attribute evaluator.
|
Enumeration<Option> |
listOptions()
Returns an enumeration of all the available options..
|
static void |
main(String[] args)
Main method.
|
String |
missingValueTipText()
Returns the tip text for this property.
|
String |
noHeaderRowPresentTipText()
Returns the tip text for this property.
|
String |
nominalAttributesTipText()
Returns the tip text for this property.
|
String |
nominalLabelSpecsTipText()
Returns the tip text for this property.
|
void |
reset()
Resets the loader ready to read a new data set
|
void |
setBufferSize(int buff)
Set the buffer size to use - i.e.
|
void |
setDateAttributes(String value)
Set the attribute range to be forced to type date.
|
void |
setDateFormat(String value)
Set the format to use for parsing date values.
|
void |
setEnclosureCharacters(String enclosure)
Set the character(s) to use/recognize as string enclosures
|
void |
setFieldSeparator(String value)
Sets the character used as column separator.
|
void |
setMissingValue(String value)
Sets the placeholder for missing values.
|
void |
setNoHeaderRowPresent(boolean b)
Set whether there is no header row in the data.
|
void |
setNominalAttributes(String value)
Sets the attribute range to be forced to type nominal.
|
void |
setNominalLabelSpecs(Object[] specs)
Set label specifications for nominal attributes.
|
void |
setOptions(String[] options)
Sets the OptionHandler's options using the given list.
|
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 Stream object.
|
void |
setStringAttributes(String value)
Sets the attribute range to be forced to type string.
|
String |
stringAttributesTipText()
Returns the tip text for this property.
|
getUseRelativePath, retrieveFile, runFileLoader, setEnvironment, setFile, setUseRelativePath, useRelativePathTipTextsetRetrievalpublic static String FILE_EXTENSION
public String globalInfo()
public String getFileExtension()
FileSourcedConvertergetFileExtension in interface FileSourcedConverterpublic String[] getFileExtensions()
FileSourcedConvertergetFileExtensions in interface FileSourcedConverterpublic String getFileDescription()
FileSourcedConvertergetFileDescription in interface FileSourcedConverterpublic String getRevision()
RevisionHandlergetRevision in interface RevisionHandlerpublic String noHeaderRowPresentTipText()
public void setNoHeaderRowPresent(boolean b)
b - true if there is no header row in the datapublic boolean getNoHeaderRowPresent()
public void setMissingValue(String value)
value - the placeholderpublic String getMissingValue()
public String missingValueTipText()
public void setStringAttributes(String value)
value - the rangepublic String getStringAttributes()
public String stringAttributesTipText()
public void setNominalAttributes(String value)
value - the rangepublic String getNominalAttributes()
public String nominalAttributesTipText()
public void setDateFormat(String value)
value - the format to use.public String getDateFormat()
public String dateFormatTipText()
public void setDateAttributes(String value)
value - the rangepublic String getDateAttributes()
public String dateAttributesTipText()
public String enclosureCharactersTipText()
public void setEnclosureCharacters(String enclosure)
enclosure - the characters to use as string enclosurespublic String getEnclosureCharacters()
public void setFieldSeparator(String value)
value - the character to usepublic String getFieldSeparator()
public String fieldSeparatorTipText()
public void setBufferSize(int buff)
buff - the buffer size (number of rows)public int getBufferSize()
public String bufferSizeTipText()
public void setNominalLabelSpecs(Object[] specs)
specs - an array of label specificationspublic Object[] getNominalLabelSpecs()
public String nominalLabelSpecsTipText()
public Enumeration<Option> listOptions()
OptionHandlerlistOptions in interface OptionHandlerpublic void setOptions(String[] options) throws Exception
OptionHandlersetOptions in interface OptionHandleroptions - the list of options as an array of stringsException - if an option is not supportedpublic String[] getOptions()
OptionHandlergetOptions in interface OptionHandlerpublic Instance getNextInstance(Instances structure) throws IOException
LoadergetNextInstance in interface LoadergetNextInstance in class AbstractLoaderstructure - the dataset header information, will get updated in case
of string or relational attributesIOException - 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 Instances getDataSet() throws IOException
LoadergetDataSet in interface LoadergetDataSet in class AbstractLoaderIOException - 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);
public void setSource(InputStream input) throws IOException
setSource in interface LoadersetSource in class AbstractLoaderinput - the input streamIOException - if an error occurspublic void setSource(File file) throws IOException
setSource in interface LoadersetSource in class AbstractFileLoaderfile - the source file.IOException - if an error occurspublic Instances getStructure() throws IOException
LoadergetStructure in interface LoadergetStructure in class AbstractLoaderIOException - 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);
public void reset()
throws IOException
AbstractFileLoaderreset in interface Loaderreset in class AbstractFileLoaderIOException - if something goes wrongpublic static void main(String[] args)
args - should contain the name of an input file.Copyright © 2014 University of Waikato, Hamilton, NZ. All Rights Reserved.