package com.sentibrand;

import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;

import java.util.OptionalDouble;

import static edu.stanford.nlp.sentiment.SentimentCoreAnnotations.SentimentAnnotatedTree;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class SentimentProcessingService {

    private final StanfordCoreNLP pipeline = new StanfordCoreNLP();

    public OptionalDouble forText(String text) {
        return isNotBlank(text) ?
                averageSentiment(text) :
                OptionalDouble.empty();
    }

    private OptionalDouble averageSentiment(String text) {
        return pipeline.process(text)
                .get(SentencesAnnotation.class)
                .stream()
                .flatMapToDouble(coreMap -> coreMap.get(SentimentAnnotatedTree.class)
                        .stream()
                        .mapToInt(RNNCoreAnnotations::getPredictedClass)
                        .asDoubleStream())
                .average();
    }
}

@@ -188,16 +188,65 @@
 CoreNLP;
+%0Aimport org.springframework.stereotype.Component;
 %0A%0Aimport
@@ -427,16 +427,27 @@
 Blank;%0A%0A
+@Component%0A
 public c

Make Spring bean.