// Path: Hadoop_Summit_Pig_for_Data_Science/src/main/java/com/caseystella/ds/nlp/SentimentClass.java
// public enum SentimentClass {
//     VERY_NEGATIVE(0)
//    , NEGATIVE(1)
//    , NEUTRAL(2)
//    , POSITIVE(3)
//    , VERY_POSITIVE(4)
//     ;
//     private int index = -1;
//     SentimentClass(int idx)
//     {
//         index = idx;
//     }
//     public int getIndex() { return index;}
//     public static SentimentClass getSpecific(int sentimentClass)
//     {
//         return SentimentClass.values()[sentimentClass];
//     }
// 
//     public static SentimentClass getGeneral(int sentimentClass)
//     {
//         //remove the extreme cases
//         if(sentimentClass == 0) sentimentClass = 1;
//         if(sentimentClass == 4) sentimentClass = 3;
//         return SentimentClass.values()[sentimentClass];
//     }
// }


import com.caseystella.ds.nlp.SentimentClass;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import edu.stanford.nlp.ie.machinereading.structure.AnnotationUtils;
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;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;
import org.ejml.simple.SimpleMatrix;
import java.io.*;
import java.util.*;
package com.caseystella.ds.nlp.rollup.util;



/**
 * This generates training data for the rollup approach analysis
 *
 * @see com.caseystella.ds.nlp.rollup.util.EvaluateRollupApproaches
 */
public class GenerateTrainingData
{

    private static List<Map.Entry<String, String>> getSentiment(StanfordCoreNLP pipeline, String document)
    {
        List<Map.Entry<String, String>> ret = new ArrayList<Map.Entry<String, String>>();


        Annotation annotation = pipeline.process(document);
        /*
         * We're going to iterate over all of the sentences and extract the sentiment.  We'll adopt a majority rule policy
         */
        for( CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class))
        {
            //for each sentence, we get the sentiment annotation
            //this comes in the form of a tree of annotations
            Tree sentimentTree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
            //Letting CoreNLP roll up the sentiment for us
            int sentimentClassIdx = RNNCoreAnnotations.getPredictedClass(sentimentTree);
            //now we add to our list of sentences and sentiments
// Path: Hadoop_Summit_Pig_for_Data_Science/src/main/java/com/caseystella/ds/nlp/SentimentClass.java
// public enum SentimentClass {
//     VERY_NEGATIVE(0)
//    , NEGATIVE(1)
//    , NEUTRAL(2)
//    , POSITIVE(3)
//    , VERY_POSITIVE(4)
//     ;
//     private int index = -1;
//     SentimentClass(int idx)
//     {
//         index = idx;
//     }
//     public int getIndex() { return index;}
//     public static SentimentClass getSpecific(int sentimentClass)
//     {
//         return SentimentClass.values()[sentimentClass];
//     }
// 
//     public static SentimentClass getGeneral(int sentimentClass)
//     {
//         //remove the extreme cases
//         if(sentimentClass == 0) sentimentClass = 1;
//         if(sentimentClass == 4) sentimentClass = 3;
//         return SentimentClass.values()[sentimentClass];
//     }
// }


// Path: Hadoop_Summit_Pig_for_Data_Science/src/main/java/com/caseystella/ds/nlp/rollup/util/GenerateTrainingData.java
import com.caseystella.ds.nlp.SentimentClass;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import edu.stanford.nlp.ie.machinereading.structure.AnnotationUtils;
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;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;
import org.ejml.simple.SimpleMatrix;
import java.io.*;
import java.util.*;

package com.caseystella.ds.nlp.rollup.util;



/**
 * This generates training data for the rollup approach analysis
 *
 * @see com.caseystella.ds.nlp.rollup.util.EvaluateRollupApproaches
 */
public class GenerateTrainingData
{

    private static List<Map.Entry<String, String>> getSentiment(StanfordCoreNLP pipeline, String document)
    {
        List<Map.Entry<String, String>> ret = new ArrayList<Map.Entry<String, String>>();


        Annotation annotation = pipeline.process(document);
        /*
         * We're going to iterate over all of the sentences and extract the sentiment.  We'll adopt a majority rule policy
         */
        for( CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class))
        {
            //for each sentence, we get the sentiment annotation
            //this comes in the form of a tree of annotations
            Tree sentimentTree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
            //Letting CoreNLP roll up the sentiment for us
            int sentimentClassIdx = RNNCoreAnnotations.getPredictedClass(sentimentTree);
            //now we add to our list of sentences and sentiments
            SentimentClass sentimentClass = SentimentClass.getGeneral(sentimentClassIdx);