// 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);
//     }
// }


import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction;
import junit.framework.TestCase;
        ICodingAnnotationStudy study = createExample();

        KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study,
                new OrdinalDistanceFunction());
        assertEquals(0.7598, alpha.calculateAgreement(), 0.0001);
    }

    /**
     * Creates an example annotation study introduced by Hayes &amp; Krippendorff (2007: p. 84).
     */
    public static ICodingAnnotationStudy createExample()
    {
        CodingAnnotationStudy study = new CodingAnnotationStudy(5);
        study.addItem(1, 1, 2, null, 2);
        study.addItem(1, 1, 0, 1, null);
        study.addItem(2, 3, 3, 3, null);
        study.addItem(null, 0, 0, null, 0);
        study.addItem(0, 0, 0, null, 0);
        study.addItem(0, 0, 0, null, 0);
        study.addItem(1, 0, 2, null, 1);
        study.addItem(1, null, 2, 0, null);
        study.addItem(2, 2, 2, null, 2);
        study.addItem(2, 1, 1, 1, null);
        study.addItem(null, 1, 0, 0, null);
        study.addItem(0, 0, 0, 0, null);
        study.addItem(1, 2, 2, 2, null);
        study.addItem(3, 3, 2, 2, 3);
        study.addItem(1, 1, 1, null, 1);
        study.addItem(1, 1, 1, null, 1);
        study.addItem(2, 1, 2, null, 2);
// 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/test/java/org/dkpro/statistics/agreement/coding/HayesKrippendorff2007Test.java
import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction;
import junit.framework.TestCase;

        ICodingAnnotationStudy study = createExample();

        KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study,
                new OrdinalDistanceFunction());
        assertEquals(0.7598, alpha.calculateAgreement(), 0.0001);
    }

    /**
     * Creates an example annotation study introduced by Hayes &amp; Krippendorff (2007: p. 84).
     */
    public static ICodingAnnotationStudy createExample()
    {
        CodingAnnotationStudy study = new CodingAnnotationStudy(5);
        study.addItem(1, 1, 2, null, 2);
        study.addItem(1, 1, 0, 1, null);
        study.addItem(2, 3, 3, 3, null);
        study.addItem(null, 0, 0, null, 0);
        study.addItem(0, 0, 0, null, 0);
        study.addItem(0, 0, 0, null, 0);
        study.addItem(1, 0, 2, null, 1);
        study.addItem(1, null, 2, 0, null);
        study.addItem(2, 2, 2, null, 2);
        study.addItem(2, 1, 1, 1, null);
        study.addItem(null, 1, 0, 0, null);
        study.addItem(0, 0, 0, 0, null);
        study.addItem(1, 2, 2, 2, null);
        study.addItem(3, 3, 2, 2, 3);
        study.addItem(1, 1, 1, null, 1);
        study.addItem(1, 1, 1, null, 1);
        study.addItem(2, 1, 2, null, 2);
        study.addItem(1, 2, 3, 3, null);