Package opennlp.tools.sentiment

# Class SentimentME

java.lang.Object
opennlp.tools.sentiment.SentimentME

All Implemented Interfaces:
  `opennlp.tools.sentiment.SentimentDetector`

public class SentimentME extends Object implements opennlp.tools.sentiment.SentimentDetector
A `SentimentDetector` implementation for creating and using maximum-entropy-based Sentiment Analysis models.

See Also:
  - `SentimentModel`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SentimentME(SentimentModel sentModel)`
  Instantiates a `SentimentME` with the specified model.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getBestSentiment(double[] outcome)`
  Returns the best chosen sentiment for the given probability distribution.
  `String`
  `predict(String sentence)`
  `String`
  `predict(String[] tokens)`
  `double[]`
  `probabilities(String[] text)`
  Returns the probability distribution over sentiment labels for the given tokens.
  `static SentimentModel`
  `train(String languageCode, opennlp.tools.util.ObjectStream<opennlp.tools.sentiment.SentimentSample> samples, opennlp.tools.util.TrainingParameters trainParams, SentimentFactory factory)`
  Trains a `Sentiment Analysis model`.

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

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

- ## Constructor Details

  - ### SentimentME

    public SentimentME(SentimentModel sentModel)
    Instantiates a `SentimentME` with the specified model.
    Parameters:
      `sentModel` - The `sentiment analysis model` to use. It must not be `null`.
    Throws:
      `IllegalArgumentException` - Thrown if parameters are invalid.

- ## Method Details

  - ### train

    public static SentimentModel train(String languageCode, opennlp.tools.util.ObjectStream<opennlp.tools.sentiment.SentimentSample> samples, opennlp.tools.util.TrainingParameters trainParams, SentimentFactory factory) throws IOException
    Trains a `Sentiment Analysis model`.
    Parameters:
      `languageCode` - the code for the language of the text, e.g. "en"
      `samples` - the sentiment samples to be used
      `trainParams` - parameters for training
      `factory` - a Sentiment Analysis factory
    Returns:
      A valid `SentimentModel`.
    Throws:
      `IOException` - Thrown if IO errors occurred during training.

  - ### predict

    public String predict(String sentence)
    Specified by:
      `predict` in interface `opennlp.tools.sentiment.SentimentDetector`

  - ### predict

    public String predict(String[] tokens)
    Specified by:
      `predict` in interface `opennlp.tools.sentiment.SentimentDetector`

  - ### getBestSentiment

    public String getBestSentiment(double[] outcome)
    Returns the best chosen sentiment for the given probability distribution.
    Parameters:
      `outcome` - the probability distribution over outcomes.
    Returns:
      the best sentiment label.

  - ### probabilities

    public double[] probabilities(String[] text)
    Returns the probability distribution over sentiment labels for the given tokens.
    Parameters:
      `text` - the tokens to classify.
    Returns:
      the probability distribution over sentiment labels.