Search in sources :

Example 11 with SpanDiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.

the class CasDiffTest method singleEmptyCasTest.

@Test
public void singleEmptyCasTest() throws Exception {
    String text = "";
    CAS user1Cas = JCasFactory.createJCas().getCas();
    user1Cas.setDocumentText(text);
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1Cas));
    List<SpanDiffAdapter> diffAdapters = asList(new SpanDiffAdapter(Token.class.getName()));
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // result.print(System.out);
    assertEquals(0, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
}
Also used : CAS(org.apache.uima.cas.CAS) SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 12 with SpanDiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.

the class CasDiffTest method noDifferencesPosTest.

@Test
public void noDifferencesPosTest() throws Exception {
    Map<String, List<CAS>> casByUser = load("casdiff/noDifferences/data.conll", "casdiff/noDifferences/data.conll");
    List<SpanDiffAdapter> diffAdapters = asList(POS_DIFF_ADAPTER);
    CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
    DiffResult result = diff.toResult();
    // result.print(System.out);
    assertEquals(26, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
// Todo: Agreement has moved to separate project - should create agreement test there
// CodingAgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff,
// entryTypes.get(0), "PosValue", casByUser);
// assertEquals(1.0d, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Test(org.junit.Test)

Example 13 with SpanDiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.

the class CasDiffTest method multiLinkWithRoleMultiTargetDifferenceTest.

@Test
public void multiLinkWithRoleMultiTargetDifferenceTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(createMultiLinkWithRoleTestTypeSystem());
    makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0), makeLinkFS(jcasA, "slot1", 10, 10));
    JCas jcasB = JCasFactory.createJCas(createMultiLinkWithRoleTestTypeSystem());
    makeLinkHostFS(jcasB, 0, 0, makeLinkFS(jcasB, "slot1", 10, 10));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA.getCas()));
    casByUser.put("user2", asList(jcasB.getCas()));
    SpanDiffAdapter adapter = new SpanDiffAdapter(HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // diff.print(System.out);
    assertEquals(2, diff.size());
    assertEquals(1, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
// // Check against new impl
// AgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff, HOST_TYPE,
// "links",
// casByUser);
// 
// // Asserts
// System.out.printf("Agreement: %s%n", agreement.toString());
// AgreementUtils.dumpAgreementStudy(System.out, agreement);
// 
// assertEquals(0.0, agreement.getAgreement(), 0.00001d);
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 14 with SpanDiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.

the class CasDiffTest method singleNoDifferencesTest.

@Test
public void singleNoDifferencesTest() throws Exception {
    Map<String, List<CAS>> casByUser = load("casdiff/singleSpanNoDifference/data.conll", "casdiff/singleSpanNoDifference/data.conll");
    List<? extends DiffAdapter> diffAdapters = asList(new SpanDiffAdapter(POS.class.getName(), "PosValue"));
    CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
    DiffResult result = diff.toResult();
    // result.print(System.out);
    assertEquals(1, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
// Todo: Agreement has moved to separate project - should create agreement test there
// CodingAgreementResult agreement = getCohenKappaAgreement(diff, entryTypes.get(0),
// "PosValue", casByUser);
// assertEquals(NaN, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Test(org.junit.Test)

Example 15 with SpanDiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.

the class CasDiff method getDiffAdapters.

public static List<DiffAdapter> getDiffAdapters(AnnotationSchemaService schemaService, Iterable<AnnotationLayer> aLayers) {
    List<DiffAdapter> adapters = new ArrayList<>();
    nextLayer: for (AnnotationLayer layer : aLayers) {
        if (!layer.isEnabled()) {
            continue nextLayer;
        }
        Set<String> labelFeatures = new LinkedHashSet<>();
        nextFeature: for (AnnotationFeature f : schemaService.listSupportedFeatures(layer)) {
            if (!f.isEnabled()) {
                continue nextFeature;
            }
            // Link features are treated separately from primitive label features
            if (!NONE.equals(f.getLinkMode())) {
                continue nextFeature;
            }
            labelFeatures.add(f.getName());
        }
        DiffAdapter_ImplBase adapter;
        switch(layer.getType()) {
            case SPAN_TYPE:
                {
                    adapter = new SpanDiffAdapter(layer.getName(), labelFeatures);
                    break;
                }
            case RELATION_TYPE:
                {
                    RelationAdapter typeAdpt = (RelationAdapter) schemaService.getAdapter(layer);
                    adapter = new RelationDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
                    break;
                }
            default:
                LOG.debug("Curation for layer type [{}] not supported - ignoring", layer.getType());
                continue nextLayer;
        }
        adapters.add(adapter);
        nextFeature: for (AnnotationFeature f : schemaService.listSupportedFeatures(layer)) {
            if (!f.isEnabled()) {
                continue nextFeature;
            }
            switch(f.getLinkMode()) {
                case NONE:
                    // Nothing to do here
                    break;
                case SIMPLE:
                    adapter.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
                    break;
                case WITH_ROLE:
                    adapter.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
                    break;
                default:
                    throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
            }
            labelFeatures.add(f.getName());
        }
    }
    return adapters;
}
Also used : RelationAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) RelationDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.relation.RelationDiffAdapter) ArrayList(java.util.ArrayList) SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) RelationDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.relation.RelationDiffAdapter) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) DiffAdapter_ImplBase(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter_ImplBase) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter)16 ArrayList (java.util.ArrayList)14 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult)13 Arrays.asList (java.util.Arrays.asList)13 List (java.util.List)13 Test (org.junit.Test)13 LinkedHashMap (java.util.LinkedHashMap)8 JCasFactory.createJCas (org.apache.uima.fit.factory.JCasFactory.createJCas)6 JCas (org.apache.uima.jcas.JCas)6 CAS (org.apache.uima.cas.CAS)3 DiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter)2 RelationDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.relation.RelationDiffAdapter)2 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 RelationAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter)1 BooleanFeatureSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.BooleanFeatureSupport)1 FeatureSupportRegistryImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl)1 NumberFeatureSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.NumberFeatureSupport)1 SlotFeatureSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.SlotFeatureSupport)1 StringFeatureSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.StringFeatureSupport)1