ThreadSafePOSTaggerME (Apache OpenNLP Tools 2.5.9 API)
Description: declaration: package: opennlp.tools.postag, class: ThreadSafePOSTaggerME

# Class ThreadSafePOSTaggerME

java.lang.Object
opennlp.tools.postag.ThreadSafePOSTaggerME

All Implemented Interfaces:
  `AutoCloseable, Probabilistic, POSTagger`

@ThreadSafe public class ThreadSafePOSTaggerME extends Object implements POSTagger, Probabilistic, AutoCloseable
A thread-safe version of the `POSTaggerME`. Using it is completely transparent. You can use it in a single-threaded context as well, it only incurs a minimal overhead.

Note:
This implementation uses a `ThreadLocal`. Although the implementation is lightweight because the model is not duplicated, if you have many long-running threads, you may run into memory problems.

Be careful when using this in a Jakarta EE application, for example.

The user is responsible for clearing the `ThreadLocal` via calling `close()`.

See Also:
  - `POSTagger`
  - `POSTaggerME`
  - `Probabilistic`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ThreadSafePOSTaggerME(String language)`
  Initializes a `ThreadSafePOSTaggerME` by downloading a default model for a given `language`.
  `ThreadSafePOSTaggerME(String language, POSTagFormat format)`
  Initializes a `ThreadSafePOSTaggerME` by downloading a default model for a given `language`.
  `ThreadSafePOSTaggerME(POSModel model)`
  Initializes a `ThreadSafePOSTaggerME` with the specified `model`.
  `ThreadSafePOSTaggerME(POSModel model, POSTagFormat format)`
  Initializes a `ThreadSafePOSTaggerME` with the specified `model`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `double[]`
  `probs()`
  Retrieves the probabilities of the last decoded sequence.
  `String[]`
  `tag(String[] sentence)`
  Assigns the sentence of tokens pos tags.
  `String[]`
  `tag(String[] sentence, Object[] additionaContext)`
  Assigns the sentence of tokens pos tags.
  `Sequence[]`
  `topKSequences(String[] sentence)`
  Assigns the sentence the top-k `sequences`.
  `Sequence[]`
  `topKSequences(String[] sentence, Object[] additionaContext)`
  Assigns the sentence the top-k `sequences`.

  ### Methods inherited from class Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ThreadSafePOSTaggerME

    public ThreadSafePOSTaggerME(String language) throws IOException
    Initializes a `ThreadSafePOSTaggerME` by downloading a default model for a given `language`.
    Parameters:
      `language` - An ISO conform language code.
    Throws:
      `IOException` - Thrown if the model could not be downloaded or saved.

  - ### ThreadSafePOSTaggerME

    public ThreadSafePOSTaggerME(String language, POSTagFormat format) throws IOException
    Initializes a `ThreadSafePOSTaggerME` by downloading a default model for a given `language`.
    Parameters:
      `language` - An ISO conform language code.
      `format` - A valid `POSTagFormat`.
    Throws:
      `IOException` - Thrown if the model could not be downloaded or saved.

  - ### ThreadSafePOSTaggerME

    public ThreadSafePOSTaggerME(POSModel model)
    Initializes a `ThreadSafePOSTaggerME` with the specified `model`.
    Parameters:
      `model` - A valid `POSModel`.

  - ### ThreadSafePOSTaggerME

    public ThreadSafePOSTaggerME(POSModel model, POSTagFormat format)
    Initializes a `ThreadSafePOSTaggerME` with the specified `model`.
    Parameters:
      `model` - A valid `POSModel`.
      `format` - A valid `POSTagFormat`.

- ## Method Details

  - ### tag

    public String[] tag(String[] sentence)
    Description copied from interface: `POSTagger`
    Assigns the sentence of tokens pos tags.
    Specified by:
      `tag` in interface `POSTagger`
    Parameters:
      `sentence` - The sentence of tokens to be tagged.
    Returns:
      An array of pos tags for each token provided in `sentence`.

  - ### tag

    public String[] tag(String[] sentence, Object[] additionaContext)
    Description copied from interface: `POSTagger`
    Assigns the sentence of tokens pos tags.
    Specified by:
      `tag` in interface `POSTagger`
    Parameters:
      `sentence` - The sentence of tokens to be tagged.
      `additionaContext` - The context to provide additional information with.
    Returns:
      An array of pos tags for each token provided in `sentence`.

  - ### topKSequences

    public Sequence[] topKSequences(String[] sentence)
    Description copied from interface: `POSTagger`
    Assigns the sentence the top-k `sequences`.
    Specified by:
      `topKSequences` in interface `POSTagger`
    Parameters:
      `sentence` - The sentence of tokens to be tagged.
    Returns:
      An array of `sequences` for each token provided in `sentence`.

  - ### topKSequences

    public Sequence[] topKSequences(String[] sentence, Object[] additionaContext)
    Description copied from interface: `POSTagger`
    Assigns the sentence the top-k `sequences`.
    Specified by:
      `topKSequences` in interface `POSTagger`
    Parameters:
      `sentence` - The sentence of tokens to be tagged.
      `additionaContext` - The context to provide additional information with.
    Returns:
      An array of `sequences` for each token provided in `sentence`.

  - ### probs

    public double[] probs()
    Description copied from interface: `Probabilistic`
    Retrieves the probabilities of the last decoded sequence.
    Specified by:
      `probs` in interface `Probabilistic`
    Returns:
      An array with the same number of probabilities as tokens were sent to the computational method when it was last called.

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`