// Path: Hadoop_Summit_Pig_for_Data_Science/src/test/java/com/caseystella/ds/util/ReservoirSampler.java
// public class ReservoirSampler<T> {
//     private final List<T> reservoir = new ArrayList<T>();
//     private final int numSamples;
// 
//     private final Random random;
//     private int numItemsSeen = 0;
// 
//     /**
//      * Create a new sampler with a certain reservoir size using
//      * a supplied random number generator.
//      *
//      * @param numSamples Maximum number of samples to
//      *                   retain in the reservoir. Must be non-negative.
//      * @param random Instance of the random number generator
//      *               to use for sampling
//      */
//     public ReservoirSampler(int numSamples, Random random) {
//         Preconditions.checkArgument(numSamples > 0,
//                 "numSamples should be positive");
//         Preconditions.checkNotNull(random);
//         this.numSamples = numSamples;
//         this.random = random;
//     }
// 
//     /**
//      * Create a new sampler with a certain reservoir size using
//      * the default random number generator.
//      *
//      * @param numSamples Maximum number of samples to
//      *        retain in the reservoir. Must be non-negative.
//      */
//     public ReservoirSampler(int numSamples) {
//         this(numSamples, new Random(0));
//     }
// 
//     /**
//      * Sample an item and store in the reservoir if needed.
//      *
//      * @param item The item to sample - may not be null.
//      */
//     public void sample(T item) {
//         Preconditions.checkNotNull(item);
//         if (reservoir.size() < numSamples) {
//             // reservoir not yet full, just append
//             reservoir.add(item);
//         } else {
//             // find a sample to replace
//             int rIndex = random.nextInt(numItemsSeen + 1);
//             if (rIndex < numSamples) {
//                 reservoir.set(rIndex, item);
//             }
//         }
//         numItemsSeen++;
//     }
// 
//     /**
//      * Get samples collected in the reservoir.
//      *
//      * @return A sequence of the samples. No guarantee is provided on the order of the samples.
//      */
//     public Iterable<T> getSamples() {
//         return reservoir;
//     }
// }


import com.caseystella.ds.util.ReservoirSampler;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.util.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.util.EnumMap;
import java.util.List;
package com.caseystella.ds.nlp;



/**
 * Created by cstella on 3/21/14.
 */
public class SentimentAnalysisTest
{
    private static Iterable<String> readFile(String filename) throws IOException {
        return Splitter.on('\n').split(IOUtils.slurpFile(filename));
    }
    private static int[][] initializeConfusionMatrix()
    {
        int numClasses = SentimentClass.values().length;
        int[][] confusionMatrix = new int[numClasses][numClasses];
        for(int i = 0;i < numClasses;++i)
        {
            for(int j = 0;j < numClasses;++j)
            {
                confusionMatrix[i][j] = 0;
            }
        }
        return confusionMatrix;
    }

    @Test
    public void testIMDBSentimentAnalysis() throws Exception
    {
        int[][] confusionMatrix  = initializeConfusionMatrix();
        int totalNumDocs = 100;
// Path: Hadoop_Summit_Pig_for_Data_Science/src/test/java/com/caseystella/ds/util/ReservoirSampler.java
// public class ReservoirSampler<T> {
//     private final List<T> reservoir = new ArrayList<T>();
//     private final int numSamples;
// 
//     private final Random random;
//     private int numItemsSeen = 0;
// 
//     /**
//      * Create a new sampler with a certain reservoir size using
//      * a supplied random number generator.
//      *
//      * @param numSamples Maximum number of samples to
//      *                   retain in the reservoir. Must be non-negative.
//      * @param random Instance of the random number generator
//      *               to use for sampling
//      */
//     public ReservoirSampler(int numSamples, Random random) {
//         Preconditions.checkArgument(numSamples > 0,
//                 "numSamples should be positive");
//         Preconditions.checkNotNull(random);
//         this.numSamples = numSamples;
//         this.random = random;
//     }
// 
//     /**
//      * Create a new sampler with a certain reservoir size using
//      * the default random number generator.
//      *
//      * @param numSamples Maximum number of samples to
//      *        retain in the reservoir. Must be non-negative.
//      */
//     public ReservoirSampler(int numSamples) {
//         this(numSamples, new Random(0));
//     }
// 
//     /**
//      * Sample an item and store in the reservoir if needed.
//      *
//      * @param item The item to sample - may not be null.
//      */
//     public void sample(T item) {
//         Preconditions.checkNotNull(item);
//         if (reservoir.size() < numSamples) {
//             // reservoir not yet full, just append
//             reservoir.add(item);
//         } else {
//             // find a sample to replace
//             int rIndex = random.nextInt(numItemsSeen + 1);
//             if (rIndex < numSamples) {
//                 reservoir.set(rIndex, item);
//             }
//         }
//         numItemsSeen++;
//     }
// 
//     /**
//      * Get samples collected in the reservoir.
//      *
//      * @return A sequence of the samples. No guarantee is provided on the order of the samples.
//      */
//     public Iterable<T> getSamples() {
//         return reservoir;
//     }
// }


// Path: Hadoop_Summit_Pig_for_Data_Science/src/test/java/com/caseystella/ds/nlp/SentimentAnalysisTest.java
import com.caseystella.ds.util.ReservoirSampler;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.util.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.util.EnumMap;
import java.util.List;

package com.caseystella.ds.nlp;



/**
 * Created by cstella on 3/21/14.
 */
public class SentimentAnalysisTest
{
    private static Iterable<String> readFile(String filename) throws IOException {
        return Splitter.on('\n').split(IOUtils.slurpFile(filename));
    }
    private static int[][] initializeConfusionMatrix()
    {
        int numClasses = SentimentClass.values().length;
        int[][] confusionMatrix = new int[numClasses][numClasses];
        for(int i = 0;i < numClasses;++i)
        {
            for(int j = 0;j < numClasses;++j)
            {
                confusionMatrix[i][j] = 0;
            }
        }
        return confusionMatrix;
    }

    @Test
    public void testIMDBSentimentAnalysis() throws Exception
    {
        int[][] confusionMatrix  = initializeConfusionMatrix();
        int totalNumDocs = 100;
        ReservoirSampler<String> positiveReservoir = new ReservoirSampler<String>(totalNumDocs/2);