smile.data.parser
Class DelimitedTextParser
- java.lang.Object
-
- smile.data.parser.DelimitedTextParser
-
public class DelimitedTextParser extends java.lang.ObjectThe delimited text file parser. By default, the parser expects a white-space-separated-values file. Each line in the file corresponds to a row in the table. Within a line, fields are separated by white spaces, each field belonging to one table column. This class can also be used to read other text tabular files by setting delimiter character such ash ','. The file may contain comment lines (starting with '%') and missing values (indicated by placeholder '?'), which both can be parameterized.
-
-
Constructor Summary
Constructors Constructor and Description DelimitedTextParser()Constructor with default delimiter of white space, comment line starting with '%', missing value placeholder "?", no column names, no row names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description DelimitedTextParseraddIgnoredColumn(int index)Adds one columns index to ignoreDelimitedTextParseraddIgnoredColumns(java.util.List<java.lang.Integer> ignoredColumns)Adds several column indices to ignorejava.lang.StringgetCommentStartWith()Returns the character/string that starts a comment line.java.lang.StringgetDelimiter()Returns the delimiter character/string.java.lang.StringgetMissingValuePlaceholder()Returns the missing value placeholder.booleanhasColumnNames()Returns if the dataset has column namesS (at row 0).booleanhasRowNames()Returns if the dataset has row names (at column 0).AttributeDatasetparse(Attribute[] attributes, java.io.File file)Parse a dataset from given file.AttributeDatasetparse(Attribute[] attributes, java.lang.String path)Parse a dataset from given file.AttributeDatasetparse(java.io.File file)Parse a dataset from given file.AttributeDatasetparse(java.lang.String path)Parse a dataset from given file.AttributeDatasetparse(java.lang.String name, Attribute[] attributes, java.io.File file)Parse a dataset from given file.AttributeDatasetparse(java.lang.String name, Attribute[] attributes, java.lang.String path)Parse a dataset from given file.AttributeDatasetparse(java.lang.String name, Attribute[] attributes, java.net.URI uri)Parse a dataset from given URI.AttributeDatasetparse(java.lang.String name, java.io.File file)Parse a dataset from given file.AttributeDatasetparse(java.lang.String name, java.io.InputStream stream)Parse a dataset from an input stream.AttributeDatasetparse(java.net.URI uri)Parse a dataset from given URI.DelimitedTextParsersetColumnNames(boolean hasColNames)Set if the dataset has column names (at row 0).DelimitedTextParsersetCommentStartWith(java.lang.String comment)Set the character/string that starts a comment line.DelimitedTextParsersetDelimiter(java.lang.String delimiter)Set the delimiter character/string.DelimitedTextParsersetIgnoredColumns(java.util.List<java.lang.Integer> ignoredColumns)Sets the list of column indices to ignore (starting at 0)DelimitedTextParsersetMissingValuePlaceholder(java.lang.String missing)Set the missing value placeholder.DelimitedTextParsersetResponseIndex(Attribute response, int index)Sets the attribute and column index (starting at 0) of dependent/response variable.DelimitedTextParsersetRowNames(boolean hasRowNames)Set if the dataset has row names (at column 0).
-
-
-
Constructor Detail
-
DelimitedTextParser
public DelimitedTextParser()
Constructor with default delimiter of white space, comment line starting with '%', missing value placeholder "?", no column names, no row names.
-
-
Method Detail
-
getDelimiter
public java.lang.String getDelimiter()
Returns the delimiter character/string.
-
setDelimiter
public DelimitedTextParser setDelimiter(java.lang.String delimiter)
Set the delimiter character/string.
-
getCommentStartWith
public java.lang.String getCommentStartWith()
Returns the character/string that starts a comment line.
-
setCommentStartWith
public DelimitedTextParser setCommentStartWith(java.lang.String comment)
Set the character/string that starts a comment line.
-
getMissingValuePlaceholder
public java.lang.String getMissingValuePlaceholder()
Returns the missing value placeholder.
-
setMissingValuePlaceholder
public DelimitedTextParser setMissingValuePlaceholder(java.lang.String missing)
Set the missing value placeholder.
-
setResponseIndex
public DelimitedTextParser setResponseIndex(Attribute response, int index)
Sets the attribute and column index (starting at 0) of dependent/response variable.
-
setIgnoredColumns
public DelimitedTextParser setIgnoredColumns(java.util.List<java.lang.Integer> ignoredColumns)
Sets the list of column indices to ignore (starting at 0)
-
addIgnoredColumn
public DelimitedTextParser addIgnoredColumn(int index)
Adds one columns index to ignore
-
addIgnoredColumns
public DelimitedTextParser addIgnoredColumns(java.util.List<java.lang.Integer> ignoredColumns)
Adds several column indices to ignore
-
hasRowNames
public boolean hasRowNames()
Returns if the dataset has row names (at column 0).
-
setRowNames
public DelimitedTextParser setRowNames(boolean hasRowNames)
Set if the dataset has row names (at column 0).
-
hasColumnNames
public boolean hasColumnNames()
Returns if the dataset has column namesS (at row 0).
-
setColumnNames
public DelimitedTextParser setColumnNames(boolean hasColNames)
Set if the dataset has column names (at row 0).
-
parse
public AttributeDataset parse(java.net.URI uri) throws java.io.IOException, java.text.ParseException
Parse a dataset from given URI.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.lang.String name, Attribute[] attributes, java.net.URI uri) throws java.io.IOException, java.text.ParseException
Parse a dataset from given URI.- Parameters:
uri- the URI of data source.attributes- the list attributes of data in proper order.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.lang.String path) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
path- the file path of data source.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(Attribute[] attributes, java.lang.String path) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
path- the file path of data source.attributes- the list attributes of data in proper order.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.lang.String name, Attribute[] attributes, java.lang.String path) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
path- the file path of data source.attributes- the list attributes of data in proper order.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.io.File file) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
file- the file of data source.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.lang.String name, java.io.File file) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
file- the file of data source.- Throws:
java.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(Attribute[] attributes, java.io.File file) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
file- the file of data source.attributes- the list attributes of data in proper order.- Throws:
java.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.lang.String name, Attribute[] attributes, java.io.File file) throws java.io.IOException, java.text.ParseException
Parse a dataset from given file.- Parameters:
file- the file of data source.attributes- the list attributes of data in proper order.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
parse
public AttributeDataset parse(java.lang.String name, java.io.InputStream stream) throws java.io.IOException, java.text.ParseException
Parse a dataset from an input stream.- Parameters:
name- the name of dataset.stream- the input stream of data.- Throws:
java.io.FileNotFoundExceptionjava.io.IOExceptionjava.text.ParseException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG