Search in sources :

Example 46 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class AnnotationDetailEditorPanel method loadFeatureEditorModels.

public void loadFeatureEditorModels(JCas aJCas, AjaxRequestTarget aTarget) throws AnnotationException {
    LOG.trace("loadFeatureEditorModels()");
    AnnotatorState state = getModelObject();
    Selection selection = state.getSelection();
    List<FeatureState> featureStates = state.getFeatureStates();
    for (FeatureState featureState : featureStates) {
        if (StringUtils.isNotBlank(featureState.feature.getLinkTypeName())) {
            featureState.value = new ArrayList<>();
        }
    }
    try {
        if (selection.isSpan()) {
            annotationFeatureForm.updateLayersDropdown();
        }
        if (selection.getAnnotation().isSet()) {
            // If an existing annotation was selected, take the feature editor model values from
            // there
            AnnotationFS annoFs = selectByAddr(aJCas, state.getSelection().getAnnotation().getId());
            // Try obtaining the layer from the feature structure
            AnnotationLayer layer;
            try {
                layer = annotationService.getLayer(state.getProject(), annoFs);
                state.setSelectedAnnotationLayer(layer);
                LOG.trace(String.format("loadFeatureEditorModels() selectedLayer set from selection: %s", state.getSelectedAnnotationLayer().getUiName()));
            } catch (NoResultException e) {
                clearFeatureEditorModels(aTarget);
                throw new IllegalStateException("Unknown layer [" + annoFs.getType().getName() + "]", e);
            }
            // selected span annotation
            if (!selection.isArc() && !state.getPreferences().isRememberLayer()) {
                state.setSelectedAnnotationLayer(layer);
            }
            loadFeatureEditorModelsCommon(aTarget, aJCas, layer, annoFs, null);
        } else {
            if (selection.isArc()) {
                // Avoid creation of arcs on locked layers
                if (state.getSelectedAnnotationLayer() != null && state.getSelectedAnnotationLayer().isReadonly()) {
                    state.setSelectedAnnotationLayer(new AnnotationLayer());
                } else {
                    loadFeatureEditorModelsCommon(aTarget, aJCas, state.getSelectedAnnotationLayer(), null, state.getRememberedArcFeatures());
                }
            } else {
                loadFeatureEditorModelsCommon(aTarget, aJCas, state.getSelectedAnnotationLayer(), null, state.getRememberedSpanFeatures());
            }
        }
        annotationFeatureForm.updateRememberLayer();
        if (aTarget != null) {
            aTarget.add(annotationFeatureForm);
        }
    } catch (Exception e) {
        throw new AnnotationException(e);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) NoResultException(javax.persistence.NoResultException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 47 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class AnnotationDetailEditorPanel method checkAttachStatus.

public AttachStatus checkAttachStatus(AjaxRequestTarget aTarget, Project aProject, AnnotationFS aFS) {
    AnnotationLayer layer = annotationService.getLayer(aProject, aFS);
    AttachStatus attachStatus = new AttachStatus();
    Set<AnnotationFS> attachedRels = getAttachedRels(aFS, layer);
    boolean attachedToReadOnlyRels = attachedRels.stream().anyMatch(relFS -> {
        AnnotationLayer relLayer = annotationService.getLayer(aProject, relFS);
        return relLayer.isReadonly();
    });
    if (attachedToReadOnlyRels) {
        attachStatus.readOnlyAttached |= true;
    }
    attachStatus.attachCount += attachedRels.size();
    // We do not count these atm since they only exist for built-in layers and are not
    // visible in the UI for the user.
    /*
        Set<AnnotationFS> attachedSpans = getAttachedSpans(aFS, layer);
        boolean attachedToReadOnlySpans = attachedSpans.stream().anyMatch(relFS -> {
            AnnotationLayer relLayer = annotationService.getLayer(aProject, relFS);
            return relLayer.isReadonly();
        });
        if (attachedToReadOnlySpans) {
            attachStatus.readOnlyAttached |= true;
        }
        attachStatus.attachCount += attachedSpans.size();
        */
    Set<AnnotationFS> attachedLinks = getAttachedLinks(aFS, layer);
    boolean attachedToReadOnlyLinks = attachedLinks.stream().anyMatch(relFS -> {
        AnnotationLayer relLayer = annotationService.getLayer(aProject, relFS);
        return relLayer.isReadonly();
    });
    if (attachedToReadOnlyLinks) {
        attachStatus.readOnlyAttached |= true;
    }
    attachStatus.attachCount += attachedLinks.size();
    return attachStatus;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 48 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class AnnotationFeatureForm method updateLayersDropdown.

public void updateLayersDropdown() {
    editorPanel.getLog().trace("updateLayersDropdown()");
    AnnotatorState state = getModelObject();
    annotationLayers.clear();
    AnnotationLayer l = null;
    for (AnnotationLayer layer : state.getAnnotationLayers()) {
        if (!layer.isEnabled() || layer.isReadonly() || layer.getName().equals(Token.class.getName())) {
            continue;
        }
        if (layer.getType().equals(WebAnnoConst.SPAN_TYPE)) {
            annotationLayers.add(layer);
            l = layer;
        } else // manage chain type
        if (layer.getType().equals(WebAnnoConst.CHAIN_TYPE)) {
            for (AnnotationFeature feature : annotationService.listAnnotationFeature(layer)) {
                if (!feature.isEnabled()) {
                    continue;
                }
                if (feature.getName().equals(WebAnnoConst.COREFERENCE_TYPE_FEATURE)) {
                    annotationLayers.add(layer);
                }
            }
        }
    // chain
    }
    if (state.getDefaultAnnotationLayer() != null) {
        state.setSelectedAnnotationLayer(state.getDefaultAnnotationLayer());
    } else if (l != null) {
        state.setSelectedAnnotationLayer(l);
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 49 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class AnnotationFeatureForm method actionReplace.

private void actionReplace(AjaxRequestTarget aTarget) throws IOException {
    AnnotatorState state = AnnotationFeatureForm.this.getModelObject();
    AnnotationLayer newLayer = layerSelector.getModelObject();
    JCas jCas = editorPanel.getEditorCas();
    AnnotationFS fs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
    AnnotationLayer currentLayer = annotationService.getLayer(state.getProject(), fs);
    if (currentLayer.isReadonly()) {
        error("Cannot replace an annotation on a read-only layer.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    AttachStatus attachStatus = editorPanel.checkAttachStatus(aTarget, state.getProject(), fs);
    if (attachStatus.readOnlyAttached) {
        error("Cannot replace an annotation to which annotations on read-only layers attach.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    replaceAnnotationDialog.setContentModel(new StringResourceModel("ReplaceDialog.text", AnnotationFeatureForm.this).setParameters(currentLayer.getUiName(), newLayer.getUiName(), attachStatus.attachCount));
    replaceAnnotationDialog.setConfirmAction((_target) -> {
        // The delete action clears the selection, but we need it to create
        // the new annotation - so we save it.
        Selection savedSel = editorPanel.getModelObject().getSelection().copy();
        // Delete current annotation
        editorPanel.actionDelete(_target);
        // Set up the action to create the replacement annotation
        AnnotationLayer layer = layerSelector.getModelObject();
        state.getSelection().set(savedSel);
        state.getSelection().setAnnotation(VID.NONE_ID);
        state.setSelectedAnnotationLayer(layer);
        state.setDefaultAnnotationLayer(layer);
        selectedAnnotationLayer.setDefaultModelObject(layer.getUiName());
        editorPanel.loadFeatureEditorModels(_target);
        // Create the replacement annotation
        editorPanel.actionCreateOrUpdate(_target, editorPanel.getEditorCas());
        layerSelector.modelChanged();
        _target.add(AnnotationFeatureForm.this);
    });
    replaceAnnotationDialog.setCancelAction((_target) -> {
        state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer());
        _target.add(AnnotationFeatureForm.this);
    });
    replaceAnnotationDialog.show(aTarget);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AttachStatus(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 50 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class AnnotationFeatureForm method actionDelete.

private void actionDelete(AjaxRequestTarget aTarget) throws IOException, AnnotationException {
    AnnotatorState state = AnnotationFeatureForm.this.getModelObject();
    AnnotationLayer layer = state.getSelectedAnnotationLayer();
    TypeAdapter adapter = annotationService.getAdapter(layer);
    JCas jCas = editorPanel.getEditorCas();
    AnnotationFS fs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
    if (layer.isReadonly()) {
        error("Cannot replace an annotation on a read-only layer.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    AttachStatus attachStatus = editorPanel.checkAttachStatus(aTarget, state.getProject(), fs);
    if (attachStatus.readOnlyAttached) {
        error("Cannot delete an annotation to which annotations on read-only layers attach.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    if (adapter instanceof SpanAdapter && attachStatus.attachCount > 0) {
        deleteAnnotationDialog.setContentModel(new StringResourceModel("DeleteDialog.text", this, Model.of(layer)).setParameters(attachStatus.attachCount));
        deleteAnnotationDialog.setConfirmAction((aCallbackTarget) -> {
            editorPanel.actionDelete(aCallbackTarget);
        });
        deleteAnnotationDialog.show(aTarget);
    } else {
        editorPanel.actionDelete(aTarget);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AttachStatus(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) JCas(org.apache.uima.jcas.JCas) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Aggregations

AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)67 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)35 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 ArrayList (java.util.ArrayList)14 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)13 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)8 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)7 Type (org.apache.uima.cas.Type)7 JCas (org.apache.uima.jcas.JCas)6 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)5 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 Test (org.junit.Test)5 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)4 HashMap (java.util.HashMap)4 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)3