How do you find the aggregated sense of several sentences / paragraph / large passage of text.
I have the following code below, which I based on the github Stanford CoreNLP tests and various examples, but everything I found completed the sentiment analysis, only calculates the mood for individual sentences. But I want the overall mood of the tweet to be independent of the number of sentences.
The only way I can do this is to create a separate thread for SentimentPipeline.main(String[])and load the text in stdinand collect a common opinion in sdout. I would rather just use my code to make it simpler / more efficient, but I did not find anything.
In addition, I don’t want to make a system call at the bank, as most people do, since I will make millions of tweets per day. The overhead will be too large, loading resources every time.
Annotation document = new Annotation(text);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
String output;
for (CoreMap sentence : sentences) {
output = "";
for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
String word = token.get(TextAnnotation.class);
String ne = token.get(NamedEntityTagAnnotation.class);
if (!ne.contentEquals("O")) {
output = output + (ne + " " + word + " ");
}
}
Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
String sentiment = RNNCoreAnnotations.getPredictedClass(tree);
source
share