// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationUnit.java
// public interface IAnnotationUnit
//     extends Serializable
// {
//     /**
//      * Returns the index of the rater who coded this unit (in case of a coding study) or defined the
//      * boundaries of this unit (in case of a unitizing study). The first rater has index 0.
//      */
//     public int getRaterIdx();
// 
//     /**
//      * Returns the category assigned to this unit by one of the raters. The category might be null
//      * if, and only if, the unit represents a missing value (in case of a coding study) or a gap (in
//      * case of a unitizing study).
//      */
//     public Object getCategory();
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/ICategorySpecificAgreement.java
// public interface ICategorySpecificAgreement
// {
//     /**
//      * Calculates the inter-rater agreement for the given category.
//      * 
//      * @see ICategorySpecificAgreement
//      */
//     /*
//      * TODO @throws NullPointerException if the study is null or the given category is null.
//      * 
//      * @throws ArrayIndexOutOfBoundsException if the study does not contain the given category.
//      * 
//      * @throws ArithmeticException if the study does not contain annotations for the given category.
//      */
//     public double calculateCategoryAgreement(final Object category);
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IChanceCorrectedAgreement.java
// public interface IChanceCorrectedAgreement
//     extends IAgreementMeasure
// {
//     /**
//      * Returns the observed agreement of an annotation study. The observed agreement is basically
//      * the proportion of annotation units that the raters agree on divided by the number of units in
//      * the given study.
//      */
//     public double calculateObservedAgreement();
// 
//     /**
//      * Returns the expected agreement of an annotation study. The expected agreement is the
//      * proportion of agreement that would be expected by chance alone. The expected agreement should
//      * be equal to the observed agreement if each rater makes a random decision for each unit.
//      */
//     public double calculateExpectedAgreement();
// }


import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Map;
import org.dkpro.statistics.agreement.IAnnotationUnit;
import org.dkpro.statistics.agreement.ICategorySpecificAgreement;
import org.dkpro.statistics.agreement.IChanceCorrectedAgreement;
/*
 * 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;



/**
 * Implementation of Cohen's kappa (1960) for calculating a chance-corrected inter-rater agreement
 * for two raters. The measure assumes a different probability distribution for all raters.<br>
 * <br>
 * References:
 * <ul>
 * <li>Artstein, R. &amp; Poesio, M.: Inter-Coder Agreement for Computational Linguistics.
 * Computational Linguistics 34(4):555-596, 2008.</li>
 * <li>Cohen, J.: A Coefficient of Agreement for Nominal Scales. Educational and Psychological
 * Measurement 20(1):37-46, 1960.</li>
 * </ul>
 * 
 * @author Christian M. Meyer
 */
public class CohenKappaAgreement
    extends CodingAgreementMeasure
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationUnit.java
// public interface IAnnotationUnit
//     extends Serializable
// {
//     /**
//      * Returns the index of the rater who coded this unit (in case of a coding study) or defined the
//      * boundaries of this unit (in case of a unitizing study). The first rater has index 0.
//      */
//     public int getRaterIdx();
// 
//     /**
//      * Returns the category assigned to this unit by one of the raters. The category might be null
//      * if, and only if, the unit represents a missing value (in case of a coding study) or a gap (in
//      * case of a unitizing study).
//      */
//     public Object getCategory();
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/ICategorySpecificAgreement.java
// public interface ICategorySpecificAgreement
// {
//     /**
//      * Calculates the inter-rater agreement for the given category.
//      * 
//      * @see ICategorySpecificAgreement
//      */
//     /*
//      * TODO @throws NullPointerException if the study is null or the given category is null.
//      * 
//      * @throws ArrayIndexOutOfBoundsException if the study does not contain the given category.
//      * 
//      * @throws ArithmeticException if the study does not contain annotations for the given category.
//      */
//     public double calculateCategoryAgreement(final Object category);
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IChanceCorrectedAgreement.java
// public interface IChanceCorrectedAgreement
//     extends IAgreementMeasure
// {
//     /**
//      * Returns the observed agreement of an annotation study. The observed agreement is basically
//      * the proportion of annotation units that the raters agree on divided by the number of units in
//      * the given study.
//      */
//     public double calculateObservedAgreement();
// 
//     /**
//      * Returns the expected agreement of an annotation study. The expected agreement is the
//      * proportion of agreement that would be expected by chance alone. The expected agreement should
//      * be equal to the observed agreement if each rater makes a random decision for each unit.
//      */
//     public double calculateExpectedAgreement();
// }


// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CohenKappaAgreement.java
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Map;
import org.dkpro.statistics.agreement.IAnnotationUnit;
import org.dkpro.statistics.agreement.ICategorySpecificAgreement;
import org.dkpro.statistics.agreement.IChanceCorrectedAgreement;

/*
 * 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;



/**
 * Implementation of Cohen's kappa (1960) for calculating a chance-corrected inter-rater agreement
 * for two raters. The measure assumes a different probability distribution for all raters.<br>
 * <br>
 * References:
 * <ul>
 * <li>Artstein, R. &amp; Poesio, M.: Inter-Coder Agreement for Computational Linguistics.
 * Computational Linguistics 34(4):555-596, 2008.</li>
 * <li>Cohen, J.: A Coefficient of Agreement for Nominal Scales. Educational and Psychological
 * Measurement 20(1):37-46, 1960.</li>
 * </ul>
 * 
 * @author Christian M. Meyer
 */
public class CohenKappaAgreement
    extends CodingAgreementMeasure
    implements IChanceCorrectedAgreement, ICategorySpecificAgreement