Search in sources :

Example 6 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class KrippendorffAlphaNominalAgreementMeasureTest method multiLinkWithRoleLabelDifference.

@Test
public void multiLinkWithRoleLabelDifference() throws Exception {
    PairwiseAnnotationResult<CodingAgreementResult> agreement = multiLinkWithRoleLabelDifferenceTest(sut);
    CodingAgreementResult result = agreement.getStudy("user1", "user2");
    DiffResult diff = result.getDiff();
    diff.print(System.out);
    assertEquals(3, diff.size());
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(2, diff.getIncompleteConfigurationSets().size());
    assertEquals(NaN, result.getAgreement(), 0.00001d);
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Test(org.junit.Test)

Example 7 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class SuggestionBuilder method createCurationCas.

/**
 * For the first time a curation page is opened, create a MergeCas that contains only agreeing
 * annotations Using the CAS of the curator user.
 *
 * @param aState
 *            the annotator state
 * @param aRandomAnnotationDocument
 *            an annotation document.
 * @param aCasses
 *            the CASes
 * @param aAnnotationLayers
 *            the layers.
 * @return the CAS.
 * @throws IOException
 *             if an I/O error occurs.
 */
private CAS createCurationCas(AnnotatorState aState, AnnotationDocument aRandomAnnotationDocument, Map<String, CAS> aCasses, List<AnnotationLayer> aAnnotationLayers, boolean aMergeIncompleteAnnotations) throws IOException, UIMAException, AnnotationException {
    Validate.notNull(aState, "State must be specified");
    Validate.notNull(aRandomAnnotationDocument, "Annotation document must be specified");
    // We need a modifiable copy of some annotation document which we can use to initialize
    // the curation CAS. This is an exceptional case where BYPASS is the correct choice
    CAS mergeCas = documentService.readAnnotationCas(aRandomAnnotationDocument, UNMANAGED_ACCESS);
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, aState.getAnnotationLayers());
    DiffResult diff;
    try (StopWatch watch = new StopWatch(log, "CasDiff")) {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, aCasses, 0, mergeCas.getDocumentText().length()).toResult();
    }
    try (StopWatch watch = new StopWatch(log, "CasMerge")) {
        CasMerge casMerge = new CasMerge(schemaService);
        casMerge.setMergeIncompleteAnnotations(aMergeIncompleteAnnotations);
        casMerge.reMergeCas(diff, aState.getDocument(), aState.getUser().getUsername(), mergeCas, aCasses);
    }
    curationDocumentService.writeCurationCas(mergeCas, aRandomAnnotationDocument.getDocument(), false);
    return mergeCas;
}
Also used : CAS(org.apache.uima.cas.CAS) CasMerge(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMerge) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) StopWatch(de.tudarmstadt.ukp.clarin.webanno.support.StopWatch)

Example 8 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class CasMergeTest method copyLinkToEmptyTest.

@Test
public void copyLinkToEmptyTest() throws Exception {
    JCas mergeCas = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    Type type = mergeCas.getTypeSystem().getType(CurationTestUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    AnnotationFS mergeFs = makeLinkHostMultiSPanFeatureFS(mergeCas, 0, 0, feature, "A");
    FeatureStructure copyFS = CurationTestUtils.makeLinkFS(mergeCas, "slot1", 0, 0);
    List<FeatureStructure> linkFs = new ArrayList<>();
    linkFs.add(copyFS);
    WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);
    JCas jcasA = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", makeLinkFS(jcasA, "slot1", 0, 0));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(mergeCas.getCas()));
    casByUser.put("user2", asList(jcasA.getCas()));
    DiffResult diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) FSUtil.getFeature(org.apache.uima.fit.util.FSUtil.getFeature) Feature(org.apache.uima.cas.Feature) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 9 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class CasMergeTest method multiLinkWithRoleNoDifferenceTest.

@Test
public void multiLinkWithRoleNoDifferenceTest() throws Exception {
    JCas jcasA = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0));
    makeLinkHostFS(jcasA, 10, 10, makeLinkFS(jcasA, "slot1", 10, 10));
    JCas jcasB = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostFS(jcasB, 0, 0, makeLinkFS(jcasB, "slot1", 0, 0));
    makeLinkHostFS(jcasB, 10, 10, makeLinkFS(jcasB, "slot1", 10, 10));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA.getCas()));
    casByUser.put("user2", asList(jcasB.getCas()));
    JCas curatorCas = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    curatorCas.setDocumentText(casByUser.values().stream().flatMap(Collection::stream).findFirst().get().getDocumentText());
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // result.print(System.out);
    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));
    casByUser = new HashMap<>();
    casByUser.put("actual", asList(jcasA.getCas()));
    casByUser.put("merge", asList(curatorCas.getCas()));
    result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
}
Also used : JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) Collection(java.util.Collection) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 10 with DiffResult

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.

the class CasMergeTest method multiLinkWithRoleLabelDifferenceTest.

@Test
public void multiLinkWithRoleLabelDifferenceTest() throws Exception {
    JCas jcasA = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostFS(jcasB, 0, 0, makeLinkFS(jcasB, "slot2", 0, 0));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA.getCas()));
    casByUser.put("user2", asList(jcasB.getCas()));
    JCas curatorCas = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    curatorCas.setDocumentText(casByUser.values().stream().flatMap(Collection::stream).findFirst().get().getDocumentText());
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // result.print(System.out);
    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));
    Type hostType = curatorCas.getCas().getTypeSystem().getType(HOST_TYPE);
    FeatureSupport slotSupport = featureSupportRegistry.getFeatureSupport(slotFeature);
    assertThat(select(curatorCas.getCas(), hostType)).hasSize(1);
    assertThat(select(curatorCas.getCas(), hostType).stream().map(host -> (List) slotSupport.getFeatureValue(slotFeature, host))).allMatch(Collection::isEmpty);
}
Also used : Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) Collection(java.util.Collection) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) FeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupport) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult)44 Test (org.junit.Test)39 Arrays.asList (java.util.Arrays.asList)34 List (java.util.List)34 ArrayList (java.util.ArrayList)31 LinkedHashMap (java.util.LinkedHashMap)25 CAS (org.apache.uima.cas.CAS)16 JCas (org.apache.uima.jcas.JCas)16 JCasFactory.createJCas (org.apache.uima.fit.factory.JCasFactory.createJCas)15 SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter)14 CodingAgreementResult (de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult)11 HashMap (java.util.HashMap)11 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 Map (java.util.Map)9 Collection (java.util.Collection)8 Type (org.apache.uima.cas.Type)8 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)7 CasDiff (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff)5 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)5 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)5