You can do the following in your code:
String text = "I am feeling very upset" Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); <...> Annotation annotation = pipeline.process(text); List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { String sentiment = sentence.get(SentimentCoreAnnotations.ClassName.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.
Read full article from java - Executing and testing stanford core nlp example - Stack Overflow
No comments:
Post a Comment