public class ParserFactory
extends java.lang.Object
implements java.lang.Cloneable
sample(String)
method takes a text string and tests
it against all available parsers, updating whether or not the parsers can
successfully parse the value. This method is used in a more automated
fashion by the TypeInferencer
class.TypeInferencer
Constructor and Description |
---|
ParserFactory()
Constructor.
|
ParserFactory(DataParser[] parsers)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
static ParserFactory |
getDefaultFactory()
Returns the default parser factory.
|
protected DataParser |
getParser()
Returns the highest ranking parser that successfully can
parse all the input samples viewed by this instance.
|
DataParser |
getParser(java.lang.Class type)
Returns a parser for the specified data type.
|
DataParser |
getParser(java.lang.String[][] data,
int col,
int startRow)
Analyzes a column of the given array of String values to
determine an acceptable parser data type.
|
DataParser |
getParser(java.lang.String[] data,
int startRow)
Analyzes the given array of String values to determine an
acceptable parser data type.
|
protected void |
reset()
Reset the candidate parser settings, making each parser
equally likely.
|
protected void |
sample(java.lang.String val)
Sample a data value against the parsers, updating the
parser candidates.
|
static void |
setDefaultFactory(ParserFactory factory)
Sets the default parser factory.
|
public ParserFactory()
public ParserFactory(DataParser[] parsers)
Constructor. Takes an array of parsers to test. After creating this
instance, sample data values can be passed in using the
sample()
method, and this class will check the sample
against the parsers, computing which parsers can successfully parse the
sample. This process of elimination disregards inappropriate parsers.
After a series of samples, the getParser()
method can be used to retrieve the highest ranking candidate parser.
If no parser can parse all samples, a null value will be returned by getParser(). For this reason, it is recommended to always use a StringParser as the last element of the input array, as it is guaranteed to always parse successfully (by simply returning its input String).
The ordering of parsers in the array is taken to be the desired order of precendence of the parsers. For example, if both parser[0] and parser[2] can parse all the available samples, parser[0] will be returned.
parsers
- the input DataParsers to use.public static ParserFactory getDefaultFactory()
public static void setDefaultFactory(ParserFactory factory)
factory
- the new default parser factory.public java.lang.Object clone()
clone
in class java.lang.Object
Object.clone()
protected void reset()
protected void sample(java.lang.String val)
val
- the String value to sampleprotected DataParser getParser()
public DataParser getParser(java.lang.Class type)
type
- the Class for the data type to parsepublic DataParser getParser(java.lang.String[] data, int startRow)
data
- an array of String values to parsestartRow
- the row from which to begin analyzing the
data array, allowing header rows to be excluded.public DataParser getParser(java.lang.String[][] data, int col, int startRow)
data
- an 2D array of String values to parsecol
- an index for the column to processstartRow
- the row from which to begin analyzing the
data array, allowing header rows to be excluded.Copyright ? 2013 Regents of the University of California