Search in sources :

Example 6 with DiffAdapter

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

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

the class SuggestionViewPanel method init.

/**
 * Initializes the user annotation segments later to be filled with content.
 */
public void init(AjaxRequestTarget aTarget, CurationContainer aCurationContainer, Map<String, Map<Integer, AnnotationSelection>> aAnnotationSelectionByUsernameAndAddress, SourceListView aCurationSegment) throws UIMAException, ClassNotFoundException, IOException {
    AnnotatorState state = aCurationContainer.getState();
    SourceDocument sourceDocument = state.getDocument();
    Map<String, CAS> casses = new HashMap<>();
    // This is the CAS that the user can actively edit
    CAS annotatorCas = getAnnotatorCas(state, aAnnotationSelectionByUsernameAndAddress, sourceDocument, casses);
    // We store the CAS that the user will edit as the "CURATION USER"
    casses.put(CURATION_USER, annotatorCas);
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, state.getAnnotationLayers());
    Map<String, Map<VID, AnnotationState>> annoStates1 = new HashMap<>();
    Project project = state.getProject();
    Mode mode1 = state.getMode();
    DiffResult diff;
    if (mode1.equals(CURATION)) {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd()).toResult();
    } else {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getBegin(), aCurationSegment.getEnd()).toResult();
    }
    Collection<ConfigurationSet> d = diff.getDifferingConfigurationSets().values();
    Collection<ConfigurationSet> i = diff.getIncompleteConfigurationSets().values();
    for (ConfigurationSet cfgSet : d) {
        if (i.contains(cfgSet)) {
            i.remove(cfgSet);
        }
    }
    addSuggestionColor(project, mode1, casses, annoStates1, d, false, false);
    addSuggestionColor(project, mode1, casses, annoStates1, i, true, false);
    List<ConfigurationSet> all = new ArrayList<>();
    all.addAll(diff.getConfigurationSets());
    all.removeAll(d);
    all.removeAll(i);
    addSuggestionColor(project, mode1, casses, annoStates1, all, false, true);
    // get differing feature structures
    Map<String, Map<VID, AnnotationState>> annoStates = annoStates1;
    List<String> usernamesSorted = new ArrayList<>(casses.keySet());
    Collections.sort(usernamesSorted);
    final Mode mode = state.getMode();
    boolean isAutomationMode = mode.equals(Mode.AUTOMATION);
    boolean isCorrectionMode = mode.equals(Mode.CORRECTION);
    boolean isCurationMode = mode.equals(Mode.CURATION);
    List<UserAnnotationSegment> segments = new ArrayList<>();
    for (String username : usernamesSorted) {
        if ((!username.equals(CURATION_USER) && isCurationMode) || (username.equals(CURATION_USER) && (isAutomationMode || isCorrectionMode))) {
            CAS cas = casses.get(username);
            // Set up coloring strategy
            ColoringStrategy curationColoringStrategy = makeColoringStrategy(annoStates.get(username));
            // Create curation view for the current user
            UserAnnotationSegment seg = new UserAnnotationSegment();
            seg.setUsername(username);
            seg.setAnnotatorState(state);
            seg.setCollectionData(getCollectionInformation(schemaService, aCurationContainer));
            seg.setDocumentResponse(render(cas, state, curationColoringStrategy));
            seg.setSelectionByUsernameAndAddress(aAnnotationSelectionByUsernameAndAddress);
            segments.add(seg);
        }
    }
    sentenceListView.setModelObject(segments);
    if (aTarget != null) {
        aTarget.add(this);
    }
}
Also used : HashMap(java.util.HashMap) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet) CAS(org.apache.uima.cas.CAS) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Map(java.util.Map) HashMap(java.util.HashMap) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 8 with DiffAdapter

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

the class SuggestionViewPanel method updatePanel.

/**
 * @param aTarget
 *            the AJAX target.
 * @param aCurationContainer
 *            the container.
 * @param aAnnotationSelectionByUsernameAndAddress
 *            selections by user.
 * @param aCurationSegment
 *            the segment.
 * @throws UIMAException
 *             hum?
 * @throws ClassNotFoundException
 *             hum?
 * @throws IOException
 *             hum?
 * @throws AnnotationException
 *             hum?
 */
private void updatePanel(AjaxRequestTarget aTarget, CurationContainer aCurationContainer, Map<String, Map<Integer, AnnotationSelection>> aAnnotationSelectionByUsernameAndAddress, SourceListView aCurationSegment) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    LOG.trace("call update");
    AnnotatorState state = aCurationContainer.getState();
    if (state.getDocument() == null) {
        return;
    }
    SourceDocument sourceDocument = state.getDocument();
    Map<String, CAS> casses = new HashMap<>();
    // This is the CAS that the user can actively edit
    CAS annotatorCas = getAnnotatorCas(state, aAnnotationSelectionByUsernameAndAddress, sourceDocument, casses);
    // We store the CAS that the user will edit as the "CURATION USER"
    casses.put(CURATION_USER, annotatorCas);
    List<DiffAdapter> adapters = getDiffAdapters(schemaService, state.getAnnotationLayers());
    Map<String, Map<VID, AnnotationState>> annoStates = new HashMap<>();
    Project project = state.getProject();
    Mode mode = state.getMode();
    DiffResult diff;
    if (mode.equals(CURATION)) {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd()).toResult();
    } else {
        diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, aCurationSegment.getBegin(), aCurationSegment.getEnd()).toResult();
    }
    Collection<ConfigurationSet> d = diff.getDifferingConfigurationSets().values();
    Collection<ConfigurationSet> i = diff.getIncompleteConfigurationSets().values();
    for (ConfigurationSet cfgSet : d) {
        if (i.contains(cfgSet)) {
            i.remove(cfgSet);
        }
    }
    addSuggestionColor(project, mode, casses, annoStates, d, false, false);
    addSuggestionColor(project, mode, casses, annoStates, i, true, false);
    List<ConfigurationSet> all = new ArrayList<>();
    all.addAll(diff.getConfigurationSets());
    all.removeAll(d);
    all.removeAll(i);
    addSuggestionColor(project, mode, casses, annoStates, all, false, true);
    // get differing feature structures
    sentenceListView.visitChildren(BratSuggestionVisualizer.class, (v, visit) -> {
        BratSuggestionVisualizer vis = (BratSuggestionVisualizer) v;
        UserAnnotationSegment seg = vis.getModelObject();
        CAS cas = casses.get(seg.getUsername());
        if (cas == null) {
            // This may happen if a user has not yet finished document
            return;
        }
        // Set up coloring strategy
        ColoringStrategy curationColoringStrategy = makeColoringStrategy(annoStates.get(seg.getUsername()));
        // Create curation view for the current user
        try {
            seg.setCollectionData(getCollectionInformation(schemaService, aCurationContainer));
            seg.setDocumentResponse(render(cas, state, curationColoringStrategy));
            seg.setAnnotatorState(state);
            seg.setSelectionByUsernameAndAddress(aAnnotationSelectionByUsernameAndAddress);
        } catch (IOException e) {
            error("Unable to render: " + e.getMessage());
            LOG.error("Unable to render", e);
        }
        if (isBlank(vis.getDocumentData())) {
            return;
        }
        vis.render(aTarget);
    });
}
Also used : BratSuggestionVisualizer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.BratSuggestionVisualizer) HashMap(java.util.HashMap) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) IOException(java.io.IOException) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.ConfigurationSet) CAS(org.apache.uima.cas.CAS) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Map(java.util.Map) HashMap(java.util.HashMap) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 9 with DiffAdapter

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

the class CohenKappaAgreementMeasure method calculatePairAgreement.

@Override
public CodingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
    AnnotationFeature feature = getFeature();
    DefaultAgreementTraits 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(), true, aCasMap);
    IAgreementMeasure agreement = new CohenKappaAgreement(agreementResult.getStudy());
    if (agreementResult.getStudy().getItemCount() > 0) {
        agreementResult.setAgreement(agreement.calculateAgreement());
    } else {
        agreementResult.setAgreement(Double.NaN);
    }
    return agreementResult;
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) CohenKappaAgreement(org.dkpro.statistics.agreement.coding.CohenKappaAgreement) IAgreementMeasure(org.dkpro.statistics.agreement.IAgreementMeasure) CasDiff(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff) DefaultAgreementTraits(de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 10 with DiffAdapter

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

the class FleissKappaAgreementMeasure method calculatePairAgreement.

@Override
public CodingAgreementResult calculatePairAgreement(Map<String, List<CAS>> aCasMap) {
    AnnotationFeature feature = getFeature();
    DefaultAgreementTraits 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(), true, aCasMap);
    IAgreementMeasure agreement = new FleissKappaAgreement(agreementResult.getStudy());
    if (agreementResult.getStudy().getItemCount() > 0) {
        agreementResult.setAgreement(agreement.calculateAgreement());
    } else {
        agreementResult.setAgreement(Double.NaN);
    }
    return agreementResult;
}
Also used : CodingAgreementResult(de.tudarmstadt.ukp.clarin.webanno.agreement.results.coding.CodingAgreementResult) IAgreementMeasure(org.dkpro.statistics.agreement.IAgreementMeasure) FleissKappaAgreement(org.dkpro.statistics.agreement.coding.FleissKappaAgreement) CasDiff(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff) DefaultAgreementTraits(de.tudarmstadt.ukp.clarin.webanno.agreement.measures.DefaultAgreementTraits) DiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.api.DiffAdapter) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

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