edu.cmu.sphinx.linguist
Class WordSequence

java.lang.Object
  extended by edu.cmu.sphinx.linguist.WordSequence

public final class WordSequence
extends java.lang.Object

This class can be used to keep track of a word sequence. This class is an immutable class. It can never be modified once it is created (except, perhaps for transient, cached things such as a precalculated hashcode).


Field Summary
static WordSequence EMPTY
          an empty word sequence, that is, it has no words.
 
Constructor Summary
WordSequence(java.util.List<Word> list)
          Constructs a word sequence from the list of words
WordSequence(Word[] words)
          Constructs a word sequence with the given word IDs
 
Method Summary
 WordSequence addWord(Word word, int maxSize)
          Returns a new word sequence with the given word added to the sequence
 boolean equals(java.lang.Object o)
          compares the given object to see if it is identical to this WordSequence
 WordSequence getNewest()
          Returns the newest words in the sequence (the old word is omitted)
 WordSequence getOldest()
          Returns the oldest words in the sequence (the newest word is omitted)
 WordSequence getSubSequence(int startIndex, int stopIndex)
          Returns a subsequence with both startIndex and stopIndex exclusive.
 Word getWord(int n)
          Returns the nth word in this sequence
 Word[] getWords()
          Returns the words of the WordSequence.
 int hashCode()
          Calculates the hashcode for this object
 int size()
          Returns the number of words in this sequence
 java.lang.String toString()
          Returns a string represntation of this word sequence.
 WordSequence trim(int maxSize)
          Returns a word sequence that is no longer than the given size, that is filled in with the newest words from this sequence
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final WordSequence EMPTY
an empty word sequence, that is, it has no words.

Constructor Detail

WordSequence

public WordSequence(Word[] words)
Constructs a word sequence with the given word IDs

Parameters:
words - the word IDs of the word sequence

WordSequence

public WordSequence(java.util.List<Word> list)
Constructs a word sequence from the list of words

Parameters:
list - the list of words
Method Detail

addWord

public WordSequence addWord(Word word,
                            int maxSize)
Returns a new word sequence with the given word added to the sequence

Parameters:
word - the word to add to the sequence
maxSize - the maximum size of the generated sequence
Returns:
a new word sequence with the word added (but trimmed to maxSize).

getOldest

public WordSequence getOldest()
Returns the oldest words in the sequence (the newest word is omitted)

Returns:
the oldest words in the sequence, with the newest word omitted

getNewest

public WordSequence getNewest()
Returns the newest words in the sequence (the old word is omitted)

Returns:
the newest words in the sequence with the oldest word omitted

trim

public WordSequence trim(int maxSize)
Returns a word sequence that is no longer than the given size, that is filled in with the newest words from this sequence

Parameters:
maxSize - the maximum size of the sequence
Returns:
a new word sequence, trimmed to maxSize.

getWord

public Word getWord(int n)
Returns the nth word in this sequence

Parameters:
n - which word to return
Returns:
the nth word in this sequence

size

public int size()
Returns the number of words in this sequence

Returns:
the number of words

toString

public java.lang.String toString()
Returns a string represntation of this word sequence. The format is: [ID_0][ID_1][ID_2].

Overrides:
toString in class java.lang.Object
Returns:
the string

hashCode

public int hashCode()
Calculates the hashcode for this object

Overrides:
hashCode in class java.lang.Object
Returns:
a hascode for this object

equals

public boolean equals(java.lang.Object o)
compares the given object to see if it is identical to this WordSequence

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare this to
Returns:
true if the given object is equal to this object

getSubSequence

public WordSequence getSubSequence(int startIndex,
                                   int stopIndex)
Returns a subsequence with both startIndex and stopIndex exclusive.


getWords

public Word[] getWords()
Returns the words of the WordSequence.