/**
 * 
 */
package org.openpreservation.sentiment;

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations.SentimentAnnotatedTree;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;

/**
 * @author cfw
 *
 */
public final class SentimentAnalyser {
    static StanfordCoreNLP PIPELINE = new StanfordCoreNLP("stanfordNLP.properties");

    /**
     * @param tweet
     * @return an integer value based on the tweet sentiment, higher numbers == happier tweet
     */
	public static int calculateSentiment(String tweet) {
		if (tweet == null) throw new NullPointerException("Tweet cannot be null.");
		if (tweet.length() == 0) throw new IllegalArgumentException("Tweet cannot be empty");

        int mainSentiment = 0;
        if (tweet != null && tweet.length() > 0) {
            int longest = 0;
            Annotation annotation = PIPELINE.process(tweet);
            for (CoreMap sentence : annotation
                    .get(CoreAnnotations.SentencesAnnotation.class)) {
                Tree tree = sentence
                        .get(SentimentAnnotatedTree.class);
                int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
                String partText = sentence.toString();
                if (partText.length() > longest) {
                    mainSentiment = sentiment;
                    longest = partText.length();
                }
            }
        }
        return mainSentiment;
    }
}

@@ -937,63 +937,8 @@
  0;%0A
-        if (tweet != null && tweet.length() %3E 0) %7B%0A    
     
@@ -966,20 +966,16 @@
         
-  
-  
 Annotati
@@ -1023,20 +1023,16 @@
         
-    
 for (Cor
@@ -1070,28 +1070,24 @@
             
- 
-   
 .get(CoreAnn
@@ -1121,28 +1121,24 @@
 n.class)) %7B%0A
-    
             
@@ -1174,28 +1174,24 @@
             
-    
 .get(Sentime
@@ -1222,28 +1222,24 @@
             
-   
- 
 int sentimen
@@ -1298,20 +1298,16 @@
         
-    
 String p
@@ -1349,20 +1349,16 @@
         
-  
-  
 if (part
@@ -1400,20 +1400,16 @@
         
-    
 mainSent
@@ -1443,20 +1443,16 @@
         
- 
-   
 longest 
@@ -1476,26 +1476,8 @@
 ();%0A
-                %7D%0A
     

Update SentimentAnalyser.java