Package opennlp.tools.postag

# Class POSDictionary

java.lang.Object
opennlp.tools.postag.POSDictionary

All Implemented Interfaces:
  `Iterable<String>`, `opennlp.tools.postag.MutableTagDictionary`, `opennlp.tools.postag.TagDictionary`, `opennlp.tools.util.model.SerializableArtifact`

public class POSDictionary extends Object implements Iterable<String>, opennlp.tools.postag.MutableTagDictionary, opennlp.tools.util.model.SerializableArtifact
Provides a means of determining which tags are valid for a particular word based on a `TagDictionary` read from a file.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `POSDictionary()`
  Initializes an empty case sensitive `POSDictionary`.
  `POSDictionary(boolean caseSensitive)`
  Initializes an empty `POSDictionary`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static POSDictionary`
  `create(InputStream in)`
  Creates a new `POSDictionary` from an `InputStream`.
  `boolean`
  `equals(Object obj)`
  `Class<?>`
  `getArtifactSerializerClass()`
  `String[]`
  `getTags(String word)`
  Returns a list of valid tags for the specified `word`.
  `int`
  `hashCode()`
  `boolean`
  `isCaseSensitive()`
  `Iterator<String>`
  `iterator()`
  Retrieves an `Iterator` over all words in the dictionary.
  `String[]`
  `put(String word, String... tags)`
  `void`
  `serialize(OutputStream out)`
  Writes the `POSDictionary` to the given `OutputStream`;
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.lang.Iterable

  `forEach, spliterator`

- ## Constructor Details

  - ### POSDictionary

    public POSDictionary()
    Initializes an empty case sensitive `POSDictionary`.

  - ### POSDictionary

    public POSDictionary(boolean caseSensitive)
    Initializes an empty `POSDictionary`.
    Parameters:
      `caseSensitive` - `true` if the `POSDictionary` is case sensitive, `false` otherwise.

- ## Method Details

  - ### getTags

    public String[] getTags(String word)
    Returns a list of valid tags for the specified `word`.
    Specified by:
      `getTags` in interface `opennlp.tools.postag.TagDictionary`
    Parameters:
      `word` - The word.
    Returns:
      An array of valid tags for the specified word or `null` if no information is available for that word.

  - ### iterator

    public Iterator<String> iterator()
    Retrieves an `Iterator` over all words in the dictionary.
    Specified by:
      `iterator` in interface `Iterable<String>`

  - ### serialize

    public void serialize(OutputStream out) throws IOException
    Writes the `POSDictionary` to the given `OutputStream`;

    After the serialization is finished the provided `OutputStream` remains open.

    Parameters:
      `out` - the `OutputStream` to write the dictionary into.
    Throws:
      `IOException` - Throw if writing to the `OutputStream` fails

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### create

    public static POSDictionary create(InputStream in) throws IOException
    Creates a new `POSDictionary` from an `InputStream`.

    After creation is finished the provided `InputStream` is closed.

    Parameters:
      `in` - The `InputStream` used for creating the `POSDictionary`. The stream must be open and have bytes available to read from.
    Returns:
      A valid `POSDictionary` instance.
    Throws:
      `IOException` - Thrown if IO errors occurred during creation.
      `opennlp.tools.util.InvalidFormatException` - Thrown if the entries don't have exactly one token.

  - ### put

    public String[] put(String word, String... tags)
    Specified by:
      `put` in interface `opennlp.tools.postag.MutableTagDictionary`

  - ### isCaseSensitive

    public boolean isCaseSensitive()
    Specified by:
      `isCaseSensitive` in interface `opennlp.tools.postag.TagDictionary`

  - ### getArtifactSerializerClass

    public Class<?> getArtifactSerializerClass()
    Specified by:
      `getArtifactSerializerClass` in interface `opennlp.tools.util.model.SerializableArtifact`