I'm trying to get a sentimental score for live tweets using Stanford Core NLP. Currently I'm getting the real-time tweets. But when I feed it to the Stanford Core NLP program i'm getting an error.
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;
public class NLP {
static StanfordCoreNLP pipeline;
public static void init() {
pipeline = new StanfordCoreNLP("MyPropFile.properties");
}
public static int findSentiment(String tweet) {
int mainSentiment = 0;
if (tweet != null && tweet.length() > 0) {
int longest = 0;
Annotation annotation = pipeline.process(tweet);
for (CoreMap sentence : annotation
.get(CoreAnnotations.SentencesAnnotation.class)) {
Tree tree = sentence
.get(SentimentCoreAnnotations.AnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
String partText = sentence.toString();
if (partText.length() > longest) {
mainSentiment = sentiment;
longest = partText.length();
}
}
}
return mainSentiment;
}
}
I'm calling to this init() and findSentiment() functions from outside the class NLP.
NLP.init();
System.out.println(status.getText() + " : " + NLP.findSentiment(status.getText()));
My error is: SentimentCoreAnnotations.AnnotatedTree cannot be resolved to a type
Try changing
Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
to
Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);