edu.stanford.nlp.simple.SentimentClass Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-corenlp Show documentation
Show all versions of stanford-corenlp Show documentation
Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.
package edu.stanford.nlp.simple;
import java.util.NoSuchElementException;
/**
* An enum for the Simple CoreNLP API to represent a sentiment value.
*
* @author Gabor Angeli
*/
public enum SentimentClass {
VERY_POSITIVE,
POSITIVE,
NEUTRAL,
NEGATIVE,
VERY_NEGATIVE,
;
public boolean isPositive() {
return this == VERY_POSITIVE || this == POSITIVE;
}
public boolean isNegative() {
return this == VERY_NEGATIVE || this == NEGATIVE;
}
public boolean isExtreme() {
return this == VERY_NEGATIVE || this == VERY_POSITIVE;
}
public boolean isMild() {
return !isExtreme();
}
public boolean isNeutral() {
return this == NEUTRAL;
}
/**
* Get the sentiment class from the Stanford Sentiment Treebank
* integer encoding. That is, an integer between 0 and 4 (inclusive)
*
* @param sentiment The Integer representation of a sentiment.
*
* @return The sentiment class associated with that integer.
*/
public static SentimentClass fromInt(int sentiment) {
switch (sentiment) {
case 0:
return VERY_NEGATIVE;
case 1:
return NEGATIVE;
case 2:
return NEUTRAL;
case 3:
return POSITIVE;
case 4:
return VERY_POSITIVE;
default:
throw new NoSuchElementException("No sentiment value for integer: " + sentiment);
}
}
}