idl.tmt.representation
Class TermList

java.lang.Object
  |
  +--idl.tmt.representation.TermList
All Implemented Interfaces:
java.io.Serializable

public class TermList
extends java.lang.Object
implements java.io.Serializable

A simple term list that supports lookup of terms, termID's, and adding terms. Created on Mar 19, 2004

Author:
jelsas
See Also:
Serialized Form

Inner Class Summary
 class TermList.MakeNewMapsFunction
           
 
Field Summary
private  boolean modifyable
           
private static int TERM_UNKNOWN
           
private  java.util.HashMap termIDToTerm
           
private  java.util.HashMap termToTermID
           
 
Constructor Summary
TermList()
          Creates a new TermList
 
Method Summary
 int addTerm(java.lang.String term)
          Adds the term to the termlist, and returns the ID assigned to the newly added term.
 void applyFilter(TmtMatrix filterMatrix)
          Filters this TermList based on the given matrix.
 boolean containsTerm(java.lang.String term)
          Test whether the term is known to this termlist
 void deleteTermsAfterIndex(int index)
          Deletes the terms in the termlist with indexes greater than the specified index.
 java.lang.String getTerm(int termID)
          Gets the term corresponding to this term ID.
 int getTermID(java.lang.String term)
          Gets the integer term ID corresponding to this term.
 boolean isModifyable()
           
 void permuteTerms(int[] permutation)
          Permutes the indexes of the terms in the termlist based on the given index array.
static TermList readTermList(java.lang.String prefix)
           
 void setModifyable(boolean modifyable)
           
 int size()
          Returns the size of this this termlist.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

termToTermID

private java.util.HashMap termToTermID

termIDToTerm

private java.util.HashMap termIDToTerm

TERM_UNKNOWN

private static final int TERM_UNKNOWN

modifyable

private boolean modifyable
Constructor Detail

TermList

public TermList()
Creates a new TermList
Method Detail

setModifyable

public void setModifyable(boolean modifyable)

isModifyable

public boolean isModifyable()

readTermList

public static TermList readTermList(java.lang.String prefix)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException

getTermID

public int getTermID(java.lang.String term)
Gets the integer term ID corresponding to this term.
Parameters:
term - The term to look up
Returns:
the integer ID of this term, or -1 if the term is unknown.

getTerm

public java.lang.String getTerm(int termID)
Gets the term corresponding to this term ID.
Parameters:
termID - The term ID to look up
Returns:
The term, or null if the ID is unknown.

containsTerm

public boolean containsTerm(java.lang.String term)
Test whether the term is known to this termlist
Parameters:
term - The term to lookup
Returns:
True if the term is known, false otherwise

addTerm

public int addTerm(java.lang.String term)
Adds the term to the termlist, and returns the ID assigned to the newly added term. If this termlist is not modifyable, this method returns -1 and the term is not added. See the isModifyabl() method.
Parameters:
term - The term to add
Returns:
The ID of the term added, or -1 if the termlist is not modifyable.

size

public int size()
Returns the size of this this termlist.
Returns:
the number of terms stored in the term list.

toString

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

applyFilter

public void applyFilter(TmtMatrix filterMatrix)
                 throws BadDimensionException
Filters this TermList based on the given matrix. The matrix must be an M x N matrix where M is the number of terms existing in the TermList, N is the number of terms in the filtered TermList, and N <= M. The rows of this matrix represent the existing term ID, and the columns represent the new term ID. The matrix is non-zero where the old term ID is mapped to the new term ID.

permuteTerms

public void permuteTerms(int[] permutation)
                  throws BadDimensionException
Permutes the indexes of the terms in the termlist based on the given index array.
Parameters:
permutation -  
Throws:
BadDimensionException - Thrown if permutation.length != termToTermID.size().

deleteTermsAfterIndex

public void deleteTermsAfterIndex(int index)
Deletes the terms in the termlist with indexes greater than the specified index.
Parameters:
index - The last index to keep in the term list.