Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.stanford.nlp.ling
Class Sentence<T extends HasWord>

    java.lang.Object
      java.util.AbstractCollection<E>
          java.util.AbstractList<E>
              java.util.ArrayList<T>
                  edu.stanford.nlp.ling.Sentence<T>

All Implemented Interfaces:
  Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess

    public class Sentence<T extends HasWord>

extends ArrayList<T>

Sentence holds a single sentence, and mediates 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`.

Author:
  Dan Klein, Christopher Manning (generified)
See Also:
  Serialized Form

Field Summary

Fields inherited from class java.util.AbstractList
`modCount`

Constructor Summary
`Sentence()` Constructs an empty sentence.
`Sentence(Collection<T> w)` Constructs a sentence from the input Collection.
`Sentence(int initialCapacity)` Constructs an empty list with the specified initial capacity.

Method Summary
`int` | `length()` A convenience method since we normally say sentences have a length.
`void` | `setWords(Collection<T> wordList)` Set the Sentence to this Collection of words.
`static Sentence<Word>` | `toSentence(List<String> lex)` Create a Sentence as a list of `Word` from a list of `String`.
`static Sentence<TaggedWord>` | `toSentence(List<String> lex, List<String> tags)` Create a Sentence as a list of `TaggedWord` from two lists of `String`, one for the words, and the second for the tags.
`static Sentence<Word>` | `toSentence(String... words)` Create a Sentence as a list of `Word` objects from an array of String objects.
`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, 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, 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, removeAll, retainAll, subList`

Constructor Detail

### Sentence

    public Sentence()

  Constructs an empty sentence.

### Sentence

    public Sentence(int initialCapacity)

  Constructs an empty list with the specified initial capacity.

  Parameters:
    `initialCapacity` - The initial sentence allocation size

### Sentence

    public Sentence(Collection<T> w)

  Constructs a sentence from the input Collection.

  Parameters:
    `w` - A Collection (interpreted as ordered) to make the sentence out of.

Method Detail

### toSentence

    public static Sentence<TaggedWord> toSentence(List<String> lex,
                                                  List<String> 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
  Returns:
    The Sentence

### toSentence

    public static Sentence<Word> toSentence(List<String> lex)

  Create a Sentence as a list of `Word` from a list of `String`.

  Parameters:
    `lex` - a list whose items are of type `String` and are the words
  Returns:
    The Sentence

### toSentence

    public static Sentence<Word> toSentence(String... words)

  Create a Sentence as a list of `Word` objects from an array of String objects.

  Parameters:
    `words` - The words to make it from
  Returns:
    The Sentence

### setWords

    public void setWords(Collection<T> wordList)

  Set the Sentence to this Collection of words.

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

### 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. It is equivalent to calling `toString(true)`

  Overrides:
    `toString` in class `AbstractCollection<T extends HasWord>`
  Returns:
    The sentence

### toString

    public String toString(boolean justValue)

  Returns the sentence as a string with a space between words. Designed to work robustly, even if the elements stored in the 'Sentence' are not of type Label.

  Parameters:
    `justValue` - If `true` and the elements are of type `Label`, return just the `value()` of the `Label` of each word; otherwise, call the `toString()` method on each item.
  Returns:
    The sentence in String form

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Stanford NLP Group