Search in sources :

Example 1 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationDetailEditorPanel method actionDelete.

@Override
public void actionDelete(AjaxRequestTarget aTarget) throws IOException, AnnotationException {
    JCas jCas = getEditorCas();
    AnnotatorState state = getModelObject();
    AnnotationFS fs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
    AnnotationLayer layer = annotationService.getLayer(state.getProject(), fs);
    TypeAdapter adapter = annotationService.getAdapter(layer);
    if (layer.isReadonly()) {
        error("Cannot delete an annotation on a read-only layer.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    if (checkAttachStatus(aTarget, state.getProject(), fs).readOnlyAttached) {
        error("Cannot delete an annotation to which annotations on read-only layers attach.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    deleteAnnotation(jCas, state, fs, layer, adapter);
    // Store CAS again
    writeEditorCas(jCas);
    // Update progress information
    int sentenceNumber = getSentenceNumber(jCas, state.getSelection().getBegin());
    state.setFocusUnitIndex(sentenceNumber);
    state.getDocument().setSentenceAccessed(sentenceNumber);
    // Auto-scroll
    if (state.getPreferences().isScrollPage()) {
        autoScroll(jCas, false);
    }
    state.rememberFeatures();
    info(generateMessage(state.getSelectedAnnotationLayer(), null, true));
    state.getSelection().clear();
    // after delete will follow annotation
    aTarget.add(annotationFeatureForm);
    onChange(aTarget);
    onDelete(aTarget, fs);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) 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) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 2 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationDetailEditorPanel method internalCommitAnnotation.

private void internalCommitAnnotation(AjaxRequestTarget aTarget, JCas aJCas) throws AnnotationException, IOException {
    AnnotatorState state = getModelObject();
    LOG.trace("actionAnnotate() selectedLayer: {}", state.getSelectedAnnotationLayer().getUiName());
    LOG.trace("actionAnnotate() defaultLayer: {}", state.getDefaultAnnotationLayer().getUiName());
    if (state.getSelectedAnnotationLayer() == null) {
        error("No layer is selected. First select a layer.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    if (state.getSelectedAnnotationLayer().isReadonly()) {
        error("Layer is not editable.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    // Verify if input is valid according to tagset
    LOG.trace("actionAnnotate() verifying feature values in editors");
    List<FeatureState> featureStates = getModelObject().getFeatureStates();
    for (FeatureState featureState : featureStates) {
        AnnotationFeature feature = featureState.feature;
        if (CAS.TYPE_NAME_STRING.equals(feature.getType())) {
            String value = (String) featureState.value;
            // Check if tag is necessary, set, and correct
            if (value != null && feature.getTagset() != null && !feature.getTagset().isCreateTag() && !annotationService.existsTag(value, feature.getTagset())) {
                error("[" + value + "] is not in the tag list. Please choose from the existing tags");
                return;
            }
        }
    }
    // #186 - After filling a slot, the annotation detail panel is not updated
    aTarget.add(annotationFeatureForm.getFeatureEditorPanel());
    TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer());
    // If this is an annotation creation action, create the annotation
    if (state.getSelection().getAnnotation().isNotSet()) {
        // Load the feature editors with the remembered values (if any)
        loadFeatureEditorModels(aJCas, aTarget);
        createNewAnnotation(aTarget, adapter, aJCas);
    }
    // Update the features of the selected annotation from the values presently in the
    // feature editors
    writeFeatureEditorModelsToCas(adapter, aJCas);
    // Update progress information
    LOG.trace("actionAnnotate() updating progress information");
    int sentenceNumber = getSentenceNumber(aJCas, state.getSelection().getBegin());
    state.setFocusUnitIndex(sentenceNumber);
    state.getDocument().setSentenceAccessed(sentenceNumber);
    // persist changes
    writeEditorCas(aJCas);
    // Remember the current feature values independently for spans and relations
    LOG.trace("actionAnnotate() remembering feature editor values");
    state.rememberFeatures();
    // Loading feature editor values from CAS
    loadFeatureEditorModels(aJCas, aTarget);
    // onAnnotate callback
    LOG.trace("onAnnotate()");
    onAnnotate(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 3 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationDetailEditorPanel method actionReverse.

@Override
public void actionReverse(AjaxRequestTarget aTarget) throws IOException, AnnotationException {
    aTarget.addChildren(getPage(), IFeedback.class);
    JCas jCas = getEditorCas();
    AnnotatorState state = getModelObject();
    AnnotationFS idFs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
    jCas.removeFsFromIndexes(idFs);
    AnnotationFS originFs = selectByAddr(jCas, state.getSelection().getOrigin());
    AnnotationFS targetFs = selectByAddr(jCas, state.getSelection().getTarget());
    List<FeatureState> featureStates = getModelObject().getFeatureStates();
    TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer());
    if (adapter instanceof ArcAdapter) {
        // If no features, still create arc #256
        AnnotationFS arc = ((ArcAdapter) adapter).add(targetFs, originFs, jCas, state.getWindowBeginOffset(), state.getWindowEndOffset());
        state.getSelection().setAnnotation(new VID(getAddr(arc)));
        for (FeatureState featureState : featureStates) {
            adapter.setFeatureValue(state, jCas, getAddr(arc), featureState.feature, featureState.value);
        }
    } else {
        error("chains cannot be reversed");
        return;
    }
    // persist changes
    writeEditorCas(jCas);
    int sentenceNumber = getSentenceNumber(jCas, originFs.getBegin());
    state.setFocusUnitIndex(sentenceNumber);
    state.getDocument().setSentenceAccessed(sentenceNumber);
    if (state.getPreferences().isScrollPage()) {
        autoScroll(jCas, false);
    }
    info("The arc has been reversed");
    state.rememberFeatures();
    // in case the user re-reverse it
    state.getSelection().reverseArc();
    onChange(aTarget);
}
Also used : VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) 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) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)

Example 4 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationDetailEditorPanel method getAttachedSpans.

private Set<AnnotationFS> getAttachedSpans(AnnotationFS aFs, AnnotationLayer aLayer) {
    CAS cas = aFs.getCAS();
    Set<AnnotationFS> attachedSpans = new HashSet<>();
    TypeAdapter adapter = annotationService.getAdapter(aLayer);
    if (adapter instanceof SpanAdapter && aLayer.getAttachType() != null) {
        Type spanType = CasUtil.getType(cas, aLayer.getAttachType().getName());
        Feature attachFeature = spanType.getFeatureByBaseName(aLayer.getAttachFeature().getName());
        for (AnnotationFS attachedFs : selectAt(cas, spanType, aFs.getBegin(), aFs.getEnd())) {
            if (isSame(attachedFs.getFeatureValue(attachFeature), aFs)) {
                attachedSpans.add(attachedFs);
            }
        }
    }
    return attachedSpans;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) Feature(org.apache.uima.cas.Feature) WebAnnoCasUtil.setFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) HashSet(java.util.HashSet)

Example 5 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationDetailEditorPanel method actionCreateForward.

private void actionCreateForward(AjaxRequestTarget aTarget, JCas aJCas, boolean aIsForwarded) throws IOException, AnnotationException {
    LOG.trace("actionForward(isForwarded: {})", aIsForwarded);
    if (isAnnotationFinished()) {
        throw new AnnotationException("This document is already closed. Please ask your " + "project manager to re-open it via the Monitoring page");
    }
    AnnotatorState state = getModelObject();
    // Re-set the selected layer from the drop-down since it might have changed if we
    // have previously created a relation annotation
    state.setSelectedAnnotationLayer(annotationFeatureForm.getLayerSelector().getModelObject());
    internalCommitAnnotation(aTarget, aJCas);
    if (!aIsForwarded) {
        if (state.getSelection().getEnd() >= state.getWindowEndOffset()) {
            autoScroll(aJCas, true);
        }
        List<FeatureState> featureStates = getModelObject().getFeatureStates();
        if (featureStates.get(0).value != null) {
            LOG.info("BEGIN auto-forward annotation for tagset-based annotation");
            AnnotationFS nextToken = WebAnnoCasUtil.getNextToken(aJCas, state.getSelection().getBegin(), state.getSelection().getEnd());
            if (nextToken != null) {
                if (getModelObject().getWindowEndOffset() > nextToken.getBegin()) {
                    state.getSelection().selectSpan(aJCas, nextToken.getBegin(), nextToken.getEnd());
                    actionCreateForward(aTarget, aJCas, true);
                }
            }
            LOG.info("END auto-forward annotation for tagset-based annotation");
        } else {
            LOG.info("BEGIN auto-forward annotation for free-text annotation");
            // remove the entire annotation.
            if (featureStates.get(0).value == null) {
                TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer());
                AnnotationFS fs = selectByAddr(aJCas, state.getSelection().getAnnotation().getId());
                deleteAnnotation(aJCas, state, fs, featureStates.get(0).feature.getLayer(), adapter);
            }
            AnnotationFS nextToken = WebAnnoCasUtil.getNextToken(aJCas, state.getSelection().getBegin(), state.getSelection().getEnd());
            if (nextToken != null) {
                if (getModelObject().getWindowEndOffset() > nextToken.getBegin()) {
                    state.getSelection().selectSpan(aJCas, nextToken.getBegin(), nextToken.getEnd());
                    actionCreateForward(aTarget, aJCas, true);
                }
            }
            LOG.info("END auto-forward annotation for free-text annotation");
        }
        LOG.trace("onAutoForward()");
        onAutoForward(aTarget);
    }
    aTarget.add(annotationFeatureForm);
    internalCompleteAnnotation(aTarget, aJCas);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)

Aggregations

TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)12 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)9 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)7 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 JCas (org.apache.uima.jcas.JCas)4 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)3 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)3 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)3 CAS (org.apache.uima.cas.CAS)3 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)2 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)2 HashSet (java.util.HashSet)2 Type (org.apache.uima.cas.Type)2 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)1 ColoringStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy)1 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)1 VAnnotationMarker (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1