// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/IDistanceFunction.java
// public interface IDistanceFunction
// {
// 
//     /**
//      * Returns a distance value for the given pair of categories used within the given annotation
//      * study. Normally, the measure should return a distance of 0 if, and only if, the two
//      * categories are equal and a positive number otherwise.
//      */
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2);
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/IntervalDistanceFunction.java
// public class IntervalDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         if (category1 instanceof Integer && category2 instanceof Integer) {
//             return (((Integer) category1) - ((Integer) category2))
//                     * (((Integer) category1) - ((Integer) category2));
//         }
// 
//         if (category1 instanceof Double && category2 instanceof Double) {
//             return (((Double) category1) - ((Double) category2))
//                     * (((Double) category1) - ((Double) category2));
//         }
// 
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/NominalDistanceFunction.java
// public class NominalDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/OrdinalDistanceFunction.java
// public class OrdinalDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         if (category1 instanceof Integer && category2 instanceof Integer) {
//             if (category1.equals(category2)) {
//                 return 0.0;
//             }
// 
//             // TODO: Provide generic method for the annotation study w/ potential use for unitizing
//             // tasks!
//             Map<Object, Integer> nk = CodingAnnotationStudy
//                     .countTotalAnnotationsPerCategory((ICodingAnnotationStudy) study);
//             Integer v;
// 
//             double result = 0.0;
//             v = nk.get(category1);
//             if (v != null) {
//                 result += ((double) v) / 2.0;
//             }
//             v = nk.get(category2);
//             if (v != null) {
//                 result += ((double) v) / 2.0;
//             }
// 
//             int cat1 = (Integer) category1;
//             int cat2 = (Integer) category2;
//             int minCat = (cat1 < cat2 ? cat1 : cat2);
//             int maxCat = (cat1 < cat2 ? cat2 : cat1);
//             for (int i = minCat + 1; i < maxCat; i++) {
//                 v = nk.get(i);
//                 if (v != null) {
//                     result += v;
//                 }
//             }
//             return result * result;
//         }
// 
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/RatioDistanceFunction.java
// public class RatioDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         if (category1 instanceof Integer && category2 instanceof Integer
//                 && (((Integer) category1) + ((Integer) category2) > 0.0)) {
//             double result = (((Integer) category1) - ((Integer) category2))
//                     / (double) (((Integer) category1) + ((Integer) category2));
//             return result * result;
//         }
// 
//         if (category1 instanceof Double && category2 instanceof Double
//                 && (((Double) category1) + ((Double) category2) > 0.0)) {
//             double result = (((Double) category1) - ((Double) category2))
//                     / (((Double) category1) + ((Double) category2));
//             return result * result;
//         }
// 
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// 
// }


import org.dkpro.statistics.agreement.distance.IDistanceFunction;
import org.dkpro.statistics.agreement.distance.IntervalDistanceFunction;
import org.dkpro.statistics.agreement.distance.NominalDistanceFunction;
import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction;
import org.dkpro.statistics.agreement.distance.RatioDistanceFunction;
import junit.framework.TestCase;
        CodingAnnotationStudy study = createExample3a(0);

        IDistanceFunction distFunc = new OrdinalDistanceFunction();

        final double[][] EXPECTED = new double[][]{
                {  0.0, 11.0, 22.5, 30.0, 32.5, 34.0 },
                { 11.0,  0.0, 11.5, 19.0, 21.5, 23.0 },
                { 22.5, 11.5,  0.0,  7.5, 10.0, 11.5 },
                { 30.0, 19.0,  7.5,  0.0,  2.5,  4.0 },
                { 32.5, 21.5, 10.0,  2.5,  0.0,  1.5 },
                { 34.0, 23.0, 11.5,  4.0,  1.5,  0.0 }
        }; 
        int i = 0;
        int j = 0;
        for (Object category1 : study.getCategories()) {
            for (Object category2 : study.getCategories()) {
                assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j],
                        distFunc.measureDistance(study, category1, category2), 0.001);
                j++;
            }
            i++;
            j = 0;
        }
    }

    
    public void testIntervallMetric()
    {
        CodingAnnotationStudy study = createExample3a(-2);

// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/IDistanceFunction.java
// public interface IDistanceFunction
// {
// 
//     /**
//      * Returns a distance value for the given pair of categories used within the given annotation
//      * study. Normally, the measure should return a distance of 0 if, and only if, the two
//      * categories are equal and a positive number otherwise.
//      */
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2);
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/IntervalDistanceFunction.java
// public class IntervalDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         if (category1 instanceof Integer && category2 instanceof Integer) {
//             return (((Integer) category1) - ((Integer) category2))
//                     * (((Integer) category1) - ((Integer) category2));
//         }
// 
//         if (category1 instanceof Double && category2 instanceof Double) {
//             return (((Double) category1) - ((Double) category2))
//                     * (((Double) category1) - ((Double) category2));
//         }
// 
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/NominalDistanceFunction.java
// public class NominalDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/OrdinalDistanceFunction.java
// public class OrdinalDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         if (category1 instanceof Integer && category2 instanceof Integer) {
//             if (category1.equals(category2)) {
//                 return 0.0;
//             }
// 
//             // TODO: Provide generic method for the annotation study w/ potential use for unitizing
//             // tasks!
//             Map<Object, Integer> nk = CodingAnnotationStudy
//                     .countTotalAnnotationsPerCategory((ICodingAnnotationStudy) study);
//             Integer v;
// 
//             double result = 0.0;
//             v = nk.get(category1);
//             if (v != null) {
//                 result += ((double) v) / 2.0;
//             }
//             v = nk.get(category2);
//             if (v != null) {
//                 result += ((double) v) / 2.0;
//             }
// 
//             int cat1 = (Integer) category1;
//             int cat2 = (Integer) category2;
//             int minCat = (cat1 < cat2 ? cat1 : cat2);
//             int maxCat = (cat1 < cat2 ? cat2 : cat1);
//             for (int i = minCat + 1; i < maxCat; i++) {
//                 v = nk.get(i);
//                 if (v != null) {
//                     result += v;
//                 }
//             }
//             return result * result;
//         }
// 
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/RatioDistanceFunction.java
// public class RatioDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         if (category1 instanceof Integer && category2 instanceof Integer
//                 && (((Integer) category1) + ((Integer) category2) > 0.0)) {
//             double result = (((Integer) category1) - ((Integer) category2))
//                     / (double) (((Integer) category1) + ((Integer) category2));
//             return result * result;
//         }
// 
//         if (category1 instanceof Double && category2 instanceof Double
//                 && (((Double) category1) + ((Double) category2) > 0.0)) {
//             double result = (((Double) category1) - ((Double) category2))
//                     / (((Double) category1) + ((Double) category2));
//             return result * result;
//         }
// 
//         return (category1.equals(category2) ? 0.0 : 1.0);
//     }
// 
// }


// Path: dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff2004Test.java
import org.dkpro.statistics.agreement.distance.IDistanceFunction;
import org.dkpro.statistics.agreement.distance.IntervalDistanceFunction;
import org.dkpro.statistics.agreement.distance.NominalDistanceFunction;
import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction;
import org.dkpro.statistics.agreement.distance.RatioDistanceFunction;
import junit.framework.TestCase;

        CodingAnnotationStudy study = createExample3a(0);

        IDistanceFunction distFunc = new OrdinalDistanceFunction();

        final double[][] EXPECTED = new double[][]{
                {  0.0, 11.0, 22.5, 30.0, 32.5, 34.0 },
                { 11.0,  0.0, 11.5, 19.0, 21.5, 23.0 },
                { 22.5, 11.5,  0.0,  7.5, 10.0, 11.5 },
                { 30.0, 19.0,  7.5,  0.0,  2.5,  4.0 },
                { 32.5, 21.5, 10.0,  2.5,  0.0,  1.5 },
                { 34.0, 23.0, 11.5,  4.0,  1.5,  0.0 }
        }; 
        int i = 0;
        int j = 0;
        for (Object category1 : study.getCategories()) {
            for (Object category2 : study.getCategories()) {
                assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j],
                        distFunc.measureDistance(study, category1, category2), 0.001);
                j++;
            }
            i++;
            j = 0;
        }
    }

    
    public void testIntervallMetric()
    {
        CodingAnnotationStudy study = createExample3a(-2);

        IDistanceFunction distFunc = new IntervalDistanceFunction();