LBJ2.learn
Class ChildLexicon

java.lang.Object
  extended by LBJ2.learn.Lexicon
      extended by LBJ2.learn.ChildLexicon
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ChildLexicon
extends Lexicon

Instances of this class are intended to store features that are children of other features and which do not correspond to their own weights in any learner's weight vector. While a Lexicon will store an instance of this class in its Lexicon.lexiconChildren field, an instance of this class will never do so. Also, the lookupChild(Feature) method behaves differently in this class, since it is assumed that children are stored here.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class LBJ2.learn.Lexicon
Lexicon.CountPolicy, Lexicon.PruningPolicy
 
Field Summary
private  Lexicon parentLexicon
          A reference to the lexicon that uses this lexicon as its child lexicon.
private  IVector parents
          The elements of this vector (which correspond to the features in Lexicon.lexiconInv) serve a dual purpose; first, to indicate by absolute value the number of other features currently stored in this object that have the corresponding feature as a child, and second, to indicate by sign if the corresponding feature has been marked for removal.
 
Fields inherited from class LBJ2.learn.Lexicon
featureCounts, lexicon, lexiconChildren, lexiconInv, perClassFeatureCounts, pruneCutoff
 
Constructor Summary
ChildLexicon()
          Creates an empty lexicon.
ChildLexicon(Lexicon p)
          Creates an empty lexicon.
ChildLexicon(Lexicon p, java.lang.String e)
          Creates an empty lexicon with the given encoding.
 
Method Summary
 int childLexiconLookup(DiscreteConjunctiveFeature f, int label)
          Updates the counts in parents for the children of f.
 int childLexiconLookup(DiscreteReferrer f, int label)
          Updates the counts in parents for the children of f.
 int childLexiconLookup(Feature f, int label)
          Updates the counts in parents for the children of f.
 int childLexiconLookup(RealConjunctiveFeature f, int label)
          Updates the counts in parents for the children of f.
 int childLexiconLookup(RealReferrer f, int label)
          Updates the counts in parents for the children of f.
 void clear()
          Clears the data structures associated with this instance.
 void decrementParentCounts(Feature f)
          The parent of feature f is being removed, so we decrement f's parent counts and remove it if it's ready.
 Feature getChildFeature(Feature f, int label)
          This method adds the given feature to this lexicon and also recursively adds its children, if any.
protected  void incrementParentCounts(Feature f, int label)
          Helper method for methods like childLexiconLookup(DiscreteConjunctiveFeature,int) that actually does the work of looking up the child feature and updating its parent counts.
 int lookupChild(Feature f)
          Unlike the overridden method in Lexicon, this method simply checks Lexicon.lexicon for the feature and will throw an exception if it can't be found.
 void printCountTable(boolean p)
          Produces on STDOUT a table of feature counts including a line indicating the position of Lexicon.pruneCutoff.
 void read(ExceptionlessInputStream in, boolean readCounts)
          Reads a binary representation of the lexicon.
 Feature remove(Feature f)
          Removes the mapping for the given feature from this lexicon and returns the feature object representing it that was stored here.
 void setParent(Lexicon p)
          Sets the value of parentLexicon and makes sure that any features marked for removal in this lexicon are the identical objects also present in the parent.
 void write(ExceptionlessOutputStream out)
          Writes a binary representation of the lexicon.
 
Methods inherited from class LBJ2.learn.Lexicon
clone, contains, countFeatures, discardPrunedFeatures, equals, getCountPolicy, getCutoff, getMap, hashCode, incrementCount, isPruned, isPruned, lazyMapCreation, lookup, lookup, lookup, lookupKey, main, perClassToGlobalCounts, prune, read, readLexicon, readLexicon, readLexicon, readLexicon, readLexicon, readPrunedSize, setEncoding, size, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

parents

private IVector parents
The elements of this vector (which correspond to the features in Lexicon.lexiconInv) serve a dual purpose; first, to indicate by absolute value the number of other features currently stored in this object that have the corresponding feature as a child, and second, to indicate by sign if the corresponding feature has been marked for removal.


parentLexicon

private Lexicon parentLexicon
A reference to the lexicon that uses this lexicon as its child lexicon.

Constructor Detail

ChildLexicon

public ChildLexicon()
Creates an empty lexicon.


ChildLexicon

public ChildLexicon(Lexicon p)
Creates an empty lexicon.

Parameters:
p - The lexicon that uses this lexicon as its child lexicon.

ChildLexicon

public ChildLexicon(Lexicon p,
                    java.lang.String e)
Creates an empty lexicon with the given encoding.

Parameters:
p - The lexicon that uses this lexicon as its child lexicon.
e - The encoding to use when adding features to this lexicon.
Method Detail

clear

public void clear()
Clears the data structures associated with this instance.

Overrides:
clear in class Lexicon

setParent

public void setParent(Lexicon p)
Sets the value of parentLexicon and makes sure that any features marked for removal in this lexicon are the identical objects also present in the parent. This is useful in particular just after lexicons have been read from disk.

Parameters:
p - The new parent lexicon.

remove

public Feature remove(Feature f)
Removes the mapping for the given feature from this lexicon and returns the feature object representing it that was stored here.

Parameters:
f - The feature to remove.
Returns:
The representation of f that used to be stored here, or null if it wasn't present.

decrementParentCounts

public void decrementParentCounts(Feature f)
The parent of feature f is being removed, so we decrement f's parent counts and remove it if it's ready.

Parameters:
f - The child feature whose parent counts need updating and which may be removed as well.

getChildFeature

public Feature getChildFeature(Feature f,
                               int label)
This method adds the given feature to this lexicon and also recursively adds its children, if any.

Overrides:
getChildFeature in class Lexicon
Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.
Returns:
A feature equivalent to f that is stored in this lexicon.

childLexiconLookup

public int childLexiconLookup(Feature f,
                              int label)
Updates the counts in parents for the children of f.

Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.
Returns:
The index of f in this lexicon.

childLexiconLookup

public int childLexiconLookup(DiscreteConjunctiveFeature f,
                              int label)
Updates the counts in parents for the children of f.

Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.
Returns:
The index of f in this lexicon.

childLexiconLookup

public int childLexiconLookup(RealConjunctiveFeature f,
                              int label)
Updates the counts in parents for the children of f.

Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.
Returns:
The index of f in this lexicon.

childLexiconLookup

public int childLexiconLookup(DiscreteReferrer f,
                              int label)
Updates the counts in parents for the children of f.

Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.
Returns:
The index of f in this lexicon.

childLexiconLookup

public int childLexiconLookup(RealReferrer f,
                              int label)
Updates the counts in parents for the children of f.

Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.
Returns:
The index of f in this lexicon.

incrementParentCounts

protected void incrementParentCounts(Feature f,
                                     int label)
Helper method for methods like childLexiconLookup(DiscreteConjunctiveFeature,int) that actually does the work of looking up the child feature and updating its parent counts.

Parameters:
f - The feature to look up.
label - The label of the example containing this feature, or -1 if we aren't doing per class feature counting.

lookupChild

public int lookupChild(Feature f)
Unlike the overridden method in Lexicon, this method simply checks Lexicon.lexicon for the feature and will throw an exception if it can't be found.

Overrides:
lookupChild in class Lexicon
Parameters:
f - The feature to look up.
Returns:
If the feature was found in Lexicon.lexicon, its associated integer index is returned.
Throws:
java.lang.UnsupportedOperationException - If the feature isn't found anywhere in the lexicon.

write

public void write(ExceptionlessOutputStream out)
Writes a binary representation of the lexicon.

Overrides:
write in class Lexicon
Parameters:
out - The output stream.

read

public void read(ExceptionlessInputStream in,
                 boolean readCounts)
Reads a binary representation of the lexicon.

Overrides:
read in class Lexicon
Parameters:
in - The input stream.
readCounts - Whether or not to read the feature counts.

printCountTable

public void printCountTable(boolean p)
Produces on STDOUT a table of feature counts including a line indicating the position of Lexicon.pruneCutoff. It's probably not a good idea to call this method unless you know your lexicon is small.

Overrides:
printCountTable in class Lexicon
Parameters:
p - Whether or not to include package names in the output.