Sentiment Analysis is the process of determining whether a piece of writing is positive, negative or neutral. It’s also known as opinion mining, deriving the opinion or attitude of a speaker.

In this article, we will discuss Stanford Sentiment analysis with an example.

Stanford Sentiment analysis builds on a new type of Recursive Neural Network that builds on top of grammatical structures.

Classes of sentiment classification

There are 5 classes of sentiment classification:

  1. very negative
  2. negative,
  3. neutral,
  4. positive,
  5.  very positive.


Need to add tokenize,ssplit , parse and sentiment annotators to get sentiment of a given text.

Properties props = new Properties();
     props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
     StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

     // negativeText
     // String text = "This movie doesn't care about cleverness, wit or any other kind of intelligent humor.";
     //Positive text
     //String text = "This movie is very good. I appriciate the way all the actors works.";
     //very positive text
     String text = "This movie is very good and one of my best movie. actors does best works.";
     int mainSentiment = 0;
     Annotation annotation = pipeline.process(text);
     int longest = 0;
     for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
         Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
         int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
         String partText = sentence.toString();
         if (partText.length() > longest) {
             mainSentiment = sentiment;
             longest = partText.length();
     switch (mainSentiment){
         case 0:
             System.out.println("Very Negative");
         case 1:
         case 2:
         case 3:
         case 4:
             System.out.println("Very Positive");


This movie is very good and one of my best movie. actors does best works.
Very Positive

Refer Live Demo , Deep Learning for more details.

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.

Leave a Reply

Your email address will not be published. Required fields are marked *