de.fu_berlin.ties.classify.feature
Class FeatureVector

java.lang.Object
  extended by de.fu_berlin.ties.classify.feature.FeatureVector
Direct Known Subclasses:
DefaultFeatureVector, FeatureSet

public abstract class FeatureVector
extends Object

A feature vector contains the features representing an instance. Subclasses must implement the store() method to provide a collection for storing the features.

Instances of this class are thread-safe if and only if the provided collection is thread-safe (normally this won't be the case).

Version:
$Revision: 1.6 $, $Date: 2004/09/06 17:22:10 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
FeatureVector()
          Creates a new instance.
 
Method Summary
 void add(Feature feature)
          Adds a feature to this vector.
 void addAll(Collection coll)
          Adds all of the features in the specified Collection to this vector, in the order they are returned by the specified Collection's Iterator.
 void addAll(FeatureVector fv)
          Adds all of the features in the specified feature vector to this vector, in the order they are returned by the specified feature vector.
 void addAllTokens(CharSequence text, TextTokenizer tokenizer)
          Tokenizes a text, creating and adding a feature for each token.
 CharSequence flatten()
          Flattens the contained features into a single character sequence, without including comments.
 CharSequence flatten(boolean inclComments)
          Flattens a list of features into a single character sequence.
 double getSummedStrength()
          Returns a sum of the strength values of all features contained in this vector.
 Iterator iterator()
          Returns an iterator over the Features stored in this vector.
protected  void preAddHook(Feature feature)
          Empty method that can by implemented by child classes, for example if they calculate strength values in some special way.
protected  void setSummedStrength(double newSum)
          Modifies the summed strength of all features contained in this instance.
 int size()
          Returns the number of features stored in this vector.
protected abstract  Collection<Feature> store()
          Returns the collection used for storing the features.
 double strength(Feature feature)
          Returns a strength value for a feature contained in this vector.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FeatureVector

public FeatureVector()
Creates a new instance.

Method Detail

add

public void add(Feature feature)
Adds a feature to this vector.

Parameters:
feature - the feature to add

addAll

public void addAll(Collection coll)
            throws ClassCastException
Adds all of the features in the specified Collection to this vector, in the order they are returned by the specified Collection's Iterator.

Parameters:
coll - a collection of features to add
Throws:
ClassCastException - if the collection contains elements that are not Features

addAll

public void addAll(FeatureVector fv)
Adds all of the features in the specified feature vector to this vector, in the order they are returned by the specified feature vector.

Parameters:
fv - the vector of features to add

addAllTokens

public void addAllTokens(CharSequence text,
                         TextTokenizer tokenizer)
Tokenizes a text, creating and adding a feature for each token.

Parameters:
text - the text to tokenize
tokenizer - the tokenizer to use

getSummedStrength

public double getSummedStrength()
Returns a sum of the strength values of all features contained in this vector.

Returns:
the summed strength of all features

flatten

public CharSequence flatten()
Flattens the contained features into a single character sequence, without including comments. Features are separated by newlines.

Returns:
the resulting character sequence, created by printing calling Feature.getRepresentation() on each feature in the vector; each feature representation is followed by a newline

flatten

public CharSequence flatten(boolean inclComments)
Flattens a list of features into a single character sequence. Features are separated by newlines.

Parameters:
inclComments - whether or not to include comments
Returns:
the resulting character sequence, created by printing calling Feature.getRepresentation() on each feature in the vector; each feature representation is followed by a newline

iterator

public Iterator iterator()
Returns an iterator over the Features stored in this vector.

Returns:
an iterator over the stored features

preAddHook

protected void preAddHook(Feature feature)
Empty method that can by implemented by child classes, for example if they calculate strength values in some special way. This method is called at the start of each add(Feature) operation.

Parameters:
feature - the feature to add

setSummedStrength

protected void setSummedStrength(double newSum)
Modifies the summed strength of all features contained in this instance. This method exists for the convenience of child classes that calculate strength values in some special way.

Parameters:
newSum - the new value of the attribute

size

public int size()
Returns the number of features stored in this vector.

Returns:
the number of features

strength

public double strength(Feature feature)
Returns a strength value for a feature contained in this vector. This implementation simply delegates to Feature.getStrength().

Parameters:
feature - the feature to consider
Returns:
a strength value for the specified feature

store

protected abstract Collection<Feature> store()
Returns the collection used for storing the features. The properties of a feature vector depend on the kind of collection that is used.

Returns:
the collection used for storing the features.

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a textual representation


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.