// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/MASISetAnnotationDistanceFunction.java
// public class MASISetAnnotationDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, Object category1, Object category2)
//     {
//         SetAnnotation c1 = (SetAnnotation) category1;
//         SetAnnotation c2 = (SetAnnotation) category2;
// 
//         SetAnnotation delta = new SetAnnotation(c1);
//         delta.removeAll(c2);
//         boolean c1_subset_c2 = (delta.size() == 0);
//         int overlap = c1.size() - delta.size();
//         int union = c2.size() + delta.size();
//         delta = new SetAnnotation(c2);
//         delta.removeAll(c1);
//         boolean c2_subset_c1 = (delta.size() == 0);
// 
//         double jaccard = (union == 0 ? 1.0 : (1.0 - overlap / (double) union));
//         if (c1_subset_c2 && c2_subset_c1) {
//             return jaccard * 0.0; // identical.
//         }
//         if (c1_subset_c2 || c2_subset_c1) {
//             return jaccard * (1.0 / 3.0); // subsets.
//         }
//         if (overlap > 0) {
//             return jaccard * (2.0 / 3.0); // some intersection.
//         }
//         else {
//             return jaccard * 1.0; // disjoint.
//         }
//     }
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/SetAnnotation.java
// public class SetAnnotation
//     extends HashSet<Object>
//     implements Comparable<SetAnnotation>
// {
//     private static final long serialVersionUID = 8656250211589017624L;
// 
//     /** Instantiates an empty set annotation. */
//     public SetAnnotation()
//     {
//         super();
//     }
// 
//     /** Instantiates a set annotation with the given values as set elements. */
//     public SetAnnotation(Object... values)
//     {
//         super();
//         for (Object value : values) {
//             add(value);
//         }
//     }
// 
//     /** Instantiates a set annotation with the given values as set elements. */
//     public SetAnnotation(Collection<? extends Object> c)
//     {
//         super(c);
//     }
// 
//     @Override
//     public int compareTo(final SetAnnotation that)
//     {
//         return toString().compareTo(that.toString());
//     }
// 
//     @Override
//     public boolean equals(final Object that)
//     {
//         if (!(that instanceof SetAnnotation)) {
//             return false;
//         }
//         return toString().equals(((SetAnnotation) that).toString());
//     }
// 
//     @Override
//     public int hashCode()
//     {
//         return toString().hashCode();
//     }
// 
//     @Override
//     public String toString()
//     {
//         StringBuilder result = new StringBuilder();
//         for (Object value : this) {
//             result.append(result.length() == 0 ? "" : ", ").append(value);
//         }
//         return result.toString();
//     }
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/SetAnnotationDistanceFunction.java
// public class SetAnnotationDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         SetAnnotation c1 = (SetAnnotation) category1;
//         SetAnnotation c2 = (SetAnnotation) category2;
// 
//         SetAnnotation delta = new SetAnnotation(c1);
//         delta.removeAll(c2);
//         boolean c1_subset_c2 = (delta.size() == 0);
//         int overlap = c1.size() - delta.size();
//         delta = new SetAnnotation(c2);
//         delta.removeAll(c1);
//         boolean c2_subset_c1 = (delta.size() == 0);
// 
//         if (c1_subset_c2 && c2_subset_c1) {
//             return 0.0; // identical.
//         }
//         if (c1_subset_c2 || c2_subset_c1) {
//             return 1.0 / 3.0; // subsets.
//         }
//         if (overlap > 0) {
//             return 2.0 / 3.0; // some intersection.
//         }
//         else {
//             return 1.0; // disjoint.
//         }
//     }
// 
// }


import org.dkpro.statistics.agreement.distance.MASISetAnnotationDistanceFunction;
import org.dkpro.statistics.agreement.distance.SetAnnotation;
import org.dkpro.statistics.agreement.distance.SetAnnotationDistanceFunction;
import junit.framework.TestCase;
    public void testPercentageAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        PercentageAgreement percentageAgreement = new PercentageAgreement(study);
        assertEquals(0.333, percentageAgreement.calculateAgreement(), 0.001);
    }

    
    public void testMaxPercentageAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        MaxPercentageAgreement maxPercentageAgreement = new MaxPercentageAgreement(study);
        assertEquals(0.667, maxPercentageAgreement.calculateAgreement(), 0.001);
    }

    
    public void testDiceAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        DiceAgreement DiceAgreement = new DiceAgreement(study);
        assertEquals(0.5, DiceAgreement.calculateAgreement(), 0.001);
    }

    /** Creates an example annotation study. */
    public ICodingAnnotationStudy createExample()
    {
        CodingAnnotationStudy study = new CodingAnnotationStudy(2);
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/MASISetAnnotationDistanceFunction.java
// public class MASISetAnnotationDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, Object category1, Object category2)
//     {
//         SetAnnotation c1 = (SetAnnotation) category1;
//         SetAnnotation c2 = (SetAnnotation) category2;
// 
//         SetAnnotation delta = new SetAnnotation(c1);
//         delta.removeAll(c2);
//         boolean c1_subset_c2 = (delta.size() == 0);
//         int overlap = c1.size() - delta.size();
//         int union = c2.size() + delta.size();
//         delta = new SetAnnotation(c2);
//         delta.removeAll(c1);
//         boolean c2_subset_c1 = (delta.size() == 0);
// 
//         double jaccard = (union == 0 ? 1.0 : (1.0 - overlap / (double) union));
//         if (c1_subset_c2 && c2_subset_c1) {
//             return jaccard * 0.0; // identical.
//         }
//         if (c1_subset_c2 || c2_subset_c1) {
//             return jaccard * (1.0 / 3.0); // subsets.
//         }
//         if (overlap > 0) {
//             return jaccard * (2.0 / 3.0); // some intersection.
//         }
//         else {
//             return jaccard * 1.0; // disjoint.
//         }
//     }
// 
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/SetAnnotation.java
// public class SetAnnotation
//     extends HashSet<Object>
//     implements Comparable<SetAnnotation>
// {
//     private static final long serialVersionUID = 8656250211589017624L;
// 
//     /** Instantiates an empty set annotation. */
//     public SetAnnotation()
//     {
//         super();
//     }
// 
//     /** Instantiates a set annotation with the given values as set elements. */
//     public SetAnnotation(Object... values)
//     {
//         super();
//         for (Object value : values) {
//             add(value);
//         }
//     }
// 
//     /** Instantiates a set annotation with the given values as set elements. */
//     public SetAnnotation(Collection<? extends Object> c)
//     {
//         super(c);
//     }
// 
//     @Override
//     public int compareTo(final SetAnnotation that)
//     {
//         return toString().compareTo(that.toString());
//     }
// 
//     @Override
//     public boolean equals(final Object that)
//     {
//         if (!(that instanceof SetAnnotation)) {
//             return false;
//         }
//         return toString().equals(((SetAnnotation) that).toString());
//     }
// 
//     @Override
//     public int hashCode()
//     {
//         return toString().hashCode();
//     }
// 
//     @Override
//     public String toString()
//     {
//         StringBuilder result = new StringBuilder();
//         for (Object value : this) {
//             result.append(result.length() == 0 ? "" : ", ").append(value);
//         }
//         return result.toString();
//     }
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/distance/SetAnnotationDistanceFunction.java
// public class SetAnnotationDistanceFunction
//     implements IDistanceFunction
// {
// 
//     @Override
//     public double measureDistance(final IAnnotationStudy study, final Object category1,
//             final Object category2)
//     {
//         SetAnnotation c1 = (SetAnnotation) category1;
//         SetAnnotation c2 = (SetAnnotation) category2;
// 
//         SetAnnotation delta = new SetAnnotation(c1);
//         delta.removeAll(c2);
//         boolean c1_subset_c2 = (delta.size() == 0);
//         int overlap = c1.size() - delta.size();
//         delta = new SetAnnotation(c2);
//         delta.removeAll(c1);
//         boolean c2_subset_c1 = (delta.size() == 0);
// 
//         if (c1_subset_c2 && c2_subset_c1) {
//             return 0.0; // identical.
//         }
//         if (c1_subset_c2 || c2_subset_c1) {
//             return 1.0 / 3.0; // subsets.
//         }
//         if (overlap > 0) {
//             return 2.0 / 3.0; // some intersection.
//         }
//         else {
//             return 1.0; // disjoint.
//         }
//     }
// 
// }


// Path: dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/SetAnnotationsTest.java
import org.dkpro.statistics.agreement.distance.MASISetAnnotationDistanceFunction;
import org.dkpro.statistics.agreement.distance.SetAnnotation;
import org.dkpro.statistics.agreement.distance.SetAnnotationDistanceFunction;
import junit.framework.TestCase;

    public void testPercentageAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        PercentageAgreement percentageAgreement = new PercentageAgreement(study);
        assertEquals(0.333, percentageAgreement.calculateAgreement(), 0.001);
    }

    
    public void testMaxPercentageAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        MaxPercentageAgreement maxPercentageAgreement = new MaxPercentageAgreement(study);
        assertEquals(0.667, maxPercentageAgreement.calculateAgreement(), 0.001);
    }

    
    public void testDiceAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        DiceAgreement DiceAgreement = new DiceAgreement(study);
        assertEquals(0.5, DiceAgreement.calculateAgreement(), 0.001);
    }

    /** Creates an example annotation study. */
    public ICodingAnnotationStudy createExample()
    {
        CodingAnnotationStudy study = new CodingAnnotationStudy(2);
        study.addItem(new SetAnnotation(), new SetAnnotation());