Search in sources :

Example 56 with AnnotatorState

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

the class AnnotationDetailEditorPanel method loadFeatureEditorModelsCommon.

private void loadFeatureEditorModelsCommon(AjaxRequestTarget aTarget, JCas aJCas, AnnotationLayer aLayer, FeatureStructure aFS, Map<AnnotationFeature, Serializable> aRemembered) {
    clearFeatureEditorModels(aTarget);
    AnnotatorState state = AnnotationDetailEditorPanel.this.getModelObject();
    // Populate from feature structure
    for (AnnotationFeature feature : annotationService.listAnnotationFeature(aLayer)) {
        if (!feature.isEnabled()) {
            continue;
        }
        Serializable value = null;
        if (aFS != null) {
            value = annotationService.getAdapter(aLayer).getFeatureValue(feature, aFS);
        } else if (aRemembered != null) {
            value = aRemembered.get(feature);
        }
        FeatureState featureState = null;
        if (WebAnnoConst.CHAIN_TYPE.equals(feature.getLayer().getType())) {
            if (state.getSelection().isArc()) {
                if (feature.getLayer().isLinkedListBehavior() && WebAnnoConst.COREFERENCE_RELATION_FEATURE.equals(feature.getName())) {
                    featureState = new FeatureState(feature, value);
                }
            } else {
                if (WebAnnoConst.COREFERENCE_TYPE_FEATURE.equals(feature.getName())) {
                    featureState = new FeatureState(feature, value);
                }
            }
        } else {
            featureState = new FeatureState(feature, value);
        }
        if (featureState != null) {
            state.getFeatureStates().add(featureState);
            // verification to check whether constraints exist for this project or NOT
            if (state.getConstraints() != null && state.getSelection().getAnnotation().isSet()) {
                // indicator.setRulesExist(true);
                populateTagsBasedOnRules(aJCas, featureState);
            } else {
                // indicator.setRulesExist(false);
                featureState.tagset = annotationService.listTags(featureState.feature.getTagset());
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 57 with AnnotatorState

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

the class AnnotationDetailEditorPanel method reset.

public void reset(AjaxRequestTarget aTarget) {
    AnnotatorState state = getModelObject();
    state.getSelection().clear();
    clearFeatureEditorModels(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Example 58 with AnnotatorState

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

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

the class AnnotationFeatureForm method updateRememberLayer.

void updateRememberLayer() {
    editorPanel.getLog().trace("updateRememberLayer()");
    AnnotatorState state = getModelObject();
    if (state.getPreferences().isRememberLayer()) {
        if (state.getDefaultAnnotationLayer() == null) {
            state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer());
        }
    } else if (!state.getSelection().isArc()) {
        state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer());
    }
    // if no layer is selected in Settings
    if (state.getSelectedAnnotationLayer() != null) {
        selectedAnnotationLayer.setDefaultModelObject(state.getSelectedAnnotationLayer().getUiName());
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Example 60 with AnnotatorState

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

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)84 JCas (org.apache.uima.jcas.JCas)37 IOException (java.io.IOException)26 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)23 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 UIMAException (org.apache.uima.UIMAException)20 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)16 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)16 ArrayList (java.util.ArrayList)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)14 List (java.util.List)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)9 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 SuggestionBuilder (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)9 Map (java.util.Map)9 NoResultException (javax.persistence.NoResultException)9 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)8 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)8