Package opennlp.tools.sentiment
Class SentimentME
java.lang.Object
opennlp.tools.sentiment.SentimentME
- All Implemented Interfaces:
SentimentDetector
A
SentimentDetector implementation for creating and using
maximum-entropy-based Sentiment Analysis models.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SentimentContextGeneratorprivate final SentimentFactoryprivate final MaxentModel -
Constructor Summary
ConstructorsConstructorDescriptionSentimentME(SentimentModel sentModel) Instantiates aSentimentMEwith the specified model. -
Method Summary
Modifier and TypeMethodDescriptiongetBestSentiment(double[] outcome) Returns the best chosen sentiment for the given probability distribution.Conducts a sentiment prediction for the specifed sentence.Conducts a sentiment prediction for the specifed sentence.double[]probabilities(String[] text) Returns the probability distribution over sentiment labels for the given tokens.static SentimentModeltrain(String languageCode, ObjectStream<SentimentSample> samples, TrainingParameters trainParams, SentimentFactory factory) Trains aSentiment Analysis model.
-
Field Details
-
contextGenerator
-
factory
-
maxentModel
-
-
Constructor Details
-
SentimentME
Instantiates aSentimentMEwith the specified model.- Parameters:
sentModel- Thesentiment analysis modelto use. It must not benull.- Throws:
IllegalArgumentException- Thrown if parameters are invalid.
-
-
Method Details
-
train
public static SentimentModel train(String languageCode, ObjectStream<SentimentSample> samples, TrainingParameters trainParams, SentimentFactory factory) throws IOException Trains aSentiment Analysis model.- Parameters:
languageCode- the code for the language of the text, e.g. "en"samples- the sentiment samples to be usedtrainParams- parameters for trainingfactory- a Sentiment Analysis factory- Returns:
- A valid
SentimentModel. - Throws:
IOException- Thrown if IO errors occurred during training.
-
predict
Description copied from interface:SentimentDetectorConducts a sentiment prediction for the specifed sentence.- Specified by:
predictin interfaceSentimentDetector- Parameters:
sentence- The text to be analysed for its sentiment.- Returns:
- The predicted sentiment.
-
predict
Description copied from interface:SentimentDetectorConducts a sentiment prediction for the specifed sentence.- Specified by:
predictin interfaceSentimentDetector- Parameters:
tokens- The text to be analysed for its sentiment.- Returns:
- The predicted sentiment.
-
getBestSentiment
Returns the best chosen sentiment for the given probability distribution.- Parameters:
outcome- the probability distribution over outcomes.- Returns:
- the best sentiment label.
-
probabilities
Returns the probability distribution over sentiment labels for the given tokens.- Parameters:
text- the tokens to classify.- Returns:
- the probability distribution over sentiment labels.
-