Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.parser
Class RealVectorLabelParser<V extends RealVector<?,?>>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.logging.AbstractLoggable
      extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
          extended by de.lmu.ifi.dbs.elki.parser.AbstractParser<V>
              extended by de.lmu.ifi.dbs.elki.parser.RealVectorLabelParser<V>
Type Parameters:
V - the type of RealVector expected in the ParsingResult
All Implemented Interfaces:
LinebasedParser<V>, Parser<V>, Parameterizable
Direct Known Subclasses:
DoubleVectorLabelParser, FloatVectorLabelParser, SparseFloatVectorLabelParser

public abstract class RealVectorLabelParser<V extends RealVector<?,?>>
extends AbstractParser<V>
implements LinebasedParser<V>

Provides a parser for parsing one point per line, attributes separated by whitespace.

Several labels may be given per point. A label must not be parseable as double. Lines starting with "#" will be ignored.

An index can be specified to identify an entry to be treated as class label. This index counts all entries (numeric and labels as well) starting with 0.

Author:
Arthur Zimek

Field Summary
private static OptionID CLASS_LABEL_INDEX_ID
          OptionID for CLASS_LABEL_INDEX_PARAM
static IntParameter CLASS_LABEL_INDEX_PARAM
          The parameter for an index of a numerical class label.
protected  int classLabelIndex
          Keeps the index of an attribute to be treated as a string label.
 
Fields inherited from class de.lmu.ifi.dbs.elki.parser.AbstractParser
ATTRIBUTE_CONCATENATION, COMMENT, WHITESPACE_PATTERN
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
optionHandler
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug, logger
 
Constructor Summary
RealVectorLabelParser()
          Provides a parser for parsing one point per line, attributes separated by whitespace.
 
Method Summary
protected abstract  V createDBObject(List<Double> attributes)
          Creates a database object of type V.
protected abstract  String descriptionLineType()
           
 ParsingResult<V> parse(InputStream in)
          Returns a list of the objects parsed from the specified input stream and a list of the labels associated with the objects.
 Pair<V,List<String>> parseLine(String line)
          Parse a single line into a database object
 List<String> setParameters(List<String> args)
          Grabs all specified options from the option handler.
 String shortDescription()
          Returns a short description of the class.
 
Methods inherited from class de.lmu.ifi.dbs.elki.parser.AbstractParser
toString
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
addOption, addParameterizable, addParameterizable, checkGlobalParameterConstraints, collectOptions, getAttributeSettings, getParameters, rememberParametersExcept, removeOption, removeParameterizable
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, progress, verbose, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameterizable
checkGlobalParameterConstraints, collectOptions, getParameters
 

Field Detail

CLASS_LABEL_INDEX_ID

private static final OptionID CLASS_LABEL_INDEX_ID
OptionID for CLASS_LABEL_INDEX_PARAM


CLASS_LABEL_INDEX_PARAM

public static final IntParameter CLASS_LABEL_INDEX_PARAM
The parameter for an index of a numerical class label. The corresponding numerical value is treated as string label an can be selected as class label by the AbstractDatabaseConnection. A non-numerical class label can be directly selected from the labels after parsing via the corresponding parameter of the AbstractDatabaseConnection: AbstractDatabaseConnection.CLASS_LABEL_INDEX_PARAM.

The parameter is optional and the default value is set to -1.


classLabelIndex

protected int classLabelIndex
Keeps the index of an attribute to be treated as a string label.

Constructor Detail

RealVectorLabelParser

public RealVectorLabelParser()
Provides a parser for parsing one point per line, attributes separated by whitespace.

Several labels may be given per point. A label must not be parseable as double (or float). Lines starting with "#" will be ignored.

Method Detail

parse

public ParsingResult<V> parse(InputStream in)
Description copied from interface: Parser
Returns a list of the objects parsed from the specified input stream and a list of the labels associated with the objects.

Specified by:
parse in interface Parser<V extends RealVector<?,?>>
Parameters:
in - the stream to parse objects from
Returns:
a list containing those objects parsed from the input stream and their associated labels.

parseLine

public Pair<V,List<String>> parseLine(String line)
Description copied from interface: LinebasedParser
Parse a single line into a database object

Specified by:
parseLine in interface LinebasedParser<V extends RealVector<?,?>>
Parameters:
line - single line
Returns:
parsing result

createDBObject

protected abstract V createDBObject(List<Double> attributes)

Creates a database object of type V.

Parameters:
attributes - the attributes of the vector to create.
Returns:
a RalVector of type V containing the given attribute values

shortDescription

public String shortDescription()
Description copied from class: AbstractParameterizable
Returns a short description of the class.

Specified by:
shortDescription in interface Parameterizable
Overrides:
shortDescription in class AbstractParameterizable
Returns:
Description of the class

descriptionLineType

protected abstract String descriptionLineType()

setParameters

public List<String> setParameters(List<String> args)
                           throws ParameterException
Description copied from class: AbstractParameterizable
Grabs all specified options from the option handler. Any extending class should call this method first and return the returned array without further changes, but after setting further required parameters. An example for overwriting this method taking advantage from the previously (in superclasses) defined options would be:

 {
   List remainingParameters = super.setParameters(args);
   // set parameters for your class
   // for example like this:
   if(isSet(MY_PARAM_VALUE_PARAM))
   {
      myParamValue = getParameterValue(MY_PARAM_VALUE_PARAM);
   }
   .
   .
   .
   return remainingParameters;
   // or in case of attributes requesting parameters themselves
   // return parameterizableAttribbute.setParameters(remainingParameters);
 }
 

Specified by:
setParameters in interface Parameterizable
Overrides:
setParameters in class AbstractParameterizable
Parameters:
args - parameters to set the attributes accordingly to
Returns:
a list containing the unused parameters
Throws:
ParameterException - in case of wrong parameter-setting

Release 0.2 (2009-07-06_1820)