com.sun.labs.minion.classification
Class WeightedFeature

java.lang.Object
  extended by com.sun.labs.minion.classification.WeightedFeature
All Implemented Interfaces:
Feature, Occurrence, java.io.Serializable, java.lang.Comparable<Feature>
Direct Known Subclasses:
ContingencyFeature

public class WeightedFeature
extends java.lang.Object
implements Feature, java.io.Serializable

See Also:
Serialized Form

Field Summary
protected  QueryEntry entry
          The dictionary entry that gave us this feature.
protected  int freq
          The frequency of the feature.
protected  int id
          The ID for the feature, used when doing postings.
protected static java.util.Comparator<WeightedFeature> invWeightComparator
          An "inverse" weight comparator where large weights are less than small weights
protected  java.lang.String name
          The name of the feature.
protected  float weight
          The weight associated with the feature.
protected static java.util.Comparator<WeightedFeature> weightComparator
          A weight comparator where small weights are less than large weights
 
Constructor Summary
WeightedFeature()
           
WeightedFeature(java.lang.String name)
           
WeightedFeature(java.lang.String name, float weight)
           
WeightedFeature(java.lang.String name, int id, float weight)
           
WeightedFeature(WeightedFeature f)
           
 
Method Summary
 void combine(WeightedFeature f)
          Combines another weighted feature with this one.
 int compareTo(Feature o)
          Compares two features on the basis of their names.
 void decode(ReadableBuffer b)
          Decodes the information in this feature from the given buffer.
 void encode(WriteableBuffer b)
          Encodes the information in this feature onto the given buffer.
 boolean equals(java.lang.Object o)
          Two WeightedFeature objects are equal if they represent the same feature -- that is, their names are the same, but their weights need not be.
 int getCount()
          Gets the count of occurrences that this feature represents.
 QueryEntry getEntry()
           
 int getFreq()
           
 int getID()
          Gets the ID associated with an occurrence.
static java.util.Comparator<WeightedFeature> getInverseWeightComparator()
          Gets a comparator that compares weighted features based on their weights.
 java.lang.String getName()
          Gets the name of this feature.
 float getWeight()
          Gets the weight associated with this feature.
static java.util.Comparator<WeightedFeature> getWeightComparator()
          Gets a comparator that compares weighted features based on their weights.
 void setCount(int count)
          Sets the count of occurrences that this occurrence represents.
 void setEntry(QueryEntry entry)
           
 void setFreq(int freq)
           
 void setID(int id)
          Sets the ID associated with this feature.
 void setName(java.lang.String name)
          Sets the name of this feature.
 void setWeight(float weight)
          Sets the weight associated with this feature.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The name of the feature.


id

protected int id
The ID for the feature, used when doing postings.


freq

protected int freq
The frequency of the feature.


weight

protected float weight
The weight associated with the feature.


entry

protected transient QueryEntry entry
The dictionary entry that gave us this feature. This is an optimization to avoid having to re-fetch and re-decode features when doing things like DocumentVector.findSimilar


weightComparator

protected static java.util.Comparator<WeightedFeature> weightComparator
A weight comparator where small weights are less than large weights


invWeightComparator

protected static java.util.Comparator<WeightedFeature> invWeightComparator
An "inverse" weight comparator where large weights are less than small weights

Constructor Detail

WeightedFeature

public WeightedFeature()

WeightedFeature

public WeightedFeature(java.lang.String name)

WeightedFeature

public WeightedFeature(java.lang.String name,
                       float weight)

WeightedFeature

public WeightedFeature(java.lang.String name,
                       int id,
                       float weight)

WeightedFeature

public WeightedFeature(WeightedFeature f)
Method Detail

setName

public void setName(java.lang.String name)
Sets the name of this feature.

Specified by:
setName in interface Feature
Parameters:
name - the name of the feature.

getName

public java.lang.String getName()
Gets the name of this feature.

Specified by:
getName in interface Feature
Returns:
the name of the feature.

getWeight

public float getWeight()
Gets the weight associated with this feature.


setWeight

public void setWeight(float weight)
Sets the weight associated with this feature.

Parameters:
weight - the weight

combine

public void combine(WeightedFeature f)
Combines another weighted feature with this one. The other feature is assumed to have the same name!


encode

public void encode(WriteableBuffer b)
Encodes the information in this feature onto the given buffer.

Specified by:
encode in interface Feature
Parameters:
b - a buffer onto which the feature's information can be encoded.

decode

public void decode(ReadableBuffer b)
Decodes the information in this feature from the given buffer.

Specified by:
decode in interface Feature
Parameters:
b - a buffer from which the feature's information can be decoded.

setID

public void setID(int id)
Sets the ID associated with this feature.

Specified by:
setID in interface Occurrence
Parameters:
id - the ID.

getID

public int getID()
Gets the ID associated with an occurrence.

Specified by:
getID in interface Occurrence
Returns:
the ID for the term.

setFreq

public void setFreq(int freq)

getFreq

public int getFreq()

getCount

public int getCount()
Gets the count of occurrences that this feature represents.

Specified by:
getCount in interface Occurrence
Returns:
the number of occurrences, which is always 1 in this case

setCount

public void setCount(int count)
Sets the count of occurrences that this occurrence represents.

Specified by:
setCount in interface Occurrence
Parameters:
count - the number of occurrences.

setEntry

public void setEntry(QueryEntry entry)

getEntry

public QueryEntry getEntry()

compareTo

public int compareTo(Feature o)
Compares two features on the basis of their names.

Specified by:
compareTo in interface java.lang.Comparable<Feature>

getWeightComparator

public static java.util.Comparator<WeightedFeature> getWeightComparator()
Gets a comparator that compares weighted features based on their weights. Smaller weights are "less than" larger weights.


getInverseWeightComparator

public static java.util.Comparator<WeightedFeature> getInverseWeightComparator()
Gets a comparator that compares weighted features based on their weights. Larger weights are "less than" smaller weights.


equals

public boolean equals(java.lang.Object o)
Two WeightedFeature objects are equal if they represent the same feature -- that is, their names are the same, but their weights need not be.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare to this one
Returns:
true if the names of the features are the same

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object