Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.parser
Class NumberDistanceParser<D extends NumberDistance<D,N>,N extends Number>

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<ExternalObject>
              extended by de.lmu.ifi.dbs.elki.parser.NumberDistanceParser<D,N>
Type Parameters:
D - distance type
N - number type
All Implemented Interfaces:
DistanceParser<ExternalObject,D>, Parser<ExternalObject>, Parameterizable

public class NumberDistanceParser<D extends NumberDistance<D,N>,N extends Number>
extends AbstractParser<ExternalObject>
implements DistanceParser<ExternalObject,D>

Provides a parser for parsing one distance value per line.

A line must have the following format: id1 id2 distanceValue, where id1 and id2 are integers representing the two ids belonging to the distance value. Lines starting with "#" will be ignored.

Author:
Elke Achtert

Field Summary
static OptionID DISTANCE_FUNCTION_ID
          OptionID for DISTANCE_FUNCTION_PARAM
(package private)  ClassParameter<DistanceFunction<ExternalObject,D>> DISTANCE_FUNCTION_PARAM
          Parameter for distance function.
private  DistanceFunction<ExternalObject,D> distanceFunction
          The distance function.
 
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
NumberDistanceParser()
          Provides a parser for parsing one double distance per line.
 
Method Summary
 boolean containsKey(Integer id1, Integer id2, Map<Pair<Integer,Integer>,D> cache)
          Returns true if the specified distance cache contains a distance value for the specified ids.
 DistanceFunction<ExternalObject,D> getDistanceFunction()
          Returns the distance function of this parser.
 DistanceParsingResult<ExternalObject,D> 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.
private  void put(Integer id1, Integer id2, D distance, Map<Pair<Integer,Integer>,D> cache)
          Puts the specified distance value for the given ids to the distance cache.
 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

DISTANCE_FUNCTION_ID

public static final OptionID DISTANCE_FUNCTION_ID
OptionID for DISTANCE_FUNCTION_PARAM


DISTANCE_FUNCTION_PARAM

ClassParameter<DistanceFunction<ExternalObject,D extends NumberDistance<D,N>>> DISTANCE_FUNCTION_PARAM
Parameter for distance function.


distanceFunction

private DistanceFunction<ExternalObject,D extends NumberDistance<D,N>> distanceFunction
The distance function.

Constructor Detail

NumberDistanceParser

public NumberDistanceParser()
Provides a parser for parsing one double distance per line. A line must have the following format: id1 id2 distanceValue, where id1 and id2 are integers representing the two ids belonging to the distance value, the distance value is a double value. Lines starting with "#" will be ignored.

Method Detail

parse

public DistanceParsingResult<ExternalObject,D> parse(InputStream in)
Description copied from interface: DistanceParser
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 DistanceParser<ExternalObject,D extends NumberDistance<D,N>>
Specified by:
parse in interface Parser<ExternalObject>
Parameters:
in - the stream to parse objects from
Returns:
a list containing those objects parsed from the input stream and their associated labels.

getDistanceFunction

public DistanceFunction<ExternalObject,D> getDistanceFunction()
Returns the distance function of this parser.

Specified by:
getDistanceFunction in interface DistanceParser<ExternalObject,D extends NumberDistance<D,N>>
Returns:
the distance function of this parser

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

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

put

private void put(Integer id1,
                 Integer id2,
                 D distance,
                 Map<Pair<Integer,Integer>,D> cache)
Puts the specified distance value for the given ids to the distance cache.

Parameters:
id1 - the first id
id2 - the second id
distance - the distance value
cache - the distance cache

containsKey

public boolean containsKey(Integer id1,
                           Integer id2,
                           Map<Pair<Integer,Integer>,D> cache)
Returns true if the specified distance cache contains a distance value for the specified ids.

Parameters:
id1 - the first id
id2 - the second id
cache - the distance cache
Returns:
true if this cache contains a distance value for the specified ids, false otherwise

Release 0.2.1 (2009-07-13_1605)