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

        int[][] frequencies = new int[study.getCategoryCount()][study.getCategoryCount()];
        for (ICodingAnnotationItem item : study.getItems()) {
            int cat1 = categories.get(item.getUnit(0).getCategory());
            int cat2 = categories.get(item.getUnit(1).getCategory());
            frequencies[cat1][cat2]++;
        }

        final String DIVIDER = "\t";
        for (Object category : categories.keySet()) {
            out.print(DIVIDER + category);
        }
        out.print(DIVIDER + "Σ");
        out.println();
        int i = 0;
        int[] colSum = new int[study.getCategoryCount()];
        for (Object category1 : categories.keySet()) {
            out.print(category1);
            int rowSum = 0;
            for (int j = 0; j < categories.size(); j++) {
                out.printf(DIVIDER + "%3d", frequencies[i][j]);
                rowSum += frequencies[i][j];
                colSum[j] += frequencies[i][j];
            }
            out.printf(DIVIDER + "%3d", rowSum);
            out.println();
            i++;
        }

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

        }

        int[][] frequencies = new int[study.getCategoryCount()][study.getCategoryCount()];
        for (ICodingAnnotationItem item : study.getItems()) {
            int cat1 = categories.get(item.getUnit(0).getCategory());
            int cat2 = categories.get(item.getUnit(1).getCategory());
            frequencies[cat1][cat2]++;
        }

        final String DIVIDER = "\t";
        for (Object category : categories.keySet()) {
            out.print(DIVIDER + category);
        }
        out.print(DIVIDER + "Σ");
        out.println();
        int i = 0;
        int[] colSum = new int[study.getCategoryCount()];
        for (Object category1 : categories.keySet()) {
            out.print(category1);
            int rowSum = 0;
            for (int j = 0; j < categories.size(); j++) {
                out.printf(DIVIDER + "%3d", frequencies[i][j]);
                rowSum += frequencies[i][j];
                colSum[j] += frequencies[i][j];
            }
            out.printf(DIVIDER + "%3d", rowSum);
            out.println();
            i++;
        }

        out.print("Σ");