edu.cmu.sphinx.linguist
Class WordSequence

java.lang.Object
  extended byedu.cmu.sphinx.linguist.WordSequence

public 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.
 
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)
 Word getWord(int n)
          Returns the nth word in this sequence
static WordSequence getWordSequence(java.util.List list)
          Constructs a word sequence from the list of words
static WordSequence getWordSequence(Word[] words)
          Returns a WordSequence with the given word IDs.
 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.
 java.lang.String toText()
          Returns an English text form of this word sequence, e.g., "this is a".
 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.

Method Detail

getWordSequence

public static WordSequence getWordSequence(Word[] words)
Returns a WordSequence with the given word IDs.

Parameters:
words - the array of words for the sequence
Returns:
a WordSequence with the given words

getWordSequence

public static WordSequence getWordSequence(java.util.List list)
Constructs a word sequence from the list of words

Parameters:
list - the list of words
Returns:
a WordSequence for the given words

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].

Returns:
the string

toText

public java.lang.String toText()
Returns an English text form of this word sequence, e.g., "this is a".

Returns:
the English text form

hashCode

public int hashCode()
Calculates the hashcode for this 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

Parameters:
o - the object to compare this to
Returns:
true if the given object is equal to this object