Search in sources :

Example 11 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.

the class KrippendorffAlphaAgreementMeasure method calculatePairAgreement.

@Override
public CodingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
    AnnotationFeature feature = getFeature();
    KrippendorffAlphaAgreementTraits traits = getTraits();
    List<DiffAdapter> adapters = getDiffAdapters(annotationService, asList(feature.getLayer()));
    CasDiff diff = doDiff(adapters, traits.getLinkCompareBehavior(), aCasMap);
    CodingAgreementResult agreementResult = makeCodingStudy(diff, feature.getLayer().getName(), feature.getName(), traits.isExcludeIncomplete(), aCasMap);
    IAgreementMeasure agreement = new KrippendorffAlphaAgreement(agreementResult.getStudy(), new NominalDistanceFunction());
    if (agreementResult.getStudy().getItemCount() > 0) {
        try {
            agreementResult.setAgreement(agreement.calculateAgreement());
        } catch (InsufficientDataException e) {
            agreementResult.setAgreement(NaN);
        }
    } else {
        agreementResult.setAgreement(NaN);
    }
    return agreementResult;
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) IAgreementMeasure(org.dkpro.statistics.agreement.IAgreementMeasure) CasDiff(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff) KrippendorffAlphaAgreement(org.dkpro.statistics.agreement.coding.KrippendorffAlphaAgreement) InsufficientDataException(org.dkpro.statistics.agreement.InsufficientDataException) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) NominalDistanceFunction(org.dkpro.statistics.agreement.distance.NominalDistanceFunction) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 12 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.

the class CasDiffTest method noDataTest.

@Test
public void noDataTest() throws Exception {
    List<DiffAdapter> diffAdapters = new ArrayList<>();
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // result.print(System.out);
    assertEquals(0, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
}
Also used : 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) 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 13 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter 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)

Example 14 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.

the class CasDiff method getAdapter.

private DiffAdapter getAdapter(String aType) {
    DiffAdapter adapter = typeAdapters.get(aType);
    if (adapter == null) {
        LOG.warn("No diff adapter for type [" + aType + "] -- treating as without features");
        adapter = new SpanDiffAdapter(aType, emptySet());
        typeAdapters.put(aType, adapter);
    }
    return adapter;
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) 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)

Example 15 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter in project webanno by webanno.

the class SuggestionBuilder method buildCurationContainer.

public CurationContainer buildCurationContainer(AnnotatorState aState) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    CurationContainer curationContainer = new CurationContainer();
    // initialize Variables
    SourceDocument sourceDocument = aState.getDocument();
    Map<Integer, Integer> segmentBeginEnd = new HashMap<>();
    Map<Integer, Integer> segmentNumber = new HashMap<>();
    Map<String, Map<Integer, Integer>> segmentAdress = new HashMap<>();
    // get annotation documents
    List<AnnotationDocument> finishedAnnotationDocuments = new ArrayList<>();
    for (AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(aState.getDocument())) {
        if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
            finishedAnnotationDocuments.add(annotationDocument);
        }
    }
    Map<String, CAS> casses = new HashMap<>();
    AnnotationDocument randomAnnotationDocument = null;
    CAS mergeCas;
    // get the correction/automation CAS for the logged in user
    if (aState.getMode().equals(AUTOMATION) || aState.getMode().equals(CORRECTION)) {
        casses = listCasesforCorrection(randomAnnotationDocument, sourceDocument, aState.getMode());
        mergeCas = getMergeCas(aState, sourceDocument, casses, randomAnnotationDocument, false, false, false);
        String username = casses.keySet().iterator().next();
        updateSegment(aState, segmentBeginEnd, segmentNumber, segmentAdress, casses.get(username), username, aState.getWindowBeginOffset(), aState.getWindowEndOffset());
    } else {
        casses = listCassesforCuration(finishedAnnotationDocuments, aState.getMode());
        mergeCas = getMergeCas(aState, sourceDocument, casses, randomAnnotationDocument, false, false, false);
        updateSegment(aState, segmentBeginEnd, segmentNumber, segmentAdress, mergeCas, CURATION_USER, getFirstSentence(mergeCas).getBegin(), mergeCas.getDocumentText().length());
    }
    segmentAdress.put(CURATION_USER, new HashMap<>());
    Type sentenceType = getType(mergeCas, Sentence.class);
    for (AnnotationFS s : selectCovered(mergeCas, sentenceType, diffRangeBegin, diffRangeEnd)) {
        segmentAdress.get(CURATION_USER).put(s.getBegin(), getAddr(s));
    }
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, aState.getAnnotationLayers());
    long diffStart = System.currentTimeMillis();
    log.debug("Calculating differences...");
    int count = 0;
    for (Integer begin : segmentBeginEnd.keySet()) {
        Integer end = segmentBeginEnd.get(begin);
        count++;
        if (count % 100 == 0) {
            log.debug("Processing differences: {} of {} sentences...", count, segmentBeginEnd.size());
        }
        DiffResult diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, begin, end).toResult();
        SourceListView curationSegment = new SourceListView();
        curationSegment.setBegin(begin);
        curationSegment.setEnd(end);
        curationSegment.setSentenceNumber(segmentNumber.get(begin));
        if (diff.hasDifferences() || !diff.getIncompleteConfigurationSets().isEmpty()) {
            // Is this confSet a diff due to stacked annotations (with same configuration)?
            boolean stackedDiff = false;
            stackedDiffSet: for (ConfigurationSet d : diff.getDifferingConfigurationSets().values()) {
                for (Configuration c : d.getConfigurations()) {
                    if (c.getCasGroupIds().size() != d.getCasGroupIds().size()) {
                        stackedDiff = true;
                        break stackedDiffSet;
                    }
                }
            }
            if (stackedDiff) {
                curationSegment.setSentenceState(DISAGREE);
            } else if (!diff.getIncompleteConfigurationSets().isEmpty()) {
                curationSegment.setSentenceState(DISAGREE);
            } else {
                curationSegment.setSentenceState(AGREE);
            }
        } else {
            curationSegment.setSentenceState(AGREE);
        }
        for (String username : segmentAdress.keySet()) {
            curationSegment.getSentenceAddress().put(username, segmentAdress.get(username).get(begin));
        }
        curationContainer.getCurationViewByBegin().put(begin, curationSegment);
    }
    log.debug("Difference calculation completed in {}ms", (System.currentTimeMillis() - diffStart));
    return curationContainer;
}
Also used : Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) CAS(org.apache.uima.cas.CAS) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter)15 ArrayList (java.util.ArrayList)8 RelationDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.relation.RelationDiffAdapter)7 SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)7 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult)5 CAS (org.apache.uima.cas.CAS)5 CasDiff (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff)4 DefaultAgreementTraits (de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits)3 CodingAgreementResult (de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult)3 ConfigurationSet (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet)3 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)3 Arrays.asList (java.util.Arrays.asList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)3 IAgreementMeasure (org.dkpro.statistics.agreement.IAgreementMeasure)3 ColoringStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy)2 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)2