use of de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMerge 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;
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMerge 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);
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.CasMerge in project webanno by webanno.
the class SuggestionViewPanel method onClientEvent.
/**
* Method is called, if user has clicked on a span or an arc in the sentence panel. The span or
* arc respectively is identified and copied to the merge CAS.
*/
protected void onClientEvent(AjaxRequestTarget aTarget, UserAnnotationSegment aSegment) throws UIMAException, IOException, AnnotationException {
if (isDocumentFinished(documentService, aSegment.getAnnotatorState())) {
error("This document is already closed. Please ask the project manager to re-open it.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
IRequestParameters request = getRequest().getPostParameters();
StringValue action = request.getParameterValue(PARAM_ACTION);
if (!action.isEmpty()) {
String type = removePrefix(request.getParameterValue(PARAM_TYPE).toString());
AnnotationLayer layer = schemaService.getLayer(TypeUtil.getLayerId(type));
VID sourceVid = VID.parse(request.getParameterValue(PARAM_ID).toString());
CAS targetCas = readEditorCas(aSegment.getAnnotatorState());
CAS sourceCas = readAnnotatorCas(aSegment);
AnnotatorState sourceState = aSegment.getAnnotatorState();
if (CHAIN_TYPE.equals(layer.getType())) {
error("Coreference annotations are not supported in curation");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
if (ACTION_CONTEXT_MENU.equals(action.toString())) {
// No bulk actions supports for slots at the moment.
if (sourceVid.isSlotSet()) {
return;
}
List<IMenuItem> items = contextMenu.getItemList();
items.clear();
items.add(new LambdaMenuItem(String.format("Merge all %s", layer.getUiName()), _target -> actionAcceptAll(_target, aSegment, layer)));
contextMenu.onOpen(aTarget);
return;
}
// check if clicked on a span
CasMerge casMerge = new CasMerge(schemaService);
if (ACTION_SELECT_SPAN_FOR_MERGE.equals(action.toString())) {
mergeSpan(casMerge, targetCas, sourceCas, sourceVid, sourceState.getDocument(), sourceState.getUser().getUsername(), layer);
} else // check if clicked on an arc (relation or slot)
if (ACTION_SELECT_ARC_FOR_MERGE.equals(action.toString())) {
// this is a slot arc
if (sourceVid.isSlotSet()) {
mergeSlot(casMerge, targetCas, sourceCas, sourceVid, sourceState.getDocument(), sourceState.getUser().getUsername(), layer);
} else // normal relation annotation arc is clicked
{
mergeRelation(casMerge, targetCas, sourceCas, sourceVid, sourceState.getDocument(), sourceState.getUser().getUsername(), layer);
}
}
writeEditorCas(sourceState, targetCas);
// Update timestamp
AnnotationFS sourceAnnotation = selectAnnotationByAddr(sourceCas, sourceVid.getId());
int sentenceNumber = getSentenceNumber(sourceAnnotation.getCAS(), sourceAnnotation.getBegin());
sourceState.getDocument().setSentenceAccessed(sentenceNumber);
if (sourceState.getPreferences().isScrollPage()) {
sourceState.getPagingStrategy().moveToOffset(sourceState, targetCas, sourceAnnotation.getBegin(), CENTERED);
}
onChange(aTarget);
}
}
Aggregations