// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/ICodingAnnotationItem.java
// public interface ICodingAnnotationItem
//     extends IAnnotationItem
// {
//     /**
//      * Returns the annotation unit of the rater with the specified index. That is, the object
//      * holding the category assigned to the item by the specified rater.
//      */
//     public IAnnotationUnit getUnit(int raterIdx);
// 
//     /**
//      * Returns all coding units for this annotation item (i.e., the categories assigned by the
//      * individual raters).
//      */
//     public Iterable<IAnnotationUnit> getUnits();
// 
//     /**
//      * Returns the number of raters who annotated this item with a non-null category.
//      */
//     public int getRaterCount();
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/ICodingAnnotationStudy.java
// public interface ICodingAnnotationStudy
//     extends IAnnotationStudy
// {
// 
//     // -- Categories --
// 
//     /**
//      * Returns true if, and only if, the annotation study contains at least one item with a missing
//      * value (i.e., an annotation item containing an annotation unit with category null).
//      */
//     public boolean hasMissingValues();
// 
//     // -- Items --
// 
//     /**
//      * Returns the annotation item with the given index. The first item has index 0.
//      */
//     public ICodingAnnotationItem getItem(int index);
// 
//     /** Allows iterating all annotation items of this study. */
//     public Iterable<ICodingAnnotationItem> getItems();
// 
//     /** Returns the number of annotation items defined by the study. */
//     public int getItemCount();
// 
//     // -- Units --
// 
//     /**
//      * Returns the number of annotation units defined by the study. That is, the number of
//      * annotations coded by the raters. If there are no missing values, the unit count equals the
//      * item count multiplied with the number of raters.
//      */
//     @Override
//     public int getUnitCount();
// 
// }


import java.io.PrintStream;
import java.util.LinkedHashMap;
import java.util.Map;
import org.dkpro.statistics.agreement.coding.ICodingAnnotationItem;
import org.dkpro.statistics.agreement.coding.ICodingAnnotationStudy;
/*
 * 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.visualization;



/**
 * Plain-text visualization for a contingency matrix as defined by 
 * Krippendorff (1980: p. 133). That is, a table showing the frequencies
 * of each combination of categories used by two raters. A contigency table
 * is only defined for coding studies with exactly two raters. For the example 
 * by Krippendorff (1980: p. 133), the implementation displays:
 * <pre>     
 *     0   1   Σ
 * 0   5   3   8
 * 1   1   1   2
 * Σ   6   4  10
 * </pre><br>
 * References:<ul>
 * <li>Krippendorff, K.: Content Analysis: An Introduction to Its Methodology.
 *   Beverly Hills, CA: Sage Publications, 1980.</li></ul>
 * @see ICodingAnnotationStudy
 * @author Christian M. Meyer
 */
public class ContingencyMatrixPrinter
{

    /**
     * Print the contingency matrix for the given coding study.
     * 
     * @throws IllegalArgumentException
     *             if the given study has more than two raters.
     */
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/ICodingAnnotationItem.java
// public interface ICodingAnnotationItem
//     extends IAnnotationItem
// {
//     /**
//      * Returns the annotation unit of the rater with the specified index. That is, the object
//      * holding the category assigned to the item by the specified rater.
//      */
//     public IAnnotationUnit getUnit(int raterIdx);
// 
//     /**
//      * Returns all coding units for this annotation item (i.e., the categories assigned by the
//      * individual raters).
//      */
//     public Iterable<IAnnotationUnit> getUnits();
// 
//     /**
//      * Returns the number of raters who annotated this item with a non-null category.
//      */
//     public int getRaterCount();
// }
// 
// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/ICodingAnnotationStudy.java
// public interface ICodingAnnotationStudy
//     extends IAnnotationStudy
// {
// 
//     // -- Categories --
// 
//     /**
//      * Returns true if, and only if, the annotation study contains at least one item with a missing
//      * value (i.e., an annotation item containing an annotation unit with category null).
//      */
//     public boolean hasMissingValues();
// 
//     // -- Items --
// 
//     /**
//      * Returns the annotation item with the given index. The first item has index 0.
//      */
//     public ICodingAnnotationItem getItem(int index);
// 
//     /** Allows iterating all annotation items of this study. */
//     public Iterable<ICodingAnnotationItem> getItems();
// 
//     /** Returns the number of annotation items defined by the study. */
//     public int getItemCount();
// 
//     // -- Units --
// 
//     /**
//      * Returns the number of annotation units defined by the study. That is, the number of
//      * annotations coded by the raters. If there are no missing values, the unit count equals the
//      * item count multiplied with the number of raters.
//      */
//     @Override
//     public int getUnitCount();
// 
// }


// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ContingencyMatrixPrinter.java
import java.io.PrintStream;
import java.util.LinkedHashMap;
import java.util.Map;
import org.dkpro.statistics.agreement.coding.ICodingAnnotationItem;
import org.dkpro.statistics.agreement.coding.ICodingAnnotationStudy;

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



/**
 * Plain-text visualization for a contingency matrix as defined by 
 * Krippendorff (1980: p. 133). That is, a table showing the frequencies
 * of each combination of categories used by two raters. A contigency table
 * is only defined for coding studies with exactly two raters. For the example 
 * by Krippendorff (1980: p. 133), the implementation displays:
 * <pre>     
 *     0   1   Σ
 * 0   5   3   8
 * 1   1   1   2
 * Σ   6   4  10
 * </pre><br>
 * References:<ul>
 * <li>Krippendorff, K.: Content Analysis: An Introduction to Its Methodology.
 *   Beverly Hills, CA: Sage Publications, 1980.</li></ul>
 * @see ICodingAnnotationStudy
 * @author Christian M. Meyer
 */
public class ContingencyMatrixPrinter
{

    /**
     * Print the contingency matrix for the given coding study.
     * 
     * @throws IllegalArgumentException
     *             if the given study has more than two raters.
     */
    public void print(final PrintStream out, final ICodingAnnotationStudy study)