## edu.stanford.nlp.ling
Class Sentence

    java.lang.Object
      edu.stanford.nlp.ling.Sentence

    public class Sentence

extends Object

Sentence holds a couple utility methods for lists. Those include a method that nicely prints a list and methods that construct lists of words from lists of strings.

Author:
  Dan Klein, Christopher Manning (generified), John Bauer

Method Summary

`static

`<T> String`

`

`extractNgram(List<T> list, int start, int end)`
Returns the substring of the sentence from start (inclusive) to end (exclusive).

`static

`<T> String`

`

`listToString(List<T> list)`
Returns the sentence as a string with a space between words.

`static

`<T> String`

`

`listToString(List<T> list, boolean justValue)`
Returns the sentence as a string with a space between words.

`static

`<T> String`

`

`listToString(List<T> list, boolean justValue, String separator)`
As already described, but if separator is not null, then objects such as TaggedWord

`static ArrayList<TaggedWord>` `toTaggedList(List<String> lex, List<String> tags)` Create an ArrayList as a list of `TaggedWord` from two lists of `String`, one for the words, and the second for the tags.
`static ArrayList<Word>` `toUntaggedList(List<String> lex)` Create an ArrayList as a list of `Word` from a list of `String`.
`static ArrayList<Word>` `toUntaggedList(String... words)` Create a Sentence as a list of `Word` objects from an array of String objects.
`static List<HasWord>` `toWordList(List<String> lex)`
`static List<HasWord>` `toWordList(String... words)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### toTaggedList

    public static ArrayList<TaggedWord> toTaggedList(List<String> lex,
                                                     List<String> tags)

  Create an ArrayList 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

### toUntaggedList

    public static ArrayList<Word> toUntaggedList(List<String> lex)

  Create an ArrayList 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

### toWordList

    public static List<HasWord> toWordList(List<String> lex)

### toUntaggedList

    public static ArrayList<Word> toUntaggedList(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

### toWordList

    public static List<HasWord> toWordList(String... words)

### listToString

    public static <T> String listToString(List<T> list)

  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)` TODO: Sentence used to be a subclass of ArrayList, with this method as the toString. Therefore, there may be instances of ArrayList being printed that expect this method to be used.

  Returns:
    The sentence

### listToString

    public static <T> String listToString(List<T> list,
                                          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. This one uses the default separators for any word type that uses separators, such as TaggedWord.

  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

### listToString

    public static <T> String listToString(List<T> list,
                                          boolean justValue,
                                          String separator)

  As already described, but if separator is not null, then objects such as TaggedWord

  Parameters:
    `separator` - The string used to separate Word and Tag in TaggedWord, etc

### extractNgram

    public static <T> String extractNgram(List<T> list,
                                          int start,
                                          int end)

  Returns the substring of the sentence from start (inclusive) to end (exclusive).

  Parameters:
    `start` - Leftmost index of the substring
    `end` - Rightmost index of the ngram
  Returns:
    The ngram as a String

Stanford NLP Group