Class SentimentME

java.lang.Object
opennlp.tools.sentiment.SentimentME
All Implemented Interfaces:
SentimentDetector

public class SentimentME extends Object implements SentimentDetector
A SentimentDetector implementation for creating and using maximum-entropy-based Sentiment Analysis models.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • train

      public static SentimentModel train(String languageCode, ObjectStream<SentimentSample> samples, 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)
      Description copied from interface: SentimentDetector
      Conducts a sentiment prediction for the specifed sentence.
      Specified by:
      predict in interface SentimentDetector
      Parameters:
      sentence - The text to be analysed for its sentiment.
      Returns:
      The predicted sentiment.
    • predict

      public String predict(String[] tokens)
      Description copied from interface: SentimentDetector
      Conducts a sentiment prediction for the specifed sentence.
      Specified by:
      predict in interface SentimentDetector
      Parameters:
      tokens - The text to be analysed for its sentiment.
      Returns:
      The predicted sentiment.
    • 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.