From 1eb05fef3d14d99e50aedd247ae521f6b41cbea7 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Mon, 22 Jul 2024 14:51:49 -0300 Subject: [PATCH] #37 - Upgrade dependencies - JUnit 4 -> 5 - Commons Math 2 -> 3 - Commons Logging -> SLF4J - Commons Lang 2 -> 3 - DKPro Parent POM 24 -> 32 - GitHub Action build --- .github/workflows/maven.yml | 46 +++ dkpro-statistics-agreement/pom.xml | 14 +- .../agreement/AgreementMeasure.java | 4 +- .../statistics/agreement/AnnotationStudy.java | 2 +- .../statistics/agreement/AnnotationUnit.java | 12 +- .../agreement/DisagreementMeasure.java | 26 +- .../statistics/agreement/IAnnotationItem.java | 3 +- .../agreement/IAnnotationStudy.java | 7 +- .../statistics/agreement/IAnnotationUnit.java | 14 +- .../coding/CodingAnnotationItem.java | 2 +- .../coding/CodingAnnotationStudy.java | 2 +- .../unitizing/IUnitizingAnnotationUnit.java | 41 ++- .../unitizing/UnitizingAnnotationStudy.java | 4 +- .../unitizing/UnitizingAnnotationUnit.java | 25 +- .../CoincidenceMatrixPrinter.java | 4 +- .../ContingencyMatrixPrinter.java | 2 +- .../ReliabilityMatrixPrinter.java | 6 +- .../visualization/UnitizingStudyPrinter.java | 2 +- .../agreement/AnnotationStudyTest.java | 6 +- .../agreement/coding/Agresti1992Test.java | 13 +- .../coding/ArtsteinPoesio2008Test.java | 93 +++--- .../coding/BrennanPrediger1981Test.java | 45 +-- .../agreement/coding/Cohen1960Test.java | 35 +-- .../agreement/coding/Fleiss1971Test.java | 96 +++--- .../coding/HayesKrippendorff2007Test.java | 12 +- .../coding/Krippendorff1980Test.java | 277 +++++++++--------- .../coding/Krippendorff2004Test.java | 128 ++++---- .../agreement/coding/Mieskes2009Test.java | 37 +-- .../coding/MultiRaterAgreementTest.java | 23 +- .../coding/NumericalStabilityTest.java | 82 +++--- .../agreement/coding/Randolph2005Test.java | 22 +- .../agreement/coding/SetAnnotationsTest.java | 36 +-- .../coding/TwoRaterAgreementTest.java | 78 ++--- .../agreement/coding/Warrens2010Test.java | 28 +- .../agreement/coding/Warrens2012Test.java | 30 +- .../coding/WeightedAgreementTest.java | 55 ++-- .../agreement/coding/Zwick1988Test.java | 35 ++- .../unitizing/Krippendorff1995Test.java | 226 ++++++++------ .../unitizing/Krippendorff2004Test.java | 130 ++++---- .../unitizing/UnitizingAgreementTest.java | 54 ++-- .../UnitizingAnnotationStudyTest.java | 14 +- dkpro-statistics-correlation/pom.xml | 10 +- .../correlation/PearsonCorrelation.java | 10 +- .../correlation/SpearmansRankCorrelation.java | 2 +- dkpro-statistics-significance/pom.xml | 11 +- .../statistics/significance/Significance.java | 12 +- .../significance/SignificanceTest.java | 25 +- pom.xml | 50 ++-- 48 files changed, 1029 insertions(+), 862 deletions(-) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..84933df --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,46 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "main", "release/**" ] + pull_request: + branches: [ "main", "release/**" ] + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + jdk: [17] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref || github.ref }} + + - name: Set up JDK ${{ matrix.jdk }} + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.jdk }} + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn --no-transfer-progress -B clean verify --file pom.xml + + # Fails with error message - no idea why... + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + # - name: Update dependency graph + # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 diff --git a/dkpro-statistics-agreement/pom.xml b/dkpro-statistics-agreement/pom.xml index 32625f0..4ae5ccd 100644 --- a/dkpro-statistics-agreement/pom.xml +++ b/dkpro-statistics-agreement/pom.xml @@ -16,7 +16,9 @@ See the License for the specific language governing permissions and limitations under the License. --> - + 4.0.0 dkpro-statistics-agreement @@ -35,11 +37,15 @@ repo - + - junit - junit + org.slf4j + slf4j-api + + + org.junit.jupiter + junit-jupiter-api test diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AgreementMeasure.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AgreementMeasure.java index 2a65bf7..5f94e22 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AgreementMeasure.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AgreementMeasure.java @@ -20,8 +20,8 @@ /** * Default implementation of the {@link IAgreementMeasure} interface providing computational hooks * for calculating the observed and the expected agreement. The values for observed and expected - * agreement are combined using Scott's (1955) {@code (A_O - A_E) / (1.0 - A_E)} formula - * (where A_O denotes the observed agreement and A_E denotes the expected agreement. See also + * agreement are combined using Scott's (1955) {@code (A_O - A_E) / (1.0 - A_E)} formula (where A_O + * denotes the observed agreement and A_E denotes the expected agreement. See also * {@link DisagreementMeasure} for the analogous definition of a measure based on the observed and * expected disagreement.
*
diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationStudy.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationStudy.java index e2e034b..55aeafd 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationStudy.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationStudy.java @@ -32,7 +32,7 @@ public abstract class AnnotationStudy implements IAnnotationStudy { private static final long serialVersionUID = -3596722258510421730L; - + protected List raters; protected Set categories; diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationUnit.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationUnit.java index e5f7104..ebd56f2 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationUnit.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/AnnotationUnit.java @@ -29,18 +29,18 @@ public class AnnotationUnit implements IAnnotationUnit { private static final long serialVersionUID = 4277733312128063453L; - - protected int raterIdx; - protected Object category; + + protected final int raterIdx; + protected final Object category; /** * Initializes the annotation unit with the given category as the annotation by the rater with * the specified index. */ - public AnnotationUnit(int raterIdx, final Object category) + public AnnotationUnit(int aRaterIdx, final Object aCategory) { - this.raterIdx = raterIdx; - this.category = category; + raterIdx = aRaterIdx; + category = aCategory; } @Override diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/DisagreementMeasure.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/DisagreementMeasure.java index eb1ed07..c872bb2 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/DisagreementMeasure.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/DisagreementMeasure.java @@ -17,11 +17,16 @@ */ package org.dkpro.statistics.agreement; +import java.lang.invoke.MethodHandles; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Default implementation of the {@link IAgreementMeasure} interface providing computational hooks * for calculating the observed and the expected disagreement. The values for observed and expected - * disagreement are combined using Krippendorff's (1980) {@code 1 - (D_O / D_E)} formula - * (where D_O denotes the observed disagreement and D_E denotes the expected disagreement. See also + * disagreement are combined using Krippendorff's (1980) {@code 1 - (D_O / D_E)} formula (where D_O + * denotes the observed disagreement and D_E denotes the expected disagreement. See also * {@link AgreementMeasure} for the analogous definition of a measure based on the observed and * expected agreement.
*
@@ -38,26 +43,31 @@ public abstract class DisagreementMeasure implements IAgreementMeasure { + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + /** * Calculates the inter-rater agreement for the annotation study that was passed to the class * constructor and the currently assigned distance function. * - * @throws NullPointerException if the study is null. + * @throws NullPointerException + * if the study is null. * - * @throws ArithmeticException if the study does not contain any item or the number of raters is - * smaller than 2. + * @throws ArithmeticException + * if the study does not contain any item or the number of raters is smaller than 2. */ @Override public double calculateAgreement() { double D_O = calculateObservedDisagreement(); double D_E = calculateExpectedDisagreement(); + + LOG.trace("Disagreement -- observed: {} -- expected: {}", D_O, D_E); + if (D_O == D_E) { return 0.0; } - else { - return 1.0 - (D_O / D_E); - } + + return 1.0 - (D_O / D_E); } protected abstract double calculateObservedDisagreement(); diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationItem.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationItem.java index 6feb667..8326509 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationItem.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationItem.java @@ -33,7 +33,8 @@ * @see IAnnotationStudy * @author Christian M. Meyer */ -public interface IAnnotationItem extends Serializable +public interface IAnnotationItem + extends Serializable { } diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationStudy.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationStudy.java index 9644a38..520c98d 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationStudy.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationStudy.java @@ -40,7 +40,7 @@ public interface IAnnotationStudy /** Returns the number of raters participating in this study. */ int getRaterCount(); - + int findRater(final String name); // -- Categories -- @@ -63,7 +63,10 @@ public interface IAnnotationStudy * Returns true if, and only if, the categories defined by the study yield a dichotomy (i.e., * there are exactly two categories). */ - boolean isDichotomous(); + default boolean isDichotomous() + { + return getCategoryCount() == 2; + } // -- Units -- diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationUnit.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationUnit.java index 1098d4a..03c9acc 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationUnit.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/IAnnotationUnit.java @@ -33,15 +33,15 @@ 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. + * @return 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(); + 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). + * @return 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(); + Object getCategory(); } diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationItem.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationItem.java index 4a6012f..21a036e 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationItem.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationItem.java @@ -36,7 +36,7 @@ public class CodingAnnotationItem implements ICodingAnnotationItem { private static final long serialVersionUID = 3447650373912260846L; - + protected List units; protected int nonNullCount; diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationStudy.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationStudy.java index da1f543..5955e37 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationStudy.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/coding/CodingAnnotationStudy.java @@ -45,7 +45,7 @@ public class CodingAnnotationStudy implements ICodingAnnotationStudy, Cloneable, Serializable { private static final long serialVersionUID = -8242222160334337626L; - + protected List items; /** diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/IUnitizingAnnotationUnit.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/IUnitizingAnnotationUnit.java index 32448b0..39f85ec 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/IUnitizingAnnotationUnit.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/IUnitizingAnnotationUnit.java @@ -34,23 +34,46 @@ public interface IUnitizingAnnotationUnit extends IAnnotationUnit, Comparable { + /** + * @return the offset of the annotation unit (i.e., the start position of the identified + * segment). + * @deprecated Use {@link #getBegin()} + */ + @Deprecated + default long getOffset() + { + return getBegin(); + } /** - * Returns the offset of the annotation unit (i.e., the start position of the identified - * segment). + * @return the length of the annotation unit (i.e., the difference between the end and start + * position of the identified segment). */ - public long getOffset(); + default long getLength() + { + return getEnd() - getBegin(); + } /** - * Returns the length of the annotation unit (i.e., the difference between the end and start - * position of the identified segment). + * @return the right delimiter of the annotation unit (i.e., the end position of the identified + * segment). The method is a shorthand for {@link #getOffset()} + {@link #getLength()}. + * @deprecated Use {@link #getEnd()} */ - public long getLength(); + @Deprecated + default long getEndOffset() + { + return getEnd(); + } /** - * Returns the right delimiter of the annotation unit (i.e., the end position of the identified - * segment). The method is a shorthand for {@link #getOffset()} + {@link #getLength()}. + * @return the offset of the annotation unit (i.e., the start position of the identified + * segment). */ - public long getEndOffset(); + long getBegin(); + /** + * @return the right delimiter of the annotation unit (i.e., the end position of the identified + * segment). The method is a shorthand for {@link #getOffset()} + {@link #getLength()}. + */ + long getEnd(); } diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudy.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudy.java index 1ba0840..ffd9e52 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudy.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudy.java @@ -41,7 +41,7 @@ public class UnitizingAnnotationStudy implements IUnitizingAnnotationStudy, Serializable { private static final long serialVersionUID = 5877774485360119115L; - + protected Set units; protected long begin; protected long length; @@ -129,7 +129,7 @@ public Collection getUnits() { return units; } - + @Override public long getUnitCount(int raterIdx) { diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationUnit.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationUnit.java index 3a02422..8cd9fdc 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationUnit.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationUnit.java @@ -35,9 +35,9 @@ public class UnitizingAnnotationUnit implements IUnitizingAnnotationUnit { private static final long serialVersionUID = -6716379300031576772L; - - protected long offset; - protected long length; + + final protected long offset; + final protected long length; /** * Initializes the unit with the given offset and length as well as the category assigned to the @@ -45,11 +45,12 @@ public class UnitizingAnnotationUnit * {@link UnitizingAnnotationStudy#addUnit(long, long, int, Object)} should be used to define * the annotation units. */ - protected UnitizingAnnotationUnit(long offset, long length, int raterIdx, final Object category) + protected UnitizingAnnotationUnit(long aOffset, long aLength, int aRaterIdx, + final Object aCategory) { - super(raterIdx, category); - this.offset = offset; - this.length = length; + super(aRaterIdx, aCategory); + offset = aOffset; + length = aLength; } @Override @@ -70,6 +71,16 @@ public long getEndOffset() return offset + length; } + public long getBegin() + { + return getOffset(); + } + + public long getEnd() + { + return getEndOffset(); + } + @Override public int compareTo(final IUnitizingAnnotationUnit that) { diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/CoincidenceMatrixPrinter.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/CoincidenceMatrixPrinter.java index 47e28a4..6ec5630 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/CoincidenceMatrixPrinter.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/CoincidenceMatrixPrinter.java @@ -120,7 +120,7 @@ protected void doPrint(final PrintStream out, final ICodingAnnotationStudy study out.printf(DIVIDER + DOUBLE_FORMAT, sum); out.println(); } -/* + /* public void printPercentage(final PrintStream out, final IItemAnnotationStudy study) { //TODO: measure length of cats. maybe cut them. Map> coincidence = @@ -175,5 +175,5 @@ public void printPercentage(final PrintStream out, final IItemAnnotationStudy st out.printf(DIVIDER + "%1.3f", sum); out.println(); } - */ + */ } diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ContingencyMatrixPrinter.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ContingencyMatrixPrinter.java index 4ac9600..98c8f56 100644 --- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ContingencyMatrixPrinter.java +++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ContingencyMatrixPrinter.java @@ -30,7 +30,7 @@ * 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: - *
     
+ * 
  *     0   1   Σ
  * 0   5   3   8
  * 1   1   1   2
diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ReliabilityMatrixPrinter.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ReliabilityMatrixPrinter.java
index f85741c..6b7a796 100644
--- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ReliabilityMatrixPrinter.java
+++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/ReliabilityMatrixPrinter.java
@@ -93,8 +93,8 @@ public void print(final PrintStream out, final ICodingAnnotationStudy study)
             }
             out.println(DIVIDER + catSum);
         }
-        
-/*        
+
+        /*
         for (Object category : categories.keySet())
             out.print(DIVIDER + category);
         out.print(DIVIDER + "Σ");
@@ -123,5 +123,5 @@ public void print(final PrintStream out, final ICodingAnnotationStudy study)
         out.printf(DIVIDER + "%3d", rowSum);
         out.println();*/
     }
-    
+
 }
diff --git a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/UnitizingStudyPrinter.java b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/UnitizingStudyPrinter.java
index 6fe5040..f018579 100644
--- a/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/UnitizingStudyPrinter.java
+++ b/dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/visualization/UnitizingStudyPrinter.java
@@ -110,7 +110,7 @@ public void printUnitsForRater(final PrintStream out, final IUnitizingAnnotation
             annotations[i] = ' ';
         }
         for (IUnitizingAnnotationUnit unit : study.getUnits()) {
-            if (unit.getRaterIdx() == raterIdx && Objects.equals(unit.getCategory(),category)) {
+            if (unit.getRaterIdx() == raterIdx && Objects.equals(unit.getCategory(), category)) {
                 for (int i = 0; i < unit.getLength(); i++) {
                     annotations[i + (int) unit.getOffset() - (int) B] = '*';
                 }
diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/AnnotationStudyTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/AnnotationStudyTest.java
index 632c0d8..0b403ce 100644
--- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/AnnotationStudyTest.java
+++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/AnnotationStudyTest.java
@@ -21,12 +21,12 @@
 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 
 import org.dkpro.statistics.agreement.coding.CodingAnnotationStudy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class AnnotationStudyTest
 {
     @Test
-    public void testAddItem()
+    void testAddItem()
     {
         CodingAnnotationStudy study = new CodingAnnotationStudy(3);
         study.addItem("A", "B", "C");
@@ -38,7 +38,7 @@ public void testAddItem()
     }
 
     @Test
-    public void testAddItemMissingUnits()
+    void testAddItemMissingUnits()
     {
         CodingAnnotationStudy study = new CodingAnnotationStudy(3);
         
diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Agresti1992Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Agresti1992Test.java
index 539207c..756539a 100644
--- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Agresti1992Test.java
+++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Agresti1992Test.java
@@ -17,7 +17,9 @@
  */
 package org.dkpro.statistics.agreement.coding;
 
-import junit.framework.TestCase;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
 
 /**
  * Tests based on Agresti (1992) for category-specific agreement using
@@ -33,12 +35,10 @@
  * 
  * @author Christian M. Meyer
  */
-public class Agresti1992Test
-    extends TestCase
+class Agresti1992Test
 {
-
-    
-    public void testAgreement()
+    @Test
+    void testAgreement()
     {
         ICodingAnnotationStudy study = createExample();
 
@@ -73,5 +73,4 @@ public static ICodingAnnotationStudy createExample()
         study.addMultipleItems(10, 4, 4);
         return study;
     }
-
 }
diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/ArtsteinPoesio2008Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/ArtsteinPoesio2008Test.java
index 09b6e18..437474f 100644
--- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/ArtsteinPoesio2008Test.java
+++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/ArtsteinPoesio2008Test.java
@@ -17,12 +17,13 @@
  */
 package org.dkpro.statistics.agreement.coding;
 
-import static junit.framework.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.offset;
 
 import org.dkpro.statistics.agreement.IAnnotationStudy;
 import org.dkpro.statistics.agreement.distance.IDistanceFunction;
 import org.dkpro.statistics.agreement.distance.NominalDistanceFunction;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 /**
  * Tests based on Artstein & Poesio (2008) for several inter-rater agreement measures.
@@ -35,32 +36,32 @@ * * @author Christian M. Meyer */ -public class ArtsteinPoesio2008Test +class ArtsteinPoesio2008Test { @Test - public void testExample1() + void testExample1() { ICodingAnnotationStudy study = createExample1(); // Two raters, observed agreement. PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.7, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.7, offset(0.001)); // Two raters, chance-corrected agreement. BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.7, s.calculateObservedAgreement(), 0.001); - assertEquals(0.5, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.4, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.4, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.7, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.545, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.341, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.545, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.341, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.7, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.54, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.348, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.54, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.348, offset(0.001)); } @Test @@ -69,22 +70,22 @@ public void testExample2() ICodingAnnotationStudy study = createExample2(); PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.88, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.88, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.88, s.calculateObservedAgreement(), 0.001); - assertEquals(0.333, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.82, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.88, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.333, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.82, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.88, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.401, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.799, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.88, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.401, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.799, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.88, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.396, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.801, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.88, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.396, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.801, offset(0.001)); } /* @@ -118,42 +119,42 @@ public double measureDistance(final IAnnotationStudy study, final Object categor // Unweighted coefficients. PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.880, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.880, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.880, s.calculateObservedAgreement(), 0.001); - assertEquals(0.333, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.820, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.880, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.333, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.820, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.880, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.4014, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.7995, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.880, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.4014, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.7995, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.880, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.396, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.8013, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.880, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.396, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.8013, offset(0.001)); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.120, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.601, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.800, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.120, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.601, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.800, offset(0.001)); alpha.setDistanceFunction(weightedDistanceFunction); - assertEquals(0.090, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.4879, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.8156, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.090, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.4879, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.8156, offset(0.001)); WeightedKappaAgreement kappaW = new WeightedKappaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.120, kappaW.calculateObservedDisagreement(), 0.001); - assertEquals(0.604, kappaW.calculateExpectedDisagreement(), 0.001); - assertEquals(0.8013, kappaW.calculateAgreement(), 0.001); + assertThat(kappaW.calculateObservedDisagreement()).isCloseTo(0.120, offset(0.001)); + assertThat(kappaW.calculateExpectedDisagreement()).isCloseTo(0.604, offset(0.001)); + assertThat(kappaW.calculateAgreement()).isCloseTo(0.8013, offset(0.001)); kappaW.setDistanceFunction(weightedDistanceFunction); - assertEquals(0.090, kappaW.calculateObservedDisagreement(), 0.001); - assertEquals(0.490, kappaW.calculateExpectedDisagreement(), 0.001); - assertEquals(0.8163, kappaW.calculateAgreement(), 0.001); + assertThat(kappaW.calculateObservedDisagreement()).isCloseTo(0.090, offset(0.001)); + assertThat(kappaW.calculateExpectedDisagreement()).isCloseTo(0.490, offset(0.001)); + assertThat(kappaW.calculateAgreement()).isCloseTo(0.8163, offset(0.001)); } /** diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/BrennanPrediger1981Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/BrennanPrediger1981Test.java index 86c9a59..307d00d 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/BrennanPrediger1981Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/BrennanPrediger1981Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Brennan & Prediger (1981) for measuring {@link BennettSAgreement} and @@ -31,51 +34,49 @@ * * @author Christian M. Meyer */ -public class BrennanPrediger1981Test - extends TestCase +class BrennanPrediger1981Test { - - + @Test public void testExample1() { ICodingAnnotationStudy study = createExample1(); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.60, kappa.calculateObservedAgreement(), 0.01); - assertEquals(0.45, kappa.calculateExpectedAgreement(), 0.01); - assertEquals(0.27, kappa.calculateAgreement(), 0.01); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.60, offset(0.01)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.45, offset(0.01)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.27, offset(0.01)); BennettSAgreement S = new BennettSAgreement(study); - assertEquals(0.60, S.calculateObservedAgreement(), 0.01); - assertEquals(0.33, S.calculateExpectedAgreement(), 0.01); - assertEquals(0.40, S.calculateAgreement(), 0.01); + assertThat(S.calculateObservedAgreement()).isCloseTo(0.60, offset(0.01)); + assertThat(S.calculateExpectedAgreement()).isCloseTo(0.33, offset(0.01)); + assertThat(S.calculateAgreement()).isCloseTo(0.40, offset(0.01)); // max A_O = sum min{marginals} -> 0.7 - // assertEquals(0.60, kappa / max-kappa, 0.01); + // assertThat(kappa / max-kappa).isCloseTo(0.60, offset(0.01)); // assertEquals(-1.00, kappa_b, 0.01); } - - public void testExample2() + @Test + void testExample2() { ICodingAnnotationStudy study = createExample2(); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.60, kappa.calculateObservedAgreement(), 0.01); - assertEquals(0.44, kappa.calculateExpectedAgreement(), 0.01); - assertEquals(0.29, kappa.calculateAgreement(), 0.01); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.60, offset(0.01)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.44, offset(0.01)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.29, offset(0.01)); BennettSAgreement S = new BennettSAgreement(study); - assertEquals(0.60, S.calculateObservedAgreement(), 0.01); - assertEquals(0.33, S.calculateExpectedAgreement(), 0.01); - assertEquals(0.40, S.calculateAgreement(), 0.01); + assertThat(S.calculateObservedAgreement()).isCloseTo(0.60, offset(0.01)); + assertThat(S.calculateExpectedAgreement()).isCloseTo(0.33, offset(0.01)); + assertThat(S.calculateAgreement()).isCloseTo(0.40, offset(0.01)); // max A_O = sum min{marginals} -> 1 - // assertEquals(0.29, kappa / max-kappa, 0.01); + // assertThat(kappa / max-kappa).isCloseTo(0.29, offset(0.01)); // A_E = max. marginal (majority class) - // assertEquals(0.00, kappa_b, 0.01); + // assertThat(kappa_b).isCloseTo(0.00, offset(0.01)); } /** diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Cohen1960Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Cohen1960Test.java index 0177798..0359810 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Cohen1960Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Cohen1960Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Cohen (1960) for measuring {@link CohenKappaAgreement}.
@@ -30,38 +33,36 @@ * * @author Christian M. Meyer */ -public class Cohen1960Test - extends TestCase +class Cohen1960Test { - - + @Test public void testExample1() { ICodingAnnotationStudy study = createExample1(); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.29, kappa.calculateObservedAgreement(), 0.01); - assertEquals(0.35, kappa.calculateExpectedAgreement(), 0.01); - assertEquals(0.90, kappa.calculateMaximumObservedAgreement(), 0.01); - assertEquals(0.85, kappa.calculateMaximumAgreement(), 0.01); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.29, offset(0.01)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.35, offset(0.01)); + assertThat(kappa.calculateMaximumObservedAgreement()).isCloseTo(0.90, offset(0.01)); + assertThat(kappa.calculateMaximumAgreement()).isCloseTo(0.85, offset(0.01)); } - - public void testExample2() + @Test + void testExample2() { ICodingAnnotationStudy study = createExample2(); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.70, kappa.calculateObservedAgreement(), 0.01); - assertEquals(0.41, kappa.calculateExpectedAgreement(), 0.01); - assertEquals(0.492, kappa.calculateAgreement(), 0.001); - assertEquals(0.831, kappa.calculateMaximumAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.70, offset(0.01)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.41, offset(0.01)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.492, offset(0.001)); + assertThat(kappa.calculateMaximumAgreement()).isCloseTo(0.831, offset(0.001)); } /** * Creates an example annotation study introduced by Cohen (1960: p. 37). */ - public static ICodingAnnotationStudy createExample1() + static ICodingAnnotationStudy createExample1() { CodingAnnotationStudy study = new CodingAnnotationStudy(2); study.addMultipleItems(25, 1, 1); @@ -79,7 +80,7 @@ public static ICodingAnnotationStudy createExample1() /** * Creates an example annotation study introduced by Cohen (1960: p. 45). */ - public static ICodingAnnotationStudy createExample2() + static ICodingAnnotationStudy createExample2() { CodingAnnotationStudy study = new CodingAnnotationStudy(2); study.addMultipleItems(88, 1, 1); diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Fleiss1971Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Fleiss1971Test.java index 9aef08d..a5aba65 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Fleiss1971Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Fleiss1971Test.java @@ -17,11 +17,15 @@ */ package org.dkpro.statistics.agreement.coding; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + import java.util.Iterator; import org.dkpro.statistics.agreement.ICategorySpecificAgreement; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Tests based on Fleiss (1971) for measuring {@link FleissKappaAgreement}.
@@ -35,81 +39,82 @@ * @author Christian M. Meyer */ public class Fleiss1971Test - extends TestCase { - - + @Test public void testAgreement() { ICodingAnnotationStudy study = createExample(); assertEquals(30, study.getItemCount()); FleissKappaAgreement kappa = new FleissKappaAgreement(study); - assertEquals(0.5556, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.2201, kappa.calculateExpectedAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.5556, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.2201, offset(0.001)); double agreement = kappa.calculateAgreement(); - assertEquals(0.430, agreement, 0.001); + assertThat(agreement).isCloseTo(0.430, offset(0.001)); // Var = 0.000759 = 2/n*m(m-1) * (AE - (2m-3)AE^2 + 2(m-2)AE / (1-AE)^2) // SE = 0.028 // TODO /* * double se = raw.standardError(agreement); double[] ci = raw.confidenceInterval(agreement, - * se, RawAgreement.CONFIDENCE_95); assertEquals(0.028, se, 0.001); assertEquals(0.610, - * ci[0], 0.001); assertEquals(0.789, ci[1], 0.001); + * se, RawAgreement.CONFIDENCE_95); + * assertThat(se).isCloseTo(0.028, offset(0.001)); + * assertEquals(0.610, ci[0], 0.001); assertThat(ci[1]).isCloseTo(0.789, offset(0.001)); */ } + @Test public void testCategoryAgreement() { ICodingAnnotationStudy study = createExample(); ICategorySpecificAgreement catAgreement = new FleissKappaAgreement(study); - assertEquals(0.248, catAgreement.calculateCategoryAgreement(1), 0.005); - assertEquals(0.248, catAgreement.calculateCategoryAgreement(2), 0.005); - assertEquals(0.517, catAgreement.calculateCategoryAgreement(3), 0.005); - assertEquals(0.470, catAgreement.calculateCategoryAgreement(4), 0.005); - assertEquals(0.565, catAgreement.calculateCategoryAgreement(5), 0.005); + assertThat(catAgreement.calculateCategoryAgreement(1)).isCloseTo(0.248, offset(0.005)); + assertThat(catAgreement.calculateCategoryAgreement(2)).isCloseTo(0.248, offset(0.005)); + assertThat(catAgreement.calculateCategoryAgreement(3)).isCloseTo(0.517, offset(0.005)); + assertThat(catAgreement.calculateCategoryAgreement(4)).isCloseTo(0.470, offset(0.005)); + assertThat(catAgreement.calculateCategoryAgreement(5)).isCloseTo(0.565, offset(0.005)); } + @Test public void testItemAgreement() { ICodingAnnotationStudy study = createExample(); ICodingItemSpecificAgreement agreement = new PercentageAgreement(study); Iterator iter = study.getItems().iterator(); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.400, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.400, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.400, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.267, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.400, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.400, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.267, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.267, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.267, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.267, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.400, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.467, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.667, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.400, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.400, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.400, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.267, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.400, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.400, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.267, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.267, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.267, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.267, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.400, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.467, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.667, offset(0.001)); + assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); assertFalse(iter.hasNext()); } @@ -153,5 +158,4 @@ public static ICodingAnnotationStudy createExample() study.addItem(5, 5, 5, 5, 5, 5); return study; } - } diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/HayesKrippendorff2007Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/HayesKrippendorff2007Test.java index 4bcf0db..9cb50da 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/HayesKrippendorff2007Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/HayesKrippendorff2007Test.java @@ -17,9 +17,11 @@ */ package org.dkpro.statistics.agreement.coding; -import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; -import junit.framework.TestCase; +import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction; +import org.junit.jupiter.api.Test; /** * Tests based on Hayes & Krippendorff (2007) for measuring {@link KrippendorffAlphaAgreement} @@ -34,17 +36,15 @@ * @author Christian M. Meyer */ public class HayesKrippendorff2007Test - extends TestCase { - - + @Test public void testAgreement() { ICodingAnnotationStudy study = createExample(); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new OrdinalDistanceFunction()); - assertEquals(0.7598, alpha.calculateAgreement(), 0.0001); + assertThat(alpha.calculateAgreement()).isCloseTo(0.7598, offset(0.0001)); } /** diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff1980Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff1980Test.java index 263bd19..3a9d071 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff1980Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff1980Test.java @@ -17,14 +17,16 @@ */ package org.dkpro.statistics.agreement.coding; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + import org.dkpro.statistics.agreement.ICategorySpecificAgreement; import org.dkpro.statistics.agreement.distance.IDistanceFunction; import org.dkpro.statistics.agreement.distance.IntervalDistanceFunction; import org.dkpro.statistics.agreement.distance.NominalDistanceFunction; import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction; import org.dkpro.statistics.agreement.distance.RatioDistanceFunction; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Tests based on Krippendorff (1980) for measuring {@link KrippendorffAlphaAgreement}.
@@ -38,40 +40,38 @@ * @author Christian M. Meyer */ public class Krippendorff1980Test - extends TestCase { - - + @Test public void testDichotomy() { ICodingAnnotationStudy study = createExample1(); PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.600, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.600, offset(0.001)); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.400, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.442, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.095, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.400, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.442, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.095, offset(0.001)); } - + @Test public void testMultiCategoryMultiRater() { ICodingAnnotationStudy study = createExample2(); PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.740, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.740, offset(0.001)); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.259, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.724, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.642, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.259, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.724, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.642, offset(0.001)); } - + @Test public void testOrdinalMetric() { CodingAnnotationStudy study = new CodingAnnotationStudy(2); @@ -85,23 +85,20 @@ public void testOrdinalMetric() study.addItem(4, 4); study.addItem(5, 5); study.addItem(10, 10); - + IDistanceFunction distFunc = new OrdinalDistanceFunction(); - - final double[][] EXPECTED = new double[][]{ - { 0.0, 2.0, 5.0, 11.0, 16.0, 18.0 }, - { 2.0, 0.0, 3.0, 9.0, 14.0, 16.0 }, - { 5.0, 3.0, 0.0, 6.0, 11.0, 13.0 }, - { 11.0, 9.0, 6.0, 0.0, 5.0, 7.0 }, - { 16.0, 14.0, 11.0, 5.0, 0.0, 2.0 }, - { 18.0, 16.0, 13.0, 7.0, 2.0, 0.0 } - }; + + final double[][] EXPECTED = new double[][] { { 0.0, 2.0, 5.0, 11.0, 16.0, 18.0 }, + { 2.0, 0.0, 3.0, 9.0, 14.0, 16.0 }, { 5.0, 3.0, 0.0, 6.0, 11.0, 13.0 }, + { 11.0, 9.0, 6.0, 0.0, 5.0, 7.0 }, { 16.0, 14.0, 11.0, 5.0, 0.0, 2.0 }, + { 18.0, 16.0, 13.0, 7.0, 2.0, 0.0 } }; int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -109,7 +106,7 @@ public void testOrdinalMetric() } } - + @Test public void testNominalMetric() { CodingAnnotationStudy study = new CodingAnnotationStudy(1); @@ -119,22 +116,21 @@ public void testNominalMetric() IDistanceFunction distFunc = new NominalDistanceFunction(); - final double[][] EXPECTED = new double[][]{ - { 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, - { 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, - { 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, - { 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0 }, - { 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0 }, - { 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0 }, - { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0 }, - { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0 } - }; + final double[][] EXPECTED = new double[][] { { 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, + { 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, + { 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, + { 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0 }, + { 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0 }, + { 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0 }, + { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0 }, + { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0 } }; int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -142,7 +138,7 @@ public void testNominalMetric() } } - + @Test public void testIntervallMetric() { CodingAnnotationStudy study = new CodingAnnotationStudy(1); @@ -151,23 +147,22 @@ public void testIntervallMetric() } IDistanceFunction distFunc = new IntervalDistanceFunction(); - - final double[][] EXPECTED = new double[][]{ - { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }, - { 1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }, - { 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }, - { 3.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 4.0 }, - { 4.0, 3.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0 }, - { 5.0, 4.0, 3.0, 2.0, 1.0, 0.0, 1.0, 2.0 }, - { 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0, 1.0 }, - { 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 } - }; + + final double[][] EXPECTED = new double[][] { { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }, + { 1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }, + { 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }, + { 3.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 4.0 }, + { 4.0, 3.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0 }, + { 5.0, 4.0, 3.0, 2.0, 1.0, 0.0, 1.0, 2.0 }, + { 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0, 1.0 }, + { 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 } }; int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -177,43 +172,44 @@ public void testIntervallMetric() study = createExample2(); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new IntervalDistanceFunction()); - assertEquals(0.547, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateAgreement()).isCloseTo(0.547, offset(0.001)); } - - public void testRatioMetric() { + @Test + public void testRatioMetric() + { CodingAnnotationStudy study = new CodingAnnotationStudy(1); for (int i = 0; i <= 7; i++) { study.addCategory(i); } - + IDistanceFunction distFunc = new RatioDistanceFunction(); - - final double[][] EXPECTED = new double[][]{ - { 0.0 , 1.0 / 1.0, 2.0 / 2.0, 3.0 / 3.0, 4.0 / 4.0, 5.0 / 5.0, - 6.0 / 6.0, 7.0 / 7.0 }, - { 1.0 / 1.0, 0.0 / 2.0, 1.0 / 3.0, 2.0 / 4.0, 3.0 / 5.0, 4.0 / 6.0, 5.0 / - 7.0, 6.0 / 8.0 }, - { 2.0 / 2.0, 1.0 / 3.0, 0.0 / 4.0, 1.0 / 5.0, 2.0 / 6.0, 3.0 / 7.0, 4.0 / - 8.0, 5.0 / 9.0 }, - { 3.0 / 3.0, 2.0 / 4.0, 1.0 / 5.0, 0.0 / 6.0, 1.0 / 7.0, 2.0 / 8.0, 3.0 / - 9.0, 4.0 / 10.0 }, - { 4.0 / 4.0, 3.0 / 5.0, 2.0 / 6.0, 1.0 / 7.0, 0.0 / 8.0, 1.0 / 9.0, 2.0 / - 10.0, 3.0 / 11.0 }, - { 5.0 / 5.0, 4.0 / 6.0, 3.0 / 7.0, 2.0 / 8.0, 1.0 / 9.0, 0.0 / 10.0, 1.0 / - 11.0, 2.0 / 12.0 }, - { 6.0 / 6.0, 5.0 / 7.0, 4.0 / 8.0, 3.0 / 9.0, 2.0 / 10.0, 1.0 / 11.0, 0.0 / - 12.0, 1.0 / 13.0 }, - { 7.0 / 7.0, 6.0 / 8.0, 5.0 / 9.0, 4.0 / 10.0, 3.0 / 11.0, 2.0 / 12.0, 1.0 / - 13.0, 0.0 / 14.0 } - }; - + + final double[][] EXPECTED = new double[][] { + { 0.0, 1.0 / 1.0, 2.0 / 2.0, 3.0 / 3.0, 4.0 / 4.0, 5.0 / 5.0, 6.0 / 6.0, + 7.0 / 7.0 }, + { 1.0 / 1.0, 0.0 / 2.0, 1.0 / 3.0, 2.0 / 4.0, 3.0 / 5.0, 4.0 / 6.0, 5.0 / 7.0, + 6.0 / 8.0 }, + { 2.0 / 2.0, 1.0 / 3.0, 0.0 / 4.0, 1.0 / 5.0, 2.0 / 6.0, 3.0 / 7.0, 4.0 / 8.0, + 5.0 / 9.0 }, + { 3.0 / 3.0, 2.0 / 4.0, 1.0 / 5.0, 0.0 / 6.0, 1.0 / 7.0, 2.0 / 8.0, 3.0 / 9.0, + 4.0 / 10.0 }, + { 4.0 / 4.0, 3.0 / 5.0, 2.0 / 6.0, 1.0 / 7.0, 0.0 / 8.0, 1.0 / 9.0, 2.0 / 10.0, + 3.0 / 11.0 }, + { 5.0 / 5.0, 4.0 / 6.0, 3.0 / 7.0, 2.0 / 8.0, 1.0 / 9.0, 0.0 / 10.0, 1.0 / 11.0, + 2.0 / 12.0 }, + { 6.0 / 6.0, 5.0 / 7.0, 4.0 / 8.0, 3.0 / 9.0, 2.0 / 10.0, 1.0 / 11.0, 0.0 / 12.0, + 1.0 / 13.0 }, + { 7.0 / 7.0, 6.0 / 8.0, 5.0 / 9.0, 4.0 / 10.0, 3.0 / 11.0, 2.0 / 12.0, 1.0 / 13.0, + 0.0 / 14.0 } }; + int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -223,73 +219,74 @@ public void testRatioMetric() { study = createExample2(); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new RatioDistanceFunction()); - assertEquals(0.483, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateAgreement()).isCloseTo(0.483, offset(0.001)); } - /* ** / - public void testItemAgreement() { - ICodingAnnotationStudy study = createExample2(); - - ICodingItemSpecificAgreement agreement = new PercentageAgreement(study); - Iterator iter = study.getItems().iterator(); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.333, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.333, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertFalse(iter.hasNext()); - - agreement = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - iter = study.getItems().iterator(); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - // Next line -- error in D_O within original publication? - //assertEquals(0.539, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.078, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - // Next line -- error in D_O within original publication? - //assertEquals(0.539, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(0.078, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(-.382, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertEquals(1.000, agreement.calculateItemAgreement(iter.next()), 0.001); - assertFalse(iter.hasNext()); - }*/ + /* + * ** / + * + * @Test public void testItemAgreement() { ICodingAnnotationStudy study = createExample2(); + * + * ICodingItemSpecificAgreement agreement = new PercentageAgreement(study); + * Iterator iter = study.getItems().iterator(); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.333, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.333, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertFalse(iter.hasNext()); + * + * agreement = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); iter = + * study.getItems().iterator(); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); // + * Next line -- error in D_O within original publication? + * //assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.539, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.078, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); // + * Next line -- error in D_O within original publication? + * //assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.539, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(0.078, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertEquals(-.382, agreement.calculateItemAgreement(iter.next()), 0.001); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertThat(agreement.calculateItemAgreement(iter.next())).isCloseTo(1.000, offset(0.001)); + * assertFalse(iter.hasNext()); } + */ - - public void testCategoryAgreement() { + @Test + public void testCategoryAgreement() + { ICodingAnnotationStudy study = createExample2(); - + ICategorySpecificAgreement agreement = new PercentageAgreement(study); - assertEquals(0.777, agreement.calculateCategoryAgreement(1), 0.001); - assertEquals(0.852, agreement.calculateCategoryAgreement(2), 0.001); - assertEquals(0.926, agreement.calculateCategoryAgreement(3), 0.001); - assertEquals(0.926, agreement.calculateCategoryAgreement(4), 0.001); + assertThat(agreement.calculateCategoryAgreement(1)).isCloseTo(0.777, offset(0.001)); + assertThat(agreement.calculateCategoryAgreement(2)).isCloseTo(0.852, offset(0.001)); + assertThat(agreement.calculateCategoryAgreement(3)).isCloseTo(0.926, offset(0.001)); + assertThat(agreement.calculateCategoryAgreement(4)).isCloseTo(0.926, offset(0.001)); - agreement = new KrippendorffAlphaAgreement(study, - new NominalDistanceFunction()); - assertEquals(0.381, agreement.calculateCategoryAgreement(1), 0.001); - assertEquals(0.711, agreement.calculateCategoryAgreement(2), 0.001); - assertEquals(0.717, agreement.calculateCategoryAgreement(3), 0.001); - assertEquals(0.764, agreement.calculateCategoryAgreement(4), 0.001); + agreement = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); + assertThat(agreement.calculateCategoryAgreement(1)).isCloseTo(0.381, offset(0.001)); + assertThat(agreement.calculateCategoryAgreement(2)).isCloseTo(0.711, offset(0.001)); + assertThat(agreement.calculateCategoryAgreement(3)).isCloseTo(0.717, offset(0.001)); + assertThat(agreement.calculateCategoryAgreement(4)).isCloseTo(0.764, offset(0.001)); } - /* ** / - public void testRaterAgreement() { - ICodingAnnotationStudy study = createExample2(); - - IRaterSpecificAgreement agreement = new PercentageAgreement(study); - assertEquals(0.684, agreement.calculateRaterAgreement(1), 0.001); - - agreement = new KrippendorffAlphaAgreement(study, - new NominalDistanceFunction()); - assertEquals(0.564, agreement.calculateRaterAgreement(0), 0.001); - }*/ + /* + * ** / + * + * @Test public void testRaterAgreement() { ICodingAnnotationStudy study = createExample2(); + * + * IRaterSpecificAgreement agreement = new PercentageAgreement(study); + * assertThat(agreement.calculateRaterAgreement(1)).isCloseTo(0.684, offset(0.001)); + * + * agreement = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); + * assertThat(agreement.calculateRaterAgreement(0)).isCloseTo(0.564, offset(0.001)); } + */ /** * Creates an example annotation study introduced by Krippendorff (1980: p. 133). @@ -327,5 +324,5 @@ public static CodingAnnotationStudy createExample2() study.addItem(2, 2, 2); return study; } - + } diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff2004Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff2004Test.java index ebafe95..b01e3e1 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff2004Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Krippendorff2004Test.java @@ -17,13 +17,15 @@ */ package org.dkpro.statistics.agreement.coding; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + import org.dkpro.statistics.agreement.distance.IDistanceFunction; import org.dkpro.statistics.agreement.distance.IntervalDistanceFunction; import org.dkpro.statistics.agreement.distance.NominalDistanceFunction; import org.dkpro.statistics.agreement.distance.OrdinalDistanceFunction; import org.dkpro.statistics.agreement.distance.RatioDistanceFunction; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Tests based on Krippendorff (2004) for measuring {@link KrippendorffAlphaAgreement}.
@@ -37,75 +39,70 @@ * @author Christian M. Meyer */ public class Krippendorff2004Test - extends TestCase { - - + @Test public void testDichotomy() { ICodingAnnotationStudy study = createExample1(); PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(0.600, pa.calculateAgreement(), 0.001); + assertThat(pa.calculateAgreement()).isCloseTo(0.600, offset(0.001)); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.400, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.442, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.095, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.400, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.442, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.095, offset(0.001)); } - + @Test public void testMultipleCategories() { ICodingAnnotationStudy study = createExample2(); PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(0.833, pa.calculateAgreement(), 0.001); + assertThat(pa.calculateAgreement()).isCloseTo(0.833, offset(0.001)); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.1667, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.6268, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.734, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.1667, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.6268, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.734, offset(0.001)); } - + @Test public void testMultipleRatersMissingValues() { ICodingAnnotationStudy study = createExample3(); PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(0.800, pa.calculateAgreement(), 0.001); + assertThat(pa.calculateAgreement()).isCloseTo(0.800, offset(0.001)); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.200, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.779, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.743, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.200, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.779, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.743, offset(0.001)); } - + @Test public void testOrdinalMetric() { CodingAnnotationStudy study = createExample3a(0); IDistanceFunction distFunc = new OrdinalDistanceFunction(); - final double[][] EXPECTED = new double[][]{ - { 0.0, 11.0, 22.5, 30.0, 32.5, 34.0 }, - { 11.0, 0.0, 11.5, 19.0, 21.5, 23.0 }, - { 22.5, 11.5, 0.0, 7.5, 10.0, 11.5 }, - { 30.0, 19.0, 7.5, 0.0, 2.5, 4.0 }, - { 32.5, 21.5, 10.0, 2.5, 0.0, 1.5 }, - { 34.0, 23.0, 11.5, 4.0, 1.5, 0.0 } - }; + final double[][] EXPECTED = new double[][] { { 0.0, 11.0, 22.5, 30.0, 32.5, 34.0 }, + { 11.0, 0.0, 11.5, 19.0, 21.5, 23.0 }, { 22.5, 11.5, 0.0, 7.5, 10.0, 11.5 }, + { 30.0, 19.0, 7.5, 0.0, 2.5, 4.0 }, { 32.5, 21.5, 10.0, 2.5, 0.0, 1.5 }, + { 34.0, 23.0, 11.5, 4.0, 1.5, 0.0 } }; int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -113,27 +110,24 @@ public void testOrdinalMetric() } } - + @Test public void testIntervallMetric() { CodingAnnotationStudy study = createExample3a(-2); IDistanceFunction distFunc = new IntervalDistanceFunction(); - final double[][] EXPECTED = new double[][]{ - { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }, - { 1.0, 0.0, 1.0, 2.0, 3.0, 4.0 }, - { 2.0, 1.0, 0.0, 1.0, 2.0, 3.0 }, - { 3.0, 2.0, 1.0, 0.0, 1.0, 2.0 }, - { 4.0, 3.0, 2.0, 1.0, 0.0, 1.0 }, - { 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 } - }; + final double[][] EXPECTED = new double[][] { { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }, + { 1.0, 0.0, 1.0, 2.0, 3.0, 4.0 }, { 2.0, 1.0, 0.0, 1.0, 2.0, 3.0 }, + { 3.0, 2.0, 1.0, 0.0, 1.0, 2.0 }, { 4.0, 3.0, 2.0, 1.0, 0.0, 1.0 }, + { 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 } }; int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -141,28 +135,28 @@ public void testIntervallMetric() } } - + @Test public void testRatioMetric() { CodingAnnotationStudy study = createExample3a(-1); IDistanceFunction distFunc = new RatioDistanceFunction(); - final double[][] EXPECTED = new double[][]{ - { 0.0 , 1.0 / 1.0, 2.0 / 2.0, 3.0 / 3.0, 4.0 / 4.0, 5.0 / 5.0 }, - { 1.0 / 1.0, 0.0 / 2.0, 1.0 / 3.0, 2.0 / 4.0, 3.0 / 5.0, 4.0 / 6.0 }, - { 2.0 / 2.0, 1.0 / 3.0, 0.0 / 4.0, 1.0 / 5.0, 2.0 / 6.0, 3.0 / 7.0 }, - { 3.0 / 3.0, 2.0 / 4.0, 1.0 / 5.0, 0.0 / 6.0, 1.0 / 7.0, 2.0 / 8.0 }, - { 4.0 / 4.0, 3.0 / 5.0, 2.0 / 6.0, 1.0 / 7.0, 0.0 / 8.0, 1.0 / 9.0 }, - { 5.0 / 5.0, 4.0 / 6.0, 3.0 / 7.0, 2.0 / 8.0, 1.0 / 9.0, 0.0 / 10.0 } - }; - + final double[][] EXPECTED = new double[][] { + { 0.0, 1.0 / 1.0, 2.0 / 2.0, 3.0 / 3.0, 4.0 / 4.0, 5.0 / 5.0 }, + { 1.0 / 1.0, 0.0 / 2.0, 1.0 / 3.0, 2.0 / 4.0, 3.0 / 5.0, 4.0 / 6.0 }, + { 2.0 / 2.0, 1.0 / 3.0, 0.0 / 4.0, 1.0 / 5.0, 2.0 / 6.0, 3.0 / 7.0 }, + { 3.0 / 3.0, 2.0 / 4.0, 1.0 / 5.0, 0.0 / 6.0, 1.0 / 7.0, 2.0 / 8.0 }, + { 4.0 / 4.0, 3.0 / 5.0, 2.0 / 6.0, 1.0 / 7.0, 0.0 / 8.0, 1.0 / 9.0 }, + { 5.0 / 5.0, 4.0 / 6.0, 3.0 / 7.0, 2.0 / 8.0, 1.0 / 9.0, 0.0 / 10.0 } }; + int i = 0; int j = 0; for (Object category1 : study.getCategories()) { for (Object category2 : study.getCategories()) { - assertEquals("item " + category1 + "," + category2, EXPECTED[i][j] * EXPECTED[i][j], - distFunc.measureDistance(study, category1, category2), 0.001); + assertThat(distFunc.measureDistance(study, category1, category2)) + .as("item " + category1 + "," + category2) + .isCloseTo(EXPECTED[i][j] * EXPECTED[i][j], offset(0.001)); j++; } i++; @@ -170,7 +164,7 @@ public void testRatioMetric() } } - + @Test public void testIntervallAgreement() { CodingAnnotationStudy study = createExample3b(); @@ -178,36 +172,36 @@ public void testIntervallAgreement() IDistanceFunction distFunc = new IntervalDistanceFunction(); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, distFunc); - assertEquals(0.433, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(2.872, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.849, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.433, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(2.872, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.849, offset(0.001)); } - + @Test public void testOtherCoefficients() { CodingAnnotationStudy study = createExample4a(); PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(0.460, pa.calculateAgreement(), 0.001); + assertThat(pa.calculateAgreement()).isCloseTo(0.460, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.190, s.calculateAgreement(), 0.001); + assertThat(s.calculateAgreement()).isCloseTo(0.190, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.186, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateAgreement()).isCloseTo(0.186, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.186, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateAgreement()).isCloseTo(0.186, offset(0.001)); study = createExample4b(); pa = new PercentageAgreement(study); - assertEquals(0.460, pa.calculateAgreement(), 0.001); + assertThat(pa.calculateAgreement()).isCloseTo(0.460, offset(0.001)); s = new BennettSAgreement(study); - assertEquals(0.190, s.calculateAgreement(), 0.001); + assertThat(s.calculateAgreement()).isCloseTo(0.190, offset(0.001)); pi = new ScottPiAgreement(study); - assertEquals(0.186, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateAgreement()).isCloseTo(0.186, offset(0.001)); kappa = new CohenKappaAgreement(study); - assertEquals(0.258, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateAgreement()).isCloseTo(0.258, offset(0.001)); } /** @@ -360,5 +354,5 @@ public static CodingAnnotationStudy createExample4b() study.addMultipleItems(20, "c", "c"); return study; } - + } diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Mieskes2009Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Mieskes2009Test.java index 8c79995..ba0a846 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Mieskes2009Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Mieskes2009Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Mieskes (2009) for category-specific agreement using @@ -33,34 +36,32 @@ * @author Margot Mieskes */ public class Mieskes2009Test - extends TestCase { - - - public void testAgreement() + @Test + void testAgreement() { ICodingAnnotationStudy study = createExample(); FleissKappaAgreement kappa = new FleissKappaAgreement(study); - assertEquals(0.84, kappa.calculateObservedAgreement(), 0.01); - assertEquals(0.20, kappa.calculateExpectedAgreement(), 0.01); - assertEquals(0.80, kappa.calculateAgreement(), 0.01); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.84, offset(0.01)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.20, offset(0.01)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.80, offset(0.01)); - assertEquals(1.00, kappa.calculateCategoryAgreement("INP"), 0.01); - assertEquals(1.00, kappa.calculateCategoryAgreement("JJ"), 0.01); - assertEquals(1.00, kappa.calculateCategoryAgreement("MD"), 0.01); - assertEquals(0.48, kappa.calculateCategoryAgreement("NN"), 0.01); - assertEquals(1.00, kappa.calculateCategoryAgreement("PRP"), 0.01); - assertEquals(0.56, kappa.calculateCategoryAgreement("RB"), 0.01); - assertEquals(0.67, kappa.calculateCategoryAgreement("UH"), 0.01); - assertEquals(0.29, kappa.calculateCategoryAgreement("VB"), 0.01); - assertEquals(-0.02, kappa.calculateCategoryAgreement("VBP"), 0.01); + assertThat(kappa.calculateCategoryAgreement("INP")).isCloseTo(1.00, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("JJ")).isCloseTo(1.00, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("MD")).isCloseTo(1.00, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("NN")).isCloseTo(0.48, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("PRP")).isCloseTo(1.00, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("RB")).isCloseTo(0.56, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("UH")).isCloseTo(0.67, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("VB")).isCloseTo(0.29, offset(0.01)); + assertThat(kappa.calculateCategoryAgreement("VBP")).isCloseTo(-0.02, offset(0.01)); } /** * Creates an example annotation study introduced by Mieskes (2009: p. 58). */ - public static ICodingAnnotationStudy createExample() + static ICodingAnnotationStudy createExample() { CodingAnnotationStudy study = new CodingAnnotationStudy(3); study.addItem("UH", "VB", "UH"); diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/MultiRaterAgreementTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/MultiRaterAgreementTest.java index 67f81e1..9646ad2 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/MultiRaterAgreementTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/MultiRaterAgreementTest.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests for {@link PercentageAgreement} and {@link FleissKappaAgreement}. @@ -25,10 +28,8 @@ * @author Christian M. Meyer */ public class MultiRaterAgreementTest - extends TestCase { - - + @Test public void testExample() { ICodingAnnotationStudy study = createExample(); @@ -36,20 +37,20 @@ public void testExample() // Generalized percentage of agreement. PercentageAgreement pa = new PercentageAgreement(study); double agreement = pa.calculateAgreement(); - assertEquals(0.533, agreement, 0.001); + assertThat(agreement).isCloseTo(0.533, offset(0.001)); //TODO /*double se = poa.standardError(agreement); double[] ci = poa.confidenceInterval(agreement, se, RawAgreement.CONFIDENCE_95); - assertEquals(0.045, se, 0.001); - assertEquals(0.610, ci[0], 0.001); - assertEquals(0.789, ci[1], 0.001);*/ + assertThat(se).isCloseTo(0.045, offset(0.001)); + assertThat(ci[0]).isCloseTo(0.610, offset(0.001)); + assertThat(ci[1]).isCloseTo(0.789, offset(0.001));*/ // Fleiss' multi-pi. FleissKappaAgreement pi = new FleissKappaAgreement(study); - assertEquals(0.533, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.508, pi.calculateExpectedAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.533, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.508, offset(0.001)); agreement = pi.calculateAgreement(); - assertEquals(0.049, agreement, 0.001); + assertThat(agreement).isCloseTo(0.049, offset(0.001)); } /** Creates an example annotation study. */ diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/NumericalStabilityTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/NumericalStabilityTest.java index 7aec3e8..00e1bb6 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/NumericalStabilityTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/NumericalStabilityTest.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests for numerical stability. @@ -25,34 +28,32 @@ * @author Christian M. Meyer */ public class NumericalStabilityTest - extends TestCase { - - + @Test public void testExample1() { ICodingAnnotationStudy study = createExample1(); PercentageAgreement raw = new PercentageAgreement(study); - assertEquals(0.9, raw.calculateAgreement(), 0.001); + assertThat(raw.calculateAgreement()).isCloseTo(0.9, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.9, s.calculateObservedAgreement(), 0.001); - assertEquals(0.5, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.8, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.9, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.8, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.9, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.5, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.8, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.9, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.8, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.9, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.5, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.8, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.9, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.8, offset(0.001)); } - + @Test public void testExample2() { ICodingAnnotationStudy study = createExample2(); @@ -72,60 +73,60 @@ public void testExample2() study = tmpStudy; PercentageAgreement raw = new PercentageAgreement(study); - assertEquals(0.9, raw.calculateAgreement(), 0.001); + assertThat(raw.calculateAgreement()).isCloseTo(0.9, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.9, s.calculateObservedAgreement(), 0.001); - assertEquals(0.5, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.8, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.9, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.8, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.9, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.759, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.585, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.9, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.759, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.585, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.9, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.756, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.590, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.9, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.756, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.590, offset(0.001)); } - + @Test public void testScaledArtsteinPoesio() { ICodingAnnotationStudy study = createExample2(500); // Two raters, observed agreement. PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(0.7, pa.calculateAgreement(), 0.001); + assertThat(pa.calculateAgreement()).isCloseTo(0.7, offset(0.001)); // Two raters, chance-corrected agreement. BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.7, s.calculateObservedAgreement(), 0.001); - assertEquals(0.5, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.4, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.4, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.7, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.545, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.341, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.545, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.341, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.7, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.54, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.348, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.54, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.348, offset(0.001)); } - + @Test public void testScaledFleiss() { ICodingAnnotationStudy study = createExample3(2000); FleissKappaAgreement pi = new FleissKappaAgreement(study); - assertEquals(0.5556, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.2201, pi.calculateExpectedAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.5556, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.2201, offset(0.001)); double agreement = pi.calculateAgreement(); - assertEquals(0.430, agreement, 0.001); + assertThat(agreement).isCloseTo(0.430, offset(0.001)); } /** @@ -214,5 +215,4 @@ public static ICodingAnnotationStudy createExample3(int scale) study.addMultipleItems(scale, 5, 5, 5, 5, 5, 5); return study; } - } diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Randolph2005Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Randolph2005Test.java index 928ee42..fc3700b 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Randolph2005Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Randolph2005Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Randolph (2005) for measuring {@link RandolphKappaAgreement} and @@ -33,33 +36,32 @@ * @author Christian M. Meyer */ public class Randolph2005Test - extends TestCase { - - + @Test public void testExample1() { ICodingAnnotationStudy study = createExample1(); FleissKappaAgreement pi = new FleissKappaAgreement(study); - assertEquals(0.67, pi.calculateObservedAgreement(), 0.01); - assertEquals(0.50, pi.calculateExpectedAgreement(), 0.01); - assertEquals(0.33, pi.calculateAgreement(), 0.01); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.67, offset(0.01)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.50, offset(0.01)); + assertThat(pi.calculateAgreement()).isCloseTo(0.33, offset(0.01)); RandolphKappaAgreement rk = new RandolphKappaAgreement(study); - assertEquals(0.33, rk.calculateAgreement(), 0.01); + assertThat(rk.calculateAgreement()).isCloseTo(0.33, offset(0.01)); } + @Test public void testExample2() { ICodingAnnotationStudy study = createExample2(); FleissKappaAgreement pi = new FleissKappaAgreement(study); - assertEquals(-0.2, pi.calculateAgreement(), 0.01); + assertThat(pi.calculateAgreement()).isCloseTo(-0.2, offset(0.01)); RandolphKappaAgreement rk = new RandolphKappaAgreement(study); - assertEquals(0.33, rk.calculateAgreement(), 0.01); + assertThat(rk.calculateAgreement()).isCloseTo(0.33, offset(0.01)); } /** diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/SetAnnotationsTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/SetAnnotationsTest.java index a3c45a6..29f575f 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/SetAnnotationsTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/SetAnnotationsTest.java @@ -17,11 +17,13 @@ */ package org.dkpro.statistics.agreement.coding; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + 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; +import org.junit.jupiter.api.Test; /** * Tests for {@link KrippendorffAlphaAgreement} with {@link SetAnnotationDistanceFunction} and @@ -31,58 +33,56 @@ * @author Tristan Miller */ public class SetAnnotationsTest - extends TestCase { - - + @Test public void testSetDistanceFunction() { ICodingAnnotationStudy study = createExample(); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, null); alpha.setDistanceFunction(new SetAnnotationDistanceFunction()); - assertEquals(0.333, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.409, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.186, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.333, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.409, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.186, offset(0.001)); } - + @Test public void testMASIDistanceFunction() { ICodingAnnotationStudy study = createExample(); KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, null); alpha.setDistanceFunction(new MASISetAnnotationDistanceFunction()); - assertEquals(0.253, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.338, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.252, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.253, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.338, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.252, offset(0.001)); } - + @Test public void testPercentageAgreement() { ICodingAnnotationStudy study = createExample(); PercentageAgreement percentageAgreement = new PercentageAgreement(study); - assertEquals(0.333, percentageAgreement.calculateAgreement(), 0.001); + assertThat(percentageAgreement.calculateAgreement()).isCloseTo(0.333, offset(0.001)); } - + @Test public void testMaxPercentageAgreement() { ICodingAnnotationStudy study = createExample(); MaxPercentageAgreement maxPercentageAgreement = new MaxPercentageAgreement(study); - assertEquals(0.667, maxPercentageAgreement.calculateAgreement(), 0.001); + assertThat(maxPercentageAgreement.calculateAgreement()).isCloseTo(0.667, offset(0.001)); } - + @Test public void testDiceAgreement() { ICodingAnnotationStudy study = createExample(); DiceAgreement DiceAgreement = new DiceAgreement(study); - assertEquals(0.5, DiceAgreement.calculateAgreement(), 0.001); + assertThat(DiceAgreement.calculateAgreement()).isCloseTo(0.5, offset(0.001)); } /** Creates an example annotation study. */ diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/TwoRaterAgreementTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/TwoRaterAgreementTest.java index 239c731..142d26e 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/TwoRaterAgreementTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/TwoRaterAgreementTest.java @@ -17,73 +17,75 @@ */ package org.dkpro.statistics.agreement.coding; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.offset; import java.util.Iterator; import org.dkpro.statistics.agreement.InsufficientDataException; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Tests for several inter-rater agreement measures with two raters. * @author Christian M. Meyer */ -public class TwoRaterAgreementTest extends TestCase { +public class TwoRaterAgreementTest { - + @Test public void testAgreement() { ICodingAnnotationStudy study = createExample(); PercentageAgreement pa = new PercentageAgreement(study); double agreement = pa.calculateAgreement(); - assertEquals(0.7, agreement); + assertThat(agreement).isEqualTo(0.7); //TODO // double se = poa.standardError(agreement); // double[] ci = poa.confidenceInterval(agreement, se, // TwoRaterObservedAgreement.CONFIDENCE_95); - // assertEquals(0.045, se, 0.001); - // assertEquals(0.610, ci[0], 0.001); - // assertEquals(0.789, ci[1], 0.001); + // assertThat(se).isCloseTo(0.045, offset(0.001)); + // assertThat(ci[0]).isCloseTo(0.610, offset(0.001)); + // assertThat(ci[1]).isCloseTo(0.789, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.7, s.calculateObservedAgreement(), 0.001); - assertEquals(0.5, s.calculateExpectedAgreement(), 0.001); - assertEquals(0.4, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(0.4, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.7, pi.calculateObservedAgreement(), 0.001); - assertEquals(0.545, pi.calculateExpectedAgreement(), 0.001); - assertEquals(0.341, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(pi.calculateExpectedAgreement()).isCloseTo(0.545, offset(0.001)); + assertThat(pi.calculateAgreement()).isCloseTo(0.341, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.7, kappa.calculateObservedAgreement(), 0.001); - assertEquals(0.54, kappa.calculateExpectedAgreement(), 0.001); - assertEquals(0.348, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateObservedAgreement()).isCloseTo(0.7, offset(0.001)); + assertThat(kappa.calculateExpectedAgreement()).isCloseTo(0.54, offset(0.001)); + assertThat(kappa.calculateAgreement()).isCloseTo(0.348, offset(0.001)); } - + @Test public void testItemSpecificAgreement() { ICodingAnnotationStudy study = createExample(); PercentageAgreement pa = new PercentageAgreement(study); Iterator itemIter = study.getItems().iterator(); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(0.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(0.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(0.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertEquals(1.0, pa.calculateItemAgreement(itemIter.next())); - assertFalse(itemIter.hasNext()); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(0.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(0.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(0.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(pa.calculateItemAgreement(itemIter.next())).isEqualTo(1.0); + assertThat(itemIter.hasNext()).isFalse(); } /* + @Test public void testCategorySpecificAgreement() { ICodingAnnotationStudy study = createExample(); @@ -91,10 +93,11 @@ public void testCategorySpecificAgreement() { new CoincidenceMatrixPrinter().print(System.out, study); PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(4 / 7, pa.calculateCategoryAgreement("low")); - assertEquals(10 / 13, pa.calculateCategoryAgreement("high")); + assertThat(pa.calculateCategoryAgreement("low")).isEqualTo(4 / 7); + assertThat(pa.calculateCategoryAgreement("high")).isEqualTo(10 / 13); }*/ + @Test public void testMissingCategories() { // Annotation categories not used by any rater must be added to @@ -107,12 +110,12 @@ public void testMissingCategories() study.addItem("A", "A"); PercentageAgreement pa = new PercentageAgreement(study); - assertEquals(1.0, pa.calculateAgreement()); + assertThat(pa.calculateAgreement()).isEqualTo(1.0); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(1.0, s.calculateObservedAgreement(), 0.001); - assertEquals(0.5, s.calculateExpectedAgreement(), 0.001); - assertEquals(1.0, s.calculateAgreement(), 0.001); + assertThat(s.calculateObservedAgreement()).isCloseTo(1.0, offset(0.001)); + assertThat(s.calculateExpectedAgreement()).isCloseTo(0.5, offset(0.001)); + assertThat(s.calculateAgreement()).isCloseTo(1.0, offset(0.001)); assertThatExceptionOfType(InsufficientDataException.class) .isThrownBy(() -> new ScottPiAgreement(study).calculateAgreement()); @@ -121,8 +124,7 @@ public void testMissingCategories() .isThrownBy(() -> new CohenKappaAgreement(study).calculateAgreement()); } - - + @Test public void testInsufficientData() { // Empty annotation study. @@ -154,7 +156,7 @@ public void testInsufficientData() .calculateAgreement()); } - + @Test public void testInvalidRaterCount() { CodingAnnotationStudy tooManyRatersStudy = new CodingAnnotationStudy(3); diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2010Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2010Test.java index ffa3663..04468ea 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2010Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2010Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Warrens (2010) for measuring several inter-rater agreement measures with more than @@ -35,33 +38,32 @@ * @author Christian M. Meyer */ public class Warrens2010Test - extends TestCase { - /***/ + @Test public void testAgreement() { ICodingAnnotationStudy study = createExample(); RandolphKappaAgreement s = new RandolphKappaAgreement(study); - assertEquals(0.8358, s.calculateAgreement(), 0.0001); + assertThat(s.calculateAgreement()).isCloseTo(0.8358, offset(0.0001)); FleissKappaAgreement pi = new FleissKappaAgreement(study); - assertEquals(0.8324, pi.calculateAgreement(), 0.0001); + assertThat(pi.calculateAgreement()).isCloseTo(0.8324, offset(0.0001)); HubertKappaAgreement kappaH = new HubertKappaAgreement(study); - assertEquals(0.8326, kappaH.calculateAgreement(), 0.0001); + assertThat(kappaH.calculateAgreement()).isCloseTo(0.8326, offset(0.0001)); // TODO LightKappaAgreement kappaL = new LightKappaAgreement(study); - // assertEquals(0.8325, kappaL.calculateAgreement(), 0.0001); + // assertThat(kappaL.calculateAgreement()).isCloseTo(0.8325, offset(0.0001)); } - /***/ + @Test public void testPairwiseEquivalenceHubertKappa() { CodingAnnotationStudy study = createExample(); HubertKappaAgreement kappaH = new HubertKappaAgreement(study); - assertEquals(0.8326, kappaH.calculateAgreement(), 0.0001); + assertThat(kappaH.calculateAgreement()).isCloseTo(0.8326, offset(0.0001)); double AOmean = 0.0; for (int r1 = 0; r1 < study.getRaterCount(); r1++) { @@ -74,16 +76,16 @@ public void testPairwiseEquivalenceHubertKappa() AOmean /= (double) (study.getRaterCount() * (double) (study.getRaterCount() - 1.0)); double AE = kappaH.calculateExpectedAgreement(); double kappaEquivalence = (AOmean - AE) / (1.0 - AE); - assertEquals(0.8326, kappaEquivalence, 0.0001); + assertThat(kappaEquivalence).isCloseTo(0.8326, offset(0.0001)); } - /***/ + @Test public void testPairwiseEquivalenceLightKappa() { CodingAnnotationStudy study = createExample(); // TODO LightKappaAgreement kappaL = new LightKappaAgreement(study); - // assertEquals(0.8325, kappaL.calculateAgreement(), 0.0001); + // assertThat(kappaL.calculateAgreement()).isCloseTo(0.8325, offset(0.0001)); double kappaEquivalence = 0.0; for (int r1 = 0; r1 < study.getRaterCount(); r1++) { @@ -95,7 +97,7 @@ public void testPairwiseEquivalenceLightKappa() kappaEquivalence *= 2.0; kappaEquivalence /= (double) (study.getRaterCount() * (double) (study.getRaterCount() - 1.0)); - assertEquals(0.8325, kappaEquivalence, 0.0001); + assertThat(kappaEquivalence).isCloseTo(0.8325, offset(0.0001)); } /** diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2012Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2012Test.java index 69ff01d..1dbc08d 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2012Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Warrens2012Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Warrens (2012) for measuring {@link HubertKappaAgreement}.
@@ -31,28 +34,27 @@ * @author Christian M. Meyer */ public class Warrens2012Test - extends TestCase { - - + @Test public void testExample1() { CodingAnnotationStudy study = createExample1(); HubertKappaAgreement kappaH = new HubertKappaAgreement(study); - assertEquals(0.802479, kappaH.calculateAgreement(), 0.000001); + assertThat(kappaH.calculateAgreement()).isCloseTo(0.802479, offset(0.000001)); // There is an error in the denominator of equation (3.2): // It should read 1 − (8/15)(2/3) − (7/15)(1/3) = 22/45 ICodingAnnotationStudy pairwiseStudy = study.extractRaters(0, 1); CohenKappaAgreement kappa2 = new CohenKappaAgreement(pairwiseStudy); - assertEquals(8.0 / 15.0 + 1.0 / 3.0, kappa2.calculateObservedAgreement(), 0.0001); - assertEquals((8.0 / 15.0) * (2.0 / 3.0) + (7.0 / 15.0) * (1.0 / 3.0), - kappa2.calculateExpectedAgreement(), 0.0001); - assertEquals(8.0 / 11.0, kappa2.calculateAgreement(), 0.0001); + assertThat(kappa2.calculateObservedAgreement()).isCloseTo(8.0 / 15.0 + 1.0 / 3.0, + offset(0.0001)); + assertThat(kappa2.calculateExpectedAgreement()) + .isCloseTo((8.0 / 15.0) * (2.0 / 3.0) + (7.0 / 15.0) * (1.0 / 3.0), offset(0.0001)); + assertThat(kappa2.calculateAgreement()).isCloseTo(8.0 / 11.0, offset(0.0001)); } - + @Test public void testExample2a() { ICodingAnnotationStudy study = createExample2a(); @@ -62,19 +64,19 @@ public void testExample2a() // When switching the frequencies 6 and 4 in the example, // we end up at a k(4,2) of 0.645! HubertKappaAgreement kappaH = new HubertKappaAgreement(study); - // assertEquals(0.645, kappaH.calculateAgreement(), 0.001); - assertEquals(0.675, kappaH.calculateAgreement(), 0.001); + // assertThat(kappaH.calculateAgreement()).isCloseTo(0.645, offset(0.001)); + assertThat(kappaH.calculateAgreement()).isCloseTo(0.675, offset(0.001)); // assertEquals(0.599, kappa(4,4).calculateAgreement(), 001); } - + @Test public void testExample2b() { ICodingAnnotationStudy study = createExample2b(); HubertKappaAgreement kappaH = new HubertKappaAgreement(study); - assertEquals(0.564, kappaH.calculateAgreement(), 0.001); + assertThat(kappaH.calculateAgreement()).isCloseTo(0.564, offset(0.001)); // assertEquals(0.625, kappa(4,4).calculateAgreement(), 001); } diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/WeightedAgreementTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/WeightedAgreementTest.java index 739f123..8510355 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/WeightedAgreementTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/WeightedAgreementTest.java @@ -17,14 +17,16 @@ */ package org.dkpro.statistics.agreement.coding; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + import java.util.Hashtable; import org.dkpro.statistics.agreement.IAnnotationStudy; import org.dkpro.statistics.agreement.distance.IDistanceFunction; import org.dkpro.statistics.agreement.distance.IntervalDistanceFunction; import org.dkpro.statistics.agreement.distance.NominalDistanceFunction; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Tests for {@link WeightedKappaAgreement} and {@link KrippendorffAlphaAgreement}. @@ -32,10 +34,8 @@ * @author Christian M. Meyer */ public class WeightedAgreementTest - extends TestCase { - - + @Test public void testDistanceFunction1() { ICodingAnnotationStudy study = createExample(); @@ -68,12 +68,13 @@ public double measureDistance(final IAnnotationStudy study, KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, null); alpha.setDistanceFunction(weightedDistanceFunction); - assertEquals(0.333, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.409, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.186, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.333, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.409, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.186, offset(0.001)); } + @Test public void testDistanceFunction2() { ICodingAnnotationStudy study = createExample(); @@ -106,11 +107,12 @@ public double measureDistance(final IAnnotationStudy study, KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, null); alpha.setDistanceFunction(weightedDistanceFunction); - assertEquals(0.253, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.338, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(0.252, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.253, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.338, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(0.252, offset(0.001)); } + @Test public void testMissingVariance() { CodingAnnotationStudy study = new CodingAnnotationStudy(2); @@ -120,22 +122,23 @@ public void testMissingVariance() KrippendorffAlphaAgreement alpha = new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.153, alpha.calculateObservedDisagreement(), 0.001); - assertEquals(0.150, alpha.calculateExpectedDisagreement(), 0.001); - assertEquals(-0.020, alpha.calculateAgreement(), 0.001); + assertThat(alpha.calculateObservedDisagreement()).isCloseTo(0.153, offset(0.001)); + assertThat(alpha.calculateExpectedDisagreement()).isCloseTo(0.150, offset(0.001)); + assertThat(alpha.calculateAgreement()).isCloseTo(-0.020, offset(0.001)); WeightedKappaAgreement kappaW = new WeightedKappaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.153, kappaW.calculateObservedDisagreement(), 0.001); - assertEquals(0.153, kappaW.calculateExpectedDisagreement(), 0.001); - assertEquals(0.000, kappaW.calculateAgreement(), 0.001); + assertThat(kappaW.calculateObservedDisagreement()).isCloseTo(0.153, offset(0.001)); + assertThat(kappaW.calculateExpectedDisagreement()).isCloseTo(0.153, offset(0.001)); + assertThat(kappaW.calculateAgreement()).isCloseTo(0.000, offset(0.001)); kappaW = new WeightedKappaAgreement(study, new IntervalDistanceFunction()); - assertEquals(0.096, kappaW.calculateObservedDisagreement(), 0.001); - assertEquals(0.096, kappaW.calculateExpectedDisagreement(), 0.001); - assertEquals(0.000, kappaW.calculateAgreement(), 0.001); + assertThat(kappaW.calculateObservedDisagreement()).isCloseTo(0.096, offset(0.001)); + assertThat(kappaW.calculateExpectedDisagreement()).isCloseTo(0.096, offset(0.001)); + assertThat(kappaW.calculateAgreement()).isCloseTo(0.000, offset(0.001)); } + @Test public void testNormalization() { CodingAnnotationStudy study = new CodingAnnotationStudy(2); @@ -145,14 +148,14 @@ public void testNormalization() WeightedKappaAgreement kappaW = new WeightedKappaAgreement(study, new NominalDistanceFunction()); - assertEquals(0.153, kappaW.calculateObservedDisagreement(), 0.001); - assertEquals(0.153, kappaW.calculateExpectedDisagreement(), 0.001); - assertEquals(0.000, kappaW.calculateAgreement(), 0.001); + assertThat(kappaW.calculateObservedDisagreement()).isCloseTo(0.153, offset(0.001)); + assertThat(kappaW.calculateExpectedDisagreement()).isCloseTo(0.153, offset(0.001)); + assertThat(kappaW.calculateAgreement()).isCloseTo(0.000, offset(0.001)); kappaW = new WeightedKappaAgreement(study, new IntervalDistanceFunction()); - assertEquals(0.096, kappaW.calculateObservedDisagreement(), 0.001); - assertEquals(0.096, kappaW.calculateExpectedDisagreement(), 0.001); - assertEquals(0.000, kappaW.calculateAgreement(), 0.001); + assertThat(kappaW.calculateObservedDisagreement()).isCloseTo(0.096, offset(0.001)); + assertThat(kappaW.calculateExpectedDisagreement()).isCloseTo(0.096, offset(0.001)); + assertThat(kappaW.calculateAgreement()).isCloseTo(0.000, offset(0.001)); } /** Creates an example annotation study. */ diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Zwick1988Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Zwick1988Test.java index 2a18c90..fa4f754 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Zwick1988Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Zwick1988Test.java @@ -17,7 +17,10 @@ */ package org.dkpro.statistics.agreement.coding; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** * Tests based on Zwick (1988) for several inter-rater agreement measures.
@@ -31,55 +34,55 @@ * @author Christian M. Meyer */ public class Zwick1988Test - extends TestCase { - - + @Test public void testExample1() { ICodingAnnotationStudy study = createExample1(); PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.600, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.600, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.467, s.calculateAgreement(), 0.001); + assertThat(s.calculateAgreement()).isCloseTo(0.467, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.467, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateAgreement()).isCloseTo(0.467, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.467, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateAgreement()).isCloseTo(0.467, offset(0.001)); } + @Test public void testExample2() { ICodingAnnotationStudy study = createExample2(); PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.600, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.600, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.467, s.calculateAgreement(), 0.001); + assertThat(s.calculateAgreement()).isCloseTo(0.467, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.444, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateAgreement()).isCloseTo(0.444, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.444, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateAgreement()).isCloseTo(0.444, offset(0.001)); } + @Test public void testExample3() { ICodingAnnotationStudy study = createExample3(); PercentageAgreement poa = new PercentageAgreement(study); - assertEquals(0.600, poa.calculateAgreement(), 0.001); + assertThat(poa.calculateAgreement()).isCloseTo(0.600, offset(0.001)); BennettSAgreement s = new BennettSAgreement(study); - assertEquals(0.467, s.calculateAgreement(), 0.001); + assertThat(s.calculateAgreement()).isCloseTo(0.467, offset(0.001)); ScottPiAgreement pi = new ScottPiAgreement(study); - assertEquals(0.460, pi.calculateAgreement(), 0.001); + assertThat(pi.calculateAgreement()).isCloseTo(0.460, offset(0.001)); CohenKappaAgreement kappa = new CohenKappaAgreement(study); - assertEquals(0.474, kappa.calculateAgreement(), 0.001); + assertThat(kappa.calculateAgreement()).isCloseTo(0.474, offset(0.001)); } /** diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff1995Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff1995Test.java index babb90c..59e0851 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff1995Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff1995Test.java @@ -17,7 +17,9 @@ */ package org.dkpro.statistics.agreement.unitizing; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.offset; import org.dkpro.statistics.agreement.InsufficientDataException; import org.dkpro.statistics.agreement.coding.CodingAnnotationStudy; @@ -25,25 +27,28 @@ import org.dkpro.statistics.agreement.coding.KrippendorffAlphaAgreement; import org.dkpro.statistics.agreement.coding.ScottPiAgreement; import org.dkpro.statistics.agreement.distance.NominalDistanceFunction; - -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** - * Tests based on Krippendorff (1995) for measuring - * {@link KrippendorffAlphaUnitizingAgreement}.

- * References:
    - *
  • Krippendorff, K.: On the reliability of unitizing contiguous data. - * Sociological Methodology 25:47–76, 1995.
+ * Tests based on Krippendorff (1995) for measuring {@link KrippendorffAlphaUnitizingAgreement}.
+ *
+ * References: + *
    + *
  • Krippendorff, K.: On the reliability of unitizing contiguous data. Sociological Methodology + * 25:47–76, 1995.
  • + *
+ * * @author Christian M. Meyer */ public class Krippendorff1995Test - extends TestCase { - public void testDigitizedAgreement() { -// IUnitizingAnnotationStudy study = createExample(1, "A"); -// ICodingAnnotationStudy digitizedStudy = study.digitize(); + @Test + public void testDigitizedAgreement() + { + // IUnitizingAnnotationStudy study = createExample(1, "A"); + // ICodingAnnotationStudy digitizedStudy = study.digitize(); - //TODO: Digitize method! + // TODO: Digitize method! // @formatter:off // A Bertha: 0 0|1 1 1 1 1 1 1 1|0 0 0 0|1 1 1 1 1 1|0 0 0 0 // Bill: 0 0 0 0|1 1 1 1|0 0 0 0 0 0 0|1 1|0 0 0 0 0 0 0 @@ -74,10 +79,12 @@ public void testDigitizedAgreement() { study.addItem(0, 0); study.addItem(0, 0); - assertEquals(0.385, new CohenKappaAgreement(study).calculateAgreement(), 0.001); - assertEquals(0.314, new ScottPiAgreement(study).calculateAgreement(), 0.001); - assertEquals(0.329, new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()) - .calculateAgreement(), 0.001); + assertThat(new CohenKappaAgreement(study).calculateAgreement()).isCloseTo(0.385, + offset(0.001)); + assertThat(new ScottPiAgreement(study).calculateAgreement()).isCloseTo(0.314, + offset(0.001)); + assertThat(new KrippendorffAlphaAgreement(study, new NominalDistanceFunction()) + .calculateAgreement()).isCloseTo(0.329, offset(0.001)); // @formatter:off // B John: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1|0 0 0 0 0 0 @@ -109,8 +116,10 @@ public void testDigitizedAgreement() { study.addItem(0, 0); study.addItem(0, 0); - assertEquals(0.385, new CohenKappaAgreement(study).calculateAgreement(), 0.001); - assertEquals(0.314, new ScottPiAgreement(study).calculateAgreement(), 0.001); + assertThat(new CohenKappaAgreement(study).calculateAgreement()).isCloseTo(0.385, + offset(0.001)); + assertThat(new ScottPiAgreement(study).calculateAgreement()).isCloseTo(0.314, + offset(0.001)); // @formatter:off // C Gerret: 0 0|1 1 1 1 1 1|0 0|1 1|0 0|1 1 1 1|0 0|1 1|0 0 @@ -142,17 +151,20 @@ public void testDigitizedAgreement() { study.addItem(0, 0); study.addItem(0, 0); - assertEquals(0.314, new CohenKappaAgreement(study).calculateAgreement(), 0.001); - assertEquals(0.314, new ScottPiAgreement(study).calculateAgreement(), 0.001); + assertThat(new CohenKappaAgreement(study).calculateAgreement()).isCloseTo(0.314, + offset(0.001)); + assertThat(new ScottPiAgreement(study).calculateAgreement()).isCloseTo(0.314, + offset(0.001)); } - + + @Test public void testThatAgreementThrowsInsufficientDataException() { // @formatter:off // D Heather: 1 1|1 1 1 1 1 1 1 1|1 1 1 1|1 1 1 1 1 1|1 1 1 1 // Hill: 1 1 1 1|1 1 1 1|1 1 1 1 1 1 1|1 1|1 1 1 1 1 1 1 // @formatter:on - + CodingAnnotationStudy study = new CodingAnnotationStudy(2); study.addItem(1, 1); study.addItem(1, 1); @@ -186,7 +198,9 @@ public void testThatAgreementThrowsInsufficientDataException() .isThrownBy(() -> new CohenKappaAgreement(study).calculateAgreement()); } - public void testVaryingLengths() { + @Test + public void testVaryingLengths() + { IUnitizingAnnotationStudy study; KrippendorffAlphaUnitizingAgreement alpha; @@ -195,74 +209,96 @@ public void testVaryingLengths() { // first plus should be a minus - see Krippendorff (2004). study = createExample(12 / 24.0); -// new UnitizingStudyPrinter().print(System.out, study, "C"); + // new UnitizingStudyPrinter().print(System.out, study, "C"); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.05494, alpha.calculateExpectedCategoryDisagreement("C"), 0.00001); - assertEquals(0.494, alpha.calculateCategoryAgreement("C"), 0.02); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.05494, + offset(0.00001)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.494, offset(0.02)); study = createExample(120 / 24.0); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.08234, alpha.calculateExpectedCategoryDisagreement("C"), 0.005); - assertEquals(0.663, alpha.calculateCategoryAgreement("C"), 0.02); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.08234, + offset(0.005)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.663, offset(0.02)); study = createExample(1200 / 24.0); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.08600, alpha.calculateExpectedCategoryDisagreement("C"), 0.005); - assertEquals(0.677, alpha.calculateCategoryAgreement("C"), 0.02); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.08600, + offset(0.005)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.677, offset(0.02)); study = createExample(12000 / 24.0); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.08638, alpha.calculateExpectedCategoryDisagreement("C"), 0.005); - assertEquals(0.678, alpha.calculateCategoryAgreement("C"), 0.02); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.08638, + offset(0.005)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.678, offset(0.02)); study = createExample(120000 / 24.0); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.08642, alpha.calculateExpectedCategoryDisagreement("C"), 0.005); - assertEquals(0.679, alpha.calculateCategoryAgreement("C"), 0.02); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.08642, + offset(0.005)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.679, offset(0.02)); study = createExample(1200000 / 24.0); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.08642, alpha.calculateExpectedCategoryDisagreement("C"), 0.005); - assertEquals(0.679, alpha.calculateCategoryAgreement("C"), 0.02); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.08642, + offset(0.005)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.679, offset(0.02)); } - - public void testAgreement() { + @Test + public void testAgreement() + { IUnitizingAnnotationStudy study = createExample(1); -// new UnitizingStudyPrinter().print(System.out, study); -// new UnitizingMatrixPrinter().print(System.out, study, "A", 0, 1); + // new UnitizingStudyPrinter().print(System.out, study); + // new UnitizingMatrixPrinter().print(System.out, study, "A", 0, 1); KrippendorffAlphaUnitizingAgreement alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.03125, alpha.calculateObservedCategoryDisagreement("A"), 0.00001); - assertEquals(2.26736, alpha.calculateObservedCategoryDisagreement("B"), 0.00001); - assertEquals(0.02777, alpha.calculateObservedCategoryDisagreement("C"), 0.00001); - assertEquals(0.38715, alpha.calculateObservedCategoryDisagreement("D"), 0.00001); + assertThat(alpha.calculateObservedCategoryDisagreement("A")).isCloseTo(0.03125, + offset(0.00001)); + assertThat(alpha.calculateObservedCategoryDisagreement("B")).isCloseTo(2.26736, + offset(0.00001)); + assertThat(alpha.calculateObservedCategoryDisagreement("C")).isCloseTo(0.02777, + offset(0.00001)); + assertThat(alpha.calculateObservedCategoryDisagreement("D")).isCloseTo(0.38715, + offset(0.00001)); study = createExample(1200000 / 24); alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.06990, alpha.calculateExpectedCategoryDisagreement("A"), 0.005); - assertEquals(1.17731, alpha.calculateExpectedCategoryDisagreement("B"), 0.005); - assertEquals(0.08642, alpha.calculateExpectedCategoryDisagreement("C"), 0.005); - assertEquals(0.41445, alpha.calculateExpectedCategoryDisagreement("D"), 0.005); + assertThat(alpha.calculateExpectedCategoryDisagreement("A")).isCloseTo(0.06990, + offset(0.005)); + assertThat(alpha.calculateExpectedCategoryDisagreement("B")).isCloseTo(1.17731, + offset(0.005)); + assertThat(alpha.calculateExpectedCategoryDisagreement("C")).isCloseTo(0.08642, + offset(0.005)); + assertThat(alpha.calculateExpectedCategoryDisagreement("D")).isCloseTo(0.41445, + offset(0.005)); - assertEquals( 0.553, alpha.calculateCategoryAgreement("A"), 0.02); - assertEquals(-0.926, alpha.calculateCategoryAgreement("B"), 0.02); - assertEquals( 0.679, alpha.calculateCategoryAgreement("C"), 0.02); - assertEquals( 0.066, alpha.calculateCategoryAgreement("D"), 0.02); + assertThat(alpha.calculateCategoryAgreement("A")).isCloseTo(0.553, offset(0.02)); + assertThat(alpha.calculateCategoryAgreement("B")).isCloseTo(-0.926, offset(0.02)); + assertThat(alpha.calculateCategoryAgreement("C")).isCloseTo(0.679, offset(0.02)); + assertThat(alpha.calculateCategoryAgreement("D")).isCloseTo(0.066, offset(0.02)); } - - /** Creates an example annotation study introduced by - * Krippendorff (1995: p. 57). */ - public static UnitizingAnnotationStudy createExample(double stretch) { - UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(2, - (int) (0 * stretch), (int) (24 * stretch)); + /** + * Creates an example annotation study introduced by Krippendorff (1995: p. 57). + */ + public static UnitizingAnnotationStudy createExample(double stretch) + { + UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(2, (int) (0 * stretch), + (int) (24 * stretch)); // @formatter:off // A Bertha: 0 0|1 1 1 1 1 1 1 1|0 0 0 0|1 1 1 1 1 1|0 0 0 0 // Bill: 0 0 0 0|1 1 1 1|0 0 0 0 0 0 0|1 1|0 0 0 0 0 0 0 @@ -274,40 +310,40 @@ public static UnitizingAnnotationStudy createExample(double stretch) { // Hill: 1 1 1 1|1 1 1 1|1 1 1 1 1 1 1|1 1|1 1 1 1 1 1 1 // @formatter:on - study.addUnit((int) ( 2 * stretch), (int) ( 8 * stretch), 0, "A"); - study.addUnit((int) (14 * stretch), (int) ( 6 * stretch), 0, "A"); - study.addUnit((int) ( 4 * stretch), (int) ( 4 * stretch), 1, "A"); - study.addUnit((int) (15 * stretch), (int) ( 2 * stretch), 1, "A"); + study.addUnit((int) (2 * stretch), (int) (8 * stretch), 0, "A"); + study.addUnit((int) (14 * stretch), (int) (6 * stretch), 0, "A"); + study.addUnit((int) (4 * stretch), (int) (4 * stretch), 1, "A"); + study.addUnit((int) (15 * stretch), (int) (2 * stretch), 1, "A"); - study.addUnit((int) ( 0 * stretch), (int) (18 * stretch), 0, "B"); - study.addUnit((int) ( 0 * stretch), (int) ( 2 * stretch), 1, "B"); - study.addUnit((int) ( 2 * stretch), (int) ( 1 * stretch), 1, "B"); - study.addUnit((int) ( 3 * stretch), (int) ( 1 * stretch), 1, "B"); - study.addUnit((int) ( 4 * stretch), (int) ( 1 * stretch), 1, "B"); - study.addUnit((int) ( 5 * stretch), (int) ( 1 * stretch), 1, "B"); - study.addUnit((int) ( 6 * stretch), (int) ( 3 * stretch), 1, "B"); - study.addUnit((int) ( 9 * stretch), (int) ( 1 * stretch), 1, "B"); + study.addUnit((int) (0 * stretch), (int) (18 * stretch), 0, "B"); + study.addUnit((int) (0 * stretch), (int) (2 * stretch), 1, "B"); + study.addUnit((int) (2 * stretch), (int) (1 * stretch), 1, "B"); + study.addUnit((int) (3 * stretch), (int) (1 * stretch), 1, "B"); + study.addUnit((int) (4 * stretch), (int) (1 * stretch), 1, "B"); + study.addUnit((int) (5 * stretch), (int) (1 * stretch), 1, "B"); + study.addUnit((int) (6 * stretch), (int) (3 * stretch), 1, "B"); + study.addUnit((int) (9 * stretch), (int) (1 * stretch), 1, "B"); - study.addUnit((int) ( 2 * stretch), (int) ( 6 * stretch), 0, "C"); - study.addUnit((int) (10 * stretch), (int) ( 2 * stretch), 0, "C"); - study.addUnit((int) (14 * stretch), (int) ( 4 * stretch), 0, "C"); - study.addUnit((int) (20 * stretch), (int) ( 2 * stretch), 0, "C"); - study.addUnit((int) ( 0 * stretch), (int) ( 2 * stretch), 1, "C"); - study.addUnit((int) ( 4 * stretch), (int) ( 4 * stretch), 1, "C"); - study.addUnit((int) (10 * stretch), (int) ( 4 * stretch), 1, "C"); - study.addUnit((int) (16 * stretch), (int) ( 2 * stretch), 1, "C"); - study.addUnit((int) (20 * stretch), (int) ( 2 * stretch), 1, "C"); + study.addUnit((int) (2 * stretch), (int) (6 * stretch), 0, "C"); + study.addUnit((int) (10 * stretch), (int) (2 * stretch), 0, "C"); + study.addUnit((int) (14 * stretch), (int) (4 * stretch), 0, "C"); + study.addUnit((int) (20 * stretch), (int) (2 * stretch), 0, "C"); + study.addUnit((int) (0 * stretch), (int) (2 * stretch), 1, "C"); + study.addUnit((int) (4 * stretch), (int) (4 * stretch), 1, "C"); + study.addUnit((int) (10 * stretch), (int) (4 * stretch), 1, "C"); + study.addUnit((int) (16 * stretch), (int) (2 * stretch), 1, "C"); + study.addUnit((int) (20 * stretch), (int) (2 * stretch), 1, "C"); - study.addUnit((int) ( 0 * stretch), (int) ( 2 * stretch), 0, "D"); - study.addUnit((int) ( 2 * stretch), (int) ( 8 * stretch), 0, "D"); - study.addUnit((int) (10 * stretch), (int) ( 4 * stretch), 0, "D"); - study.addUnit((int) (14 * stretch), (int) ( 6 * stretch), 0, "D"); - study.addUnit((int) (20 * stretch), (int) ( 4 * stretch), 0, "D"); - study.addUnit((int) ( 0 * stretch), (int) ( 4 * stretch), 1, "D"); - study.addUnit((int) ( 4 * stretch), (int) ( 4 * stretch), 1, "D"); - study.addUnit((int) ( 8 * stretch), (int) ( 7 * stretch), 1, "D"); - study.addUnit((int) (15 * stretch), (int) ( 2 * stretch), 1, "D"); - study.addUnit((int) (17 * stretch), (int) ( 7 * stretch), 1, "D"); + study.addUnit((int) (0 * stretch), (int) (2 * stretch), 0, "D"); + study.addUnit((int) (2 * stretch), (int) (8 * stretch), 0, "D"); + study.addUnit((int) (10 * stretch), (int) (4 * stretch), 0, "D"); + study.addUnit((int) (14 * stretch), (int) (6 * stretch), 0, "D"); + study.addUnit((int) (20 * stretch), (int) (4 * stretch), 0, "D"); + study.addUnit((int) (0 * stretch), (int) (4 * stretch), 1, "D"); + study.addUnit((int) (4 * stretch), (int) (4 * stretch), 1, "D"); + study.addUnit((int) (8 * stretch), (int) (7 * stretch), 1, "D"); + study.addUnit((int) (15 * stretch), (int) (2 * stretch), 1, "D"); + study.addUnit((int) (17 * stretch), (int) (7 * stretch), 1, "D"); return study; } diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff2004Test.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff2004Test.java index 2c1beb3..5d1298c 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff2004Test.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/Krippendorff2004Test.java @@ -17,81 +17,91 @@ */ package org.dkpro.statistics.agreement.unitizing; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; + +import org.junit.jupiter.api.Test; /** - * Tests based on Krippendorff (2004) for measuring - * {@link KrippendorffAlphaUnitizingAgreement}.

- * References:
    - *
  • Krippendorff, K.: Content Analysis: An Introduction to Its Methodology. - * Thousand Oaks, CA: Sage Publications, 2004.
+ * Tests based on Krippendorff (2004) for measuring {@link KrippendorffAlphaUnitizingAgreement}.
+ *
+ * References: + *
    + *
  • Krippendorff, K.: Content Analysis: An Introduction to Its Methodology. Thousand Oaks, CA: + * Sage Publications, 2004.
  • + *
+ * * @author Christian M. Meyer * @author Christian Stab */ public class Krippendorff2004Test - extends TestCase { - + @Test public void testDistanceMetric1() { - assertEquals(40.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 2, 3, null, 2, 2, "X") - + KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 4, 7, null)); - assertEquals(40.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 3, 2, null, 3, 2, "X") - + KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 5, 6, null)); - assertEquals(26.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 4, 2, "X")); - assertEquals(16.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 5, 2, "X")); - assertEquals(10.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 6, 2, "X")); - assertEquals(8.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 7, 2, "X")); - assertEquals(2.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 6, 4, "X")); - assertEquals(0.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 5, 6, "X", 5, 6, "X")); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(2, 3, null, 2, 2, "X") + + KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 4, 7, null)) + .isEqualTo(40.0); + + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(3, 2, null, 3, 2, "X") + + KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 5, 6, null)) + .isEqualTo(40.0); + + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 4, 2, "X")) + .isEqualTo(26.0); + + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 5, 2, "X")) + .isEqualTo(16.0); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 6, 2, "X")) + .isEqualTo(10.0); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 7, 2, "X")) + .isEqualTo(8.0); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 6, 4, "X")) + .isEqualTo(2.0); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(5, 6, "X", 5, 6, "X")) + .isEqualTo(0.0); + } - + @Test public void testDistanceMetric2() { - assertEquals(50.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 225, 70, "c", 220, 80, "c")); - assertEquals(850.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 370, 30, "c", 355, 20, "c")); - assertEquals(400.0, KrippendorffAlphaUnitizingAgreement.measureDistance( - 400, 50, null, 400, 20, "c")); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(225, 70, "c", 220, 80, "c")) + .isEqualTo(50.0); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(370, 30, "c", 355, 20, "c")) + .isEqualTo(850.0); + assertThat(KrippendorffAlphaUnitizingAgreement.measureDistance(400, 50, null, 400, 20, "c")) + .isEqualTo(400.0); } - + @Test public void testAgreement() { IUnitizingAnnotationStudy study = createExample(); KrippendorffAlphaUnitizingAgreement alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.8591, alpha.calculateAgreement(), 0.0005); + assertThat(alpha.calculateAgreement()).isCloseTo(0.8591, offset(0.0005)); } - - + + @Test public void testCategoryAgreement() { IUnitizingAnnotationStudy study = createExample(); - + KrippendorffAlphaUnitizingAgreement alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.0144, alpha.calculateObservedCategoryDisagreement("c"), 0.0001); - assertEquals(0.0532, alpha.calculateExpectedCategoryDisagreement("c"), 0.0001); - assertEquals(0.7286, alpha.calculateCategoryAgreement("c"), 0.0001); - - assertEquals(0.0000, alpha.calculateObservedCategoryDisagreement("k"), 0.0001); - assertEquals(0.0490, alpha.calculateExpectedCategoryDisagreement("k"), 0.0001); - assertEquals(1.0000, alpha.calculateCategoryAgreement("k"), 0.0001); + assertThat(alpha.calculateObservedCategoryDisagreement("c")).isCloseTo(0.0144, + offset(0.0001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("c")).isCloseTo(0.0532, + offset(0.0001)); + assertThat(alpha.calculateCategoryAgreement("c")).isCloseTo(0.7286, offset(0.0001)); + + assertThat(alpha.calculateObservedCategoryDisagreement("k")).isCloseTo(0.0000, + offset(0.0001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("k")).isCloseTo(0.0490, + offset(0.0001)); + assertThat(alpha.calculateCategoryAgreement("k")).isCloseTo(1.0000, offset(0.0001)); } - - + /** * Creates an example annotation study introduced by Krippendorff (2004: p. 254). */ @@ -100,18 +110,18 @@ public static UnitizingAnnotationStudy createExample() UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(2, 150, 300); // observer i is annotator 1 // observer j is annotator 2 - + // Gaps are automatically created! -// study.addItem(180, 60, 0, "k"); -// study.addItem(180, 60, 1, "k"); -// study.addItem(220, 80, 1, "c"); -// study.addItem(225, 70, 0, "c"); -// study.addItem(355, 20, 1, "c"); -// study.addItem(370, 30, 0, "c"); -// study.addItem(400, 20, 1, "c"); -// study.addItem(300, 50, 0, "k"); -// study.addItem(300, 50, 1, "k"); - + // study.addItem(180, 60, 0, "k"); + // study.addItem(180, 60, 1, "k"); + // study.addItem(220, 80, 1, "c"); + // study.addItem(225, 70, 0, "c"); + // study.addItem(355, 20, 1, "c"); + // study.addItem(370, 30, 0, "c"); + // study.addItem(400, 20, 1, "c"); + // study.addItem(300, 50, 0, "k"); + // study.addItem(300, 50, 1, "k"); + study.addUnit(225, 70, 0, "c"); study.addUnit(370, 30, 0, "c"); study.addUnit(220, 80, 1, "c"); diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAgreementTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAgreementTest.java index d05c31e..2f0d54e 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAgreementTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAgreementTest.java @@ -17,7 +17,11 @@ */ package org.dkpro.statistics.agreement.unitizing; -import junit.framework.TestCase; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; +import static org.dkpro.statistics.agreement.unitizing.KrippendorffAlphaUnitizingAgreement.measureDistance; + +import org.junit.jupiter.api.Test; /** * Tests for measuring {@link KrippendorffAlphaUnitizingAgreement}.
@@ -27,59 +31,51 @@ * @author Ivan Habernal */ public class UnitizingAgreementTest - extends TestCase { - + @Test public void testAgreement() { IUnitizingAnnotationStudy study = createExample(); KrippendorffAlphaUnitizingAgreement alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.9100, alpha.calculateObservedCategoryDisagreement("A"), 0.0001); - assertEquals(0.5351, alpha.calculateExpectedCategoryDisagreement("A"), 0.0001); - assertEquals(-0.7003, alpha.calculateCategoryAgreement("A"), 0.0001); + assertThat(alpha.calculateObservedCategoryDisagreement("A")).isCloseTo(0.9100, + offset(0.0001)); + assertThat(alpha.calculateExpectedCategoryDisagreement("A")).isCloseTo(0.5351, + offset(0.0001)); + assertThat(alpha.calculateCategoryAgreement("A")).isCloseTo(-0.7003, offset(0.0001)); } - + @Test public void testSingleAnnotationUnit() { UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(3, 20); study.addUnit(0, 1, 0, "X"); KrippendorffAlphaUnitizingAgreement alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertEquals(0.0, alpha.calculateAgreement()); + assertThat(alpha.calculateAgreement()).isEqualTo(0.0); } - + @Test public void testEmptyAnnotationSet() { UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(3, 20); KrippendorffAlphaUnitizingAgreement alpha = new KrippendorffAlphaUnitizingAgreement(study); - assertTrue(Double.isNaN(alpha.calculateAgreement())); + assertThat(alpha.calculateAgreement()).isNaN(); } - + @Test public void testDistanceMetric() { - assertEquals(0.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(0, 1, null, 0, 2, null)); - assertEquals(0.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 0, 2, null)); - assertEquals(37.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 2, 1, "A")); - assertEquals(0.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 3, 1, null)); - assertEquals(25.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 4, 1, "A")); - assertEquals(0.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 5, 1, null)); - assertEquals(29.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 6, 1, "A")); - assertEquals(0.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(1, 8, "A", 7, 4, null)); - assertEquals(0.0, - KrippendorffAlphaUnitizingAgreement.measureDistance(9, 2, null, 7, 4, null)); + assertThat(measureDistance(0, 1, null, 0, 2, null)).isEqualTo(0.0); + assertThat(measureDistance(1, 8, "A", 0, 2, null)).isEqualTo(0.0); + assertThat(measureDistance(1, 8, "A", 2, 1, "A")).isEqualTo(37.0); + assertThat(measureDistance(1, 8, "A", 3, 1, null)).isEqualTo(0.0); + assertThat(measureDistance(1, 8, "A", 4, 1, "A")).isEqualTo(25.0); + assertThat(measureDistance(1, 8, "A", 5, 1, null)).isEqualTo(0.0); + assertThat(measureDistance(1, 8, "A", 6, 1, "A")).isEqualTo(29.0); + assertThat(measureDistance(1, 8, "A", 7, 4, null)).isEqualTo(0.0); + assertThat(measureDistance(9, 2, null, 7, 4, null)).isEqualTo(0.0); } /** Creates an example annotation study. */ diff --git a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudyTest.java b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudyTest.java index ab07045..6e3b7c0 100644 --- a/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudyTest.java +++ b/dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/unitizing/UnitizingAnnotationStudyTest.java @@ -17,9 +17,11 @@ */ package org.dkpro.statistics.agreement.unitizing; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Iterator; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Tests for {@link UnitizingAnnotationStudy}.
@@ -28,8 +30,8 @@ * @author Christian M. Meyer */ public class UnitizingAnnotationStudyTest - extends TestCase { + @Test public void testSortOrder() { UnitizingAnnotationStudy study = new UnitizingAnnotationStudy(3, 7); @@ -55,14 +57,14 @@ public void testSortOrder() assertAnnotationItem(2, 5, 1, iter.next()); assertAnnotationItem(3, 1, 1, iter.next()); assertAnnotationItem(3, 2, 1, iter.next()); - assertFalse(iter.hasNext()); + assertThat(iter.hasNext()).isFalse(); } protected static void assertAnnotationItem(int expectedOffset, int expectedLength, int expectedRaterIdx, final IUnitizingAnnotationUnit actual) { - assertEquals(actual.toString(), expectedOffset, actual.getOffset()); - assertEquals(actual.toString(), expectedLength, actual.getLength()); - assertEquals(actual.toString(), expectedRaterIdx, actual.getRaterIdx()); + assertThat( actual.getOffset()).as(actual.toString()).isEqualTo(expectedOffset); + assertThat( actual.getLength()).as(actual.toString()).isEqualTo(expectedLength); + assertThat( actual.getRaterIdx()).as(actual.toString()).isEqualTo(expectedRaterIdx); } } diff --git a/dkpro-statistics-correlation/pom.xml b/dkpro-statistics-correlation/pom.xml index d92b269..3e5e97a 100644 --- a/dkpro-statistics-correlation/pom.xml +++ b/dkpro-statistics-correlation/pom.xml @@ -16,7 +16,9 @@ See the License for the specific language governing permissions and limitations under the License. --> - + 4.0.0 dkpro-statistics-correlation @@ -38,12 +40,12 @@ - commons-logging - commons-logging-api + org.slf4j + slf4j-api org.apache.commons - commons-math + commons-math3 diff --git a/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/PearsonCorrelation.java b/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/PearsonCorrelation.java index dd71603..42381e6 100644 --- a/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/PearsonCorrelation.java +++ b/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/PearsonCorrelation.java @@ -17,21 +17,21 @@ */ package org.dkpro.statistics.correlation; +import java.lang.invoke.MethodHandles; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Computes the correlation of two datasets. * * @author zesch - * */ public class PearsonCorrelation { - private static Log log = LogFactory.getLog(PearsonCorrelation.class); + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); /** * Computes the correlation between two datasets. @@ -85,7 +85,7 @@ public static double computeCorrelation(final double[] list1, final double[] lis final long N = list1.length; // we assume that both list are of equal length if (list1.length != list2.length) { - log.fatal("Lists are not the same size (" + list1.length + " - " + list2.length + ")."); + LOG.error("Lists are not the same size ({} - {}).", list1.length, list2.length); System.exit(1); } diff --git a/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/SpearmansRankCorrelation.java b/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/SpearmansRankCorrelation.java index 84235e7..05dc4af 100644 --- a/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/SpearmansRankCorrelation.java +++ b/dkpro-statistics-correlation/src/main/java/org/dkpro/statistics/correlation/SpearmansRankCorrelation.java @@ -19,7 +19,7 @@ import java.util.List; -import org.apache.commons.math.stat.correlation.SpearmansCorrelation; +import org.apache.commons.math3.stat.correlation.SpearmansCorrelation; public class SpearmansRankCorrelation { diff --git a/dkpro-statistics-significance/pom.xml b/dkpro-statistics-significance/pom.xml index c6e3a65..9fea293 100644 --- a/dkpro-statistics-significance/pom.xml +++ b/dkpro-statistics-significance/pom.xml @@ -39,11 +39,16 @@ org.apache.commons - commons-math + commons-math3 - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.assertj + assertj-core test diff --git a/dkpro-statistics-significance/src/main/java/org/dkpro/statistics/significance/Significance.java b/dkpro-statistics-significance/src/main/java/org/dkpro/statistics/significance/Significance.java index 2700305..fcab3dc 100644 --- a/dkpro-statistics-significance/src/main/java/org/dkpro/statistics/significance/Significance.java +++ b/dkpro-statistics-significance/src/main/java/org/dkpro/statistics/significance/Significance.java @@ -19,9 +19,8 @@ import java.util.List; -import org.apache.commons.math.MathException; -import org.apache.commons.math.special.Erf; -import org.apache.commons.math.stat.inference.TestUtils; +import org.apache.commons.math3.special.Erf; +import org.apache.commons.math3.stat.inference.TestUtils; /** * Computes statistical significance. @@ -30,7 +29,6 @@ */ public class Significance { - /** * Tests two correlation values for equality. See page 745 Press, W. H. (2007). Numerical * Recipes 3rd Edition: The Art of Scientific Computing. Cambridge University Press. @@ -67,7 +65,6 @@ public class Significance */ public static boolean testCorrelations(double correlation1, double correlation2, int n1, int n2, double alpha) - throws MathException { double p = getSignificance(correlation1, correlation2, n1, n2); @@ -93,7 +90,7 @@ public static boolean testCorrelations(double correlation1, double correlation2, * @throws IllegalArgumentException */ public static double getSignificance(double[] sample1, double[] sample2) - throws IllegalArgumentException, MathException + throws IllegalArgumentException { double alpha = TestUtils.pairedTTest(sample1, sample2); boolean significance = TestUtils.pairedTTest(sample1, sample2, .30); @@ -102,7 +99,7 @@ public static double getSignificance(double[] sample1, double[] sample2) } public static double getSignificance(List list1, List list2) - throws IllegalArgumentException, MathException + throws IllegalArgumentException { double[] doubleArray1 = new double[list1.size()]; double[] doubleArray2 = new double[list2.size()]; @@ -126,7 +123,6 @@ public static double getSignificance(List list1, List list2) * Computes the significance of the difference between two correlations. */ public static double getSignificance(double correlation1, double correlation2, int n1, int n2) - throws MathException { // transform to Fisher Z-values diff --git a/dkpro-statistics-significance/src/test/java/org/dkpro/statistics/significance/SignificanceTest.java b/dkpro-statistics-significance/src/test/java/org/dkpro/statistics/significance/SignificanceTest.java index 4e6dc8c..79a2c49 100644 --- a/dkpro-statistics-significance/src/test/java/org/dkpro/statistics/significance/SignificanceTest.java +++ b/dkpro-statistics-significance/src/test/java/org/dkpro/statistics/significance/SignificanceTest.java @@ -17,27 +17,26 @@ */ package org.dkpro.statistics.significance; +import static org.assertj.core.api.Assertions.assertThat; import static org.dkpro.statistics.significance.Significance.testCorrelations; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import org.apache.commons.math.MathException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SignificanceTest { @Test - public void testTestCorrelations() throws MathException + public void testTestCorrelations() { - assertTrue(testCorrelations(0.5, 0.74, 68, 68, 0.2)); - assertTrue(testCorrelations(0.5, 0.74, 68, 68, 0.1)); - assertTrue(testCorrelations(0.5, 0.74, 68, 68, 0.05)); - assertFalse(testCorrelations(0.5, 0.74, 68, 68, 0.01)); + assertThat(testCorrelations(0.5, 0.74, 68, 68, 0.2)).isTrue(); + + assertThat(testCorrelations(0.5, 0.74, 68, 68, 0.1)).isTrue(); + assertThat(testCorrelations(0.5, 0.74, 68, 68, 0.05)).isTrue(); + assertThat(testCorrelations(0.5, 0.74, 68, 68, 0.01)).isFalse(); - assertTrue(testCorrelations(0.5, 0.7, 100, 100, 0.1)); - assertTrue(testCorrelations(0.5, 0.7, 100, 100, 0.05)); - assertFalse(testCorrelations(0.5, 0.7, 100, 100, 0.01)); + assertThat(testCorrelations(0.5, 0.7, 100, 100, 0.1)).isTrue(); + assertThat(testCorrelations(0.5, 0.7, 100, 100, 0.05)).isTrue(); + assertThat(testCorrelations(0.5, 0.7, 100, 100, 0.01)).isFalse(); - assertFalse(testCorrelations(0.5, 0.5, 100, 100, 0.99)); + assertThat(testCorrelations(0.5, 0.5, 100, 100, 0.99)).isFalse(); } } diff --git a/pom.xml b/pom.xml index 5d2b9b7..eec3d55 100644 --- a/pom.xml +++ b/pom.xml @@ -16,13 +16,15 @@ See the License for the specific language governing permissions and limitations under the License. --> - + 4.0.0 org.dkpro dkpro-parent-pom - 24 + 32 org.dkpro.statistics @@ -32,13 +34,15 @@ DKPro Statistics https://dkpro.github.io/dkpro-statistics/ - DKPro Statistics is a collection of open-licensed statistical tools, currently including inter-rater agreement, correlation, and significance measures. + DKPro Statistics is a collection of open-licensed statistical + tools, currently including inter-rater agreement, correlation, and + significance measures. Ubiquitous Knowledge Processing (UKP) Lab https://www.ukp.tu-darmstadt.de/ - + chmeyer.de @@ -78,34 +82,37 @@ https://github.com/dkpro/dkpro-statistics head - + - commons-logging - commons-logging-api - 1.1 + org.apache.commons + commons-math3 + 3.2 org.apache.commons - commons-math - 2.2 + commons-lang3 + 3.14.0 - commons-lang - commons-lang - 2.6 + org.assertj + assertj-core + 3.5.2 - - junit - junit - 4.13.1 + org.junit + junit-bom + 5.10.2 + pom + import - org.assertj - assertj-core - 3.5.2 + org.slf4j + slf4j-bom + 2.0.13 + pom + import @@ -185,7 +192,8 @@ dkpro-statistics/checkstyle.xml - + ${project.compileSourceRoots} ${project.testCompileSourceRoots} basedir=${project.basedir}