// 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;
/*
 * Copyright 2014
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universität Darmstadt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dkpro.statistics.agreement.coding;



/**
 * Tests for {@link KrippendorffAlphaAgreement} with {@link SetAnnotationDistanceFunction} and
 * {@link MASISetAnnotationDistanceFunction}.
 * 
 * @author Christian M. Meyer
 * @author Tristan Miller
 */
public class SetAnnotationsTest
    extends TestCase
{

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

        KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, null);
// 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;

/*
 * Copyright 2014
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universität Darmstadt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dkpro.statistics.agreement.coding;



/**
 * Tests for {@link KrippendorffAlphaAgreement} with {@link SetAnnotationDistanceFunction} and
 * {@link MASISetAnnotationDistanceFunction}.
 * 
 * @author Christian M. Meyer
 * @author Tristan Miller
 */
public class SetAnnotationsTest
    extends TestCase
{

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

        KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, null);
        alpha.setDistanceFunction(new SetAnnotationDistanceFunction());