Search in sources :

Example 6 with Selection

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection 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 7 with Selection

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection 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 8 with Selection

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection in project webanno by webanno.

the class BratAnnotationEditor method actionArc.

private ArcAnnotationResponse actionArc(AjaxRequestTarget aTarget, IRequestParameters request, JCas jCas, VID paramId) throws IOException, AnnotationException {
    AnnotationFS originFs = selectByAddr(jCas, request.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt());
    AnnotationFS targetFs = selectByAddr(jCas, request.getParameterValue(PARAM_TARGET_SPAN_ID).toInt());
    AnnotatorState state = getModelObject();
    Selection selection = state.getSelection();
    selection.selectArc(paramId, originFs, targetFs);
    if (selection.getAnnotation().isNotSet()) {
        // Create new annotation
        getActionHandler().actionCreateOrUpdate(aTarget, jCas);
    } else {
        getActionHandler().actionSelect(aTarget, jCas);
    }
    return new ArcAnnotationResponse();
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) ArcAnnotationResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.ArcAnnotationResponse) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)8 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)8 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)7 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)4 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)4 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)3 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)3 IOException (java.io.IOException)3 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)2 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)2 ProjectService (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService)2 WebAnnoConst (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst)2 AnnotationEditorExtensionRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorExtensionRegistry)2 AnnotationActionHandler (de.tudarmstadt.ukp.clarin.webanno.api.annotation.action.AnnotationActionHandler)2 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)2 ChainAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter)2 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)2 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)2 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)2 TypeUtil (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil)2