use of edu.stanford.nlp.pipeline.StanfordCoreNLP in project neo4j-nlp-stanfordnlp by graphaware.
the class StanfordTextProcessor method sentiment.
@Override
public AnnotatedText sentiment(AnnotatedText annotatedText) {
StanfordCoreNLP pipeline = pipelines.get(SENTIMENT);
if (pipeline == null) {
throw new RuntimeException("Pipeline: " + SENTIMENT + " doesn't exist");
}
annotatedText.getSentences().parallelStream().forEach((item) -> {
Annotation document = new Annotation(item.getSentence());
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
Optional<CoreMap> sentence = sentences.stream().findFirst();
if (sentence != null && sentence.isPresent()) {
extractSentiment(sentence.get(), item);
}
});
return annotatedText;
}
Aggregations