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:
  • Constructor Details

  • 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
      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.