// Path: src/com/structed/data/entities/Example.java
// public abstract class Example {
// 
//     public String path;
//     private String label;
//     private int fold;
//     public int sizeOfVector;
// 
// 	//C'tor
// 	public Example() {
//         label = "";
//         sizeOfVector = 0;
// 	}
// 
// 	//===========GETTERS AND SETTERS=========//
// 	public Vector getFeatures(){return null;}
// 	public void setFeatures(Vector features){}
// 
//     public ArrayList<Vector> getFeatures2D(){return null;}
//     public void setFeatures2D(ArrayList<Vector> features){}
//     public ArrayList<Integer> getLabels2D(){return null;}
//     public void setLabels2D(ArrayList<Integer> rankLabels){}
// 
//     public String getLabel() {
//         return label;
//     }
//     public void setLabel(String label) {
//         this.label = label;
//     }
// 
//     public int getFold() { return fold; }
//     public void setFold(int fold) { this.fold = fold; }
// }


import com.structed.data.entities.Example;
import java.util.ArrayList;
import java.util.HashMap;
/*
 * The MIT License (MIT)
 *
 * StructED - Machine Learning Package for Structured Prediction
 *
 * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.structed.data;



/**
 * preforms caching for computing the feature functions
 * Can be used only at the vowel duration task at the moment
 */
public class CacheVowelData {

    private static HashMap<Integer, ArrayList<ArrayList<Double>>> cache = new HashMap<Integer, ArrayList<ArrayList<Double>>>();

    /**
     * get the cumulative value for a given feature from a given example
     * @param example the example to calculate the features for
     * @param frameIndex get the cumulative value until this index
     * @param featureNumber the feature number to get the cumulative data for
     * @return the cumulative value
     */
    public static double getCumulativeValue(Example example, int frameIndex, int featureNumber)
    {
        double res = 0;
        if(frameIndex <= 0)
            res = cache.get(example.hashCode()).get(0).get(featureNumber);
        else if(frameIndex >= cache.get(example.hashCode()).size())
            res = cache.get(example.hashCode()).get(cache.get(example.hashCode()).size()-1).get(featureNumber);
        else if(cache.containsKey(example.hashCode()))
            res = cache.get(example.hashCode()).get(frameIndex).get(featureNumber);

        return res;
    }

    /**
     * update the cache for the given example
     * @param example a given example to cache
     */
// Path: src/com/structed/data/entities/Example.java
// public abstract class Example {
// 
//     public String path;
//     private String label;
//     private int fold;
//     public int sizeOfVector;
// 
// 	//C'tor
// 	public Example() {
//         label = "";
//         sizeOfVector = 0;
// 	}
// 
// 	//===========GETTERS AND SETTERS=========//
// 	public Vector getFeatures(){return null;}
// 	public void setFeatures(Vector features){}
// 
//     public ArrayList<Vector> getFeatures2D(){return null;}
//     public void setFeatures2D(ArrayList<Vector> features){}
//     public ArrayList<Integer> getLabels2D(){return null;}
//     public void setLabels2D(ArrayList<Integer> rankLabels){}
// 
//     public String getLabel() {
//         return label;
//     }
//     public void setLabel(String label) {
//         this.label = label;
//     }
// 
//     public int getFold() { return fold; }
//     public void setFold(int fold) { this.fold = fold; }
// }


// Path: src/com/structed/data/CacheVowelData.java
import com.structed.data.entities.Example;
import java.util.ArrayList;
import java.util.HashMap;

/*
 * The MIT License (MIT)
 *
 * StructED - Machine Learning Package for Structured Prediction
 *
 * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.structed.data;



/**
 * preforms caching for computing the feature functions
 * Can be used only at the vowel duration task at the moment
 */
public class CacheVowelData {

    private static HashMap<Integer, ArrayList<ArrayList<Double>>> cache = new HashMap<Integer, ArrayList<ArrayList<Double>>>();

    /**
     * get the cumulative value for a given feature from a given example
     * @param example the example to calculate the features for
     * @param frameIndex get the cumulative value until this index
     * @param featureNumber the feature number to get the cumulative data for
     * @return the cumulative value
     */
    public static double getCumulativeValue(Example example, int frameIndex, int featureNumber)
    {
        double res = 0;
        if(frameIndex <= 0)
            res = cache.get(example.hashCode()).get(0).get(featureNumber);
        else if(frameIndex >= cache.get(example.hashCode()).size())
            res = cache.get(example.hashCode()).get(cache.get(example.hashCode()).size()-1).get(featureNumber);
        else if(cache.containsKey(example.hashCode()))
            res = cache.get(example.hashCode()).get(frameIndex).get(featureNumber);

        return res;
    }

    /**
     * update the cache for the given example
     * @param example a given example to cache
     */
    public static void updateCache(Example example)