Package opennlp.tools.sentdetect

# Class ThreadSafeSentenceDetectorME

java.lang.Object
opennlp.tools.sentdetect.ThreadSafeSentenceDetectorME

All Implemented Interfaces:
  `AutoCloseable`, `Probabilistic`, `SentenceDetector`

@ThreadSafe public class ThreadSafeSentenceDetectorME extends Object implements SentenceDetector, Probabilistic, AutoCloseable
A thread-safe version of `SentenceDetectorME`. 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:
  - `Probabilistic`
  - `SentenceDetector`
  - `SentenceDetectorME`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ThreadSafeSentenceDetectorME(String language)`
  Initializes a `ThreadSafeSentenceDetectorME` by downloading a default model for a given `language`.
  `ThreadSafeSentenceDetectorME(SentenceModel model)`
  Initializes a `ThreadSafeSentenceDetectorME` with the specified `model`.
  `ThreadSafeSentenceDetectorME(SentenceModel model, Dictionary abbDict)`
  Instantiates a `ThreadSafeSentenceDetectorME` with an existing `SentenceModel`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `double[]`
  `getSentenceProbabilities()`
  Deprecated.
  Use `probs()` instead.
  `double[]`
  `probs()`
  Retrieves the probabilities of the last decoded sequence.
  `String[]`
  `sentDetect(CharSequence s)`
  Detects sentences in a character sequence.
  `Span[]`
  `sentPosDetect(CharSequence s)`
  Detects sentences in a character sequence.

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

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

- ## Constructor Details

  - ### ThreadSafeSentenceDetectorME

    public ThreadSafeSentenceDetectorME(String language) throws IOException
    Initializes a `ThreadSafeSentenceDetectorME` 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.

  - ### ThreadSafeSentenceDetectorME

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

  - ### ThreadSafeSentenceDetectorME

    public ThreadSafeSentenceDetectorME(SentenceModel model, Dictionary abbDict)
    Instantiates a `ThreadSafeSentenceDetectorME` with an existing `SentenceModel`.
    Parameters:
      `model` - The `SentenceModel` to be used.
      `abbDict` - The `Dictionary` to be used. It must fit the language of the `model`.

- ## Method Details

  - ### sentDetect

    public String[] sentDetect(CharSequence s)
    Description copied from interface: `SentenceDetector`
    Detects sentences in a character sequence.
    Specified by:
      `sentDetect` in interface `SentenceDetector`
    Parameters:
      `s` - The `CharSequence` for which sentences shall to be detected.
    Returns:
      The String[] with the individual sentences as the array elements.

  - ### sentPosDetect

    public Span[] sentPosDetect(CharSequence s)
    Description copied from interface: `SentenceDetector`
    Detects sentences in a character sequence.
    Specified by:
      `sentPosDetect` in interface `SentenceDetector`
    Parameters:
      `s` - The `CharSequence` for which sentences shall be detected.
    Returns:
      The array of `spans` (offsets into `s`) for each detected sentence as the individuals array elements.

  - ### getSentenceProbabilities

    @Deprecated public double[] getSentenceProbabilities()
    Deprecated.
    Use `probs()` instead.

  - ### 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`