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.

Example:

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();
         }
     }
     System.out.println(text);
     switch (mainSentiment){
         case 0:
             System.out.println("Very Negative");
             break;
         case 1:
             System.out.println("Negative");
             break;
         case 2:
             System.out.println("Neutral");
             break;
         case 3:
             System.out.println("Positive");
             break;
         case 4:
             System.out.println("Very Positive");
             break;
     }
 }

Output:

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.
Yes
No

Leave a Reply

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