Search in sources :

Example 1 with MergeConflictException

use of de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.MergeConflictException in project webanno by webanno.

the class SuggestionViewPanel method actionAcceptAll.

private void actionAcceptAll(AjaxRequestTarget aTarget, UserAnnotationSegment aSegment, AnnotationLayer aLayer) throws IOException {
    CAS targetCas = readEditorCas(aSegment.getAnnotatorState());
    CAS sourceCas = readAnnotatorCas(aSegment);
    AnnotatorState sourceState = aSegment.getAnnotatorState();
    TypeAdapter adapter = schemaService.getAdapter(aLayer);
    int mergeConflict = 0;
    int alreadyMerged = 0;
    int updated = 0;
    int created = 0;
    Set<String> otherErrors = new LinkedHashSet<>();
    CasMerge casMerge = new CasMerge(schemaService);
    casMerge.setSilenceEvents(true);
    nextAnnotation: for (AnnotationFS ann : select(sourceCas, adapter.getAnnotationType(sourceCas))) {
        try {
            CasMergeOperationResult result;
            switch(aLayer.getType()) {
                case SPAN_TYPE:
                    result = mergeSpan(casMerge, targetCas, sourceCas, new VID(ann), sourceState.getDocument(), sourceState.getUser().getUsername(), aLayer);
                    break;
                case RELATION_TYPE:
                    result = mergeRelation(casMerge, targetCas, sourceCas, new VID(ann), sourceState.getDocument(), sourceState.getUser().getUsername(), aLayer);
                    break;
                default:
                    continue nextAnnotation;
            }
            switch(result.getState()) {
                case CREATED:
                    created++;
                    break;
                case UPDATED:
                    updated++;
                    break;
            }
        } catch (AlreadyMergedException e) {
            alreadyMerged++;
        } catch (MergeConflictException e) {
            mergeConflict++;
        } catch (Exception e) {
            otherErrors.add(e.getMessage());
        }
    }
    writeEditorCas(sourceState, targetCas);
    int success = created + updated;
    if (success > 0) {
        success(String.format("Annotations were changed: %d (%d created, %d updated)", success, created, updated));
    } else {
        info("No annotations were changed");
    }
    if (alreadyMerged > 0) {
        info("Annotations had already been merged: " + alreadyMerged);
    }
    if (mergeConflict > 0) {
        info("Annotations skipped due to conflicts: " + mergeConflict);
    }
    if (!otherErrors.isEmpty()) {
        otherErrors.forEach(this::error);
    }
    applicationEventPublisher.get().publishEvent(new BulkAnnotationEvent(this, sourceState.getDocument(), sourceState.getUser().getUsername(), adapter.getLayer()));
    aTarget.addChildren(getPage(), IFeedback.class);
    onChange(aTarget);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) CasMergeOperationResult(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMergeOperationResult) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) AlreadyMergedException(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.AlreadyMergedException) UIMAException(org.apache.uima.UIMAException) MergeConflictException(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.MergeConflictException) IOException(java.io.IOException) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) MergeConflictException(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.MergeConflictException) CAS(org.apache.uima.cas.CAS) CasMerge(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMerge) BulkAnnotationEvent(de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.BulkAnnotationEvent) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AlreadyMergedException(de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.AlreadyMergedException)

Aggregations

TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 BulkAnnotationEvent (de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.BulkAnnotationEvent)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 AlreadyMergedException (de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.AlreadyMergedException)1 CasMerge (de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMerge)1 CasMergeOperationResult (de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMergeOperationResult)1 MergeConflictException (de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.MergeConflictException)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 UIMAException (org.apache.uima.UIMAException)1 CAS (org.apache.uima.cas.CAS)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1