// 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/ISentimentRollup.java
// public interface ISentimentRollup extends Function<List<Sentence>, SentimentClass>
// {
// 
// }
// 
// Path: Hadoop_Summit_Pig_for_Data_Science/src/main/java/com/caseystella/ds/nlp/rollup/Sentence.java
// public class Sentence {
//     private EnumMap<SentimentClass, Double> sentimentProbabilities;
//     private String sentence;
//     private SentimentClass sentimentClass;
// 
//     public Sentence( double[] sentimentProbabilities
//                    , String sentence
//                    , SentimentClass sentimentClass
//                    )
//     {
//         this.sentence = sentence;
//         this.sentimentClass = sentimentClass;
//         this.sentimentProbabilities = new EnumMap<SentimentClass, Double>(SentimentClass.class);
//         for(int i = 0;i < sentimentProbabilities.length;++i)
//         {
//             this.sentimentProbabilities.put(SentimentClass.values()[i], sentimentProbabilities[i]);
//         }
//     }
// 
//     public String getSentence() { return sentence;}
//     public EnumMap<SentimentClass, Double> getSentimentProbabilities() { return sentimentProbabilities;}
//     public SentimentClass getSentiment() { return sentimentClass;}
// }


import com.caseystella.ds.nlp.SentimentClass;
import com.caseystella.ds.nlp.rollup.ISentimentRollup;
import com.caseystella.ds.nlp.rollup.Sentence;
import java.util.List;
package com.caseystella.ds.nlp.rollup.strategy;



/**
 * Created by cstella on 3/25/14.
 */
public class AverageProbabilitiesRollup  implements ISentimentRollup {

    @Override
    public SentimentClass apply(List<Sentence> input)
    {
        double[] weights = new double[] {1, 1, 1, 1, 1};
        double[] probs = new double[SentimentClass.values().length];
        SentimentClass dominantClass = null;
        int idx = 0;
        for(Sentence inputSentence : input)
        {
            if(idx++ < input.size() / 2) continue;
            for(int i = 0;i < probs.length;++i)
            {
                probs[i] += weights[i] * inputSentence.getSentimentProbabilities().get(SentimentClass.values()[i]);
            }
        }
        double max = -1;
// 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/ISentimentRollup.java
// public interface ISentimentRollup extends Function<List<Sentence>, SentimentClass>
// {
// 
// }
// 
// Path: Hadoop_Summit_Pig_for_Data_Science/src/main/java/com/caseystella/ds/nlp/rollup/Sentence.java
// public class Sentence {
//     private EnumMap<SentimentClass, Double> sentimentProbabilities;
//     private String sentence;
//     private SentimentClass sentimentClass;
// 
//     public Sentence( double[] sentimentProbabilities
//                    , String sentence
//                    , SentimentClass sentimentClass
//                    )
//     {
//         this.sentence = sentence;
//         this.sentimentClass = sentimentClass;
//         this.sentimentProbabilities = new EnumMap<SentimentClass, Double>(SentimentClass.class);
//         for(int i = 0;i < sentimentProbabilities.length;++i)
//         {
//             this.sentimentProbabilities.put(SentimentClass.values()[i], sentimentProbabilities[i]);
//         }
//     }
// 
//     public String getSentence() { return sentence;}
//     public EnumMap<SentimentClass, Double> getSentimentProbabilities() { return sentimentProbabilities;}
//     public SentimentClass getSentiment() { return sentimentClass;}
// }


// Path: Hadoop_Summit_Pig_for_Data_Science/src/main/java/com/caseystella/ds/nlp/rollup/strategy/AverageProbabilitiesRollup.java
import com.caseystella.ds.nlp.SentimentClass;
import com.caseystella.ds.nlp.rollup.ISentimentRollup;
import com.caseystella.ds.nlp.rollup.Sentence;
import java.util.List;

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



/**
 * Created by cstella on 3/25/14.
 */
public class AverageProbabilitiesRollup  implements ISentimentRollup {

    @Override
    public SentimentClass apply(List<Sentence> input)
    {
        double[] weights = new double[] {1, 1, 1, 1, 1};
        double[] probs = new double[SentimentClass.values().length];
        SentimentClass dominantClass = null;
        int idx = 0;
        for(Sentence inputSentence : input)
        {
            if(idx++ < input.size() / 2) continue;
            for(int i = 0;i < probs.length;++i)
            {
                probs[i] += weights[i] * inputSentence.getSentimentProbabilities().get(SentimentClass.values()[i]);
            }
        }
        double max = -1;
        for(int i = 0;i < probs.length;++i)