edu.stanford.nlp.trees
Class Sentence

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--edu.stanford.nlp.trees.Sentence
All Implemented Interfaces:
Cloneable, Collection, List, RandomAccess, Serializable

public class Sentence
extends ArrayList

Sentence holds a single sentence, and mediating between word numbers and words. A sentence may contain a list of Word, or of a subtype, such as TaggedWord. A Sentence is just a slightly glorified ArrayList.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Sentence()
          Constructs an empty sentence.
Sentence(Collection w)
          Constructs a sentence from the input Collection.
Sentence(List lex, List tags)
          Create a Sentence as a list of TaggedWord from two lists of String, one for the words, and the second for the tags.
 
Method Summary
 Word getWord(int index)
          Return the Word at the given index.
 int length()
          A convenience method since we normally say sentences have a length.
 void setWords(Collection wordList)
          Set the Sentence to this Collection of Word's.
 String toString()
          Returns the sentence as a string with a space between words.
 String toString(boolean justValue)
          Returns the sentence as a string with a space between words.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

Sentence

public Sentence()
Constructs an empty sentence.


Sentence

public Sentence(Collection w)
Constructs a sentence from the input Collection.

Parameters:
w - A Collection (interpreted as ordered) to make the sentence out of. It should really be a Collection of Word's.

Sentence

public Sentence(List lex,
                List tags)
Create a Sentence as a list of TaggedWord from two lists of String, one for the words, and the second for the tags.

Parameters:
lex - a list whose items are of type String and are the words
tags - a list whose items are of type String and are the tags
Method Detail

setWords

public void setWords(Collection wordList)
Set the Sentence to this Collection of Word's.

Parameters:
wordList - A collection of words (interpreted as ordered

getWord

public Word getWord(int index)
Return the Word at the given index. Does type casting.

Parameters:
index - The index to use
Returns:
The word at this index

length

public int length()
A convenience method since we normally say sentences have a length. Same as size().

Returns:
the length of the sentence

toString

public String toString()
Returns the sentence as a string with a space between words. It strictly prints out the value() of each item - this will give the expected answer for a shortform representation of the "sentence" over a range of cases (including where the sentence is a list of tags or Strings). It is equivalent to calling toString(true)

Overrides:
toString in class AbstractCollection
Returns:
The sentence

toString

public String toString(boolean justValue)
Returns the sentence as a string with a space between words.

Parameters:
justValue - If true, return just the value() of the Label of each word; if false, call the toString() method on each Label
Returns:
The sentence


Stanford NLP Group