I downloaded stanford core nlp packages and tried to test it on my machine.
Using command: java -cp \"*\" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -f
You can do the following in your code:
String text = "I am feeling very sad and frustrated.";
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
<...>
Annotation annotation = pipeline.process(text);
List sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
System.out.println(sentiment + "\t" + sentence);
}
It will print the sentiment of the sentence and the sentence itself, e.g. "I am feeling very sad and frustrated.":
Negative I am feeling very sad and frustrated.