Search in sources :

Example 1 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer 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 AnnotationLayer

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

the class AnnotationDetailEditorPanel method refresh.

private void refresh(AnnotatorState state) {
    // This already happens in loadFeatureEditorModels() above - probably not needed
    // here again
    // annotationFeatureForm.updateLayersDropdown();
    LOG.trace("actionAnnotate() setting selected layer (not sure why)");
    if (annotationFeatureForm.getAnnotationLayers().isEmpty()) {
        state.setSelectedAnnotationLayer(new AnnotationLayer());
    } else if (state.getSelectedAnnotationLayer() == null) {
        if (state.getRememberedSpanLayer() == null) {
            state.setSelectedAnnotationLayer(annotationFeatureForm.getAnnotationLayers().get(0));
        } else {
            state.setSelectedAnnotationLayer(state.getRememberedSpanLayer());
        }
    }
    LOG.trace("actionAnnotate() selectedLayer: {}", state.getSelectedAnnotationLayer().getUiName());
// Actually not sure why we would want to clear these here - in fact, they should
// still be around for the rendering phase of the feature editors...
// clearFeatureEditorModels(aTarget);
// This already happens in loadFeatureEditorModels() above - probably not needed
// here again
// annotationFeatureForm.updateRememberLayer();
}
Also used : AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 3 with AnnotationLayer

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

the class AnnotationDetailEditorPanel method actionCreateOrUpdate.

@Override
public void actionCreateOrUpdate(AjaxRequestTarget aTarget, JCas aJCas) throws IOException, AnnotationException {
    LOG.trace("actionAnnotate");
    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();
    // switches from the selected span layer to the relation layer that is attached to the span
    if (state.getSelection().isArc()) {
        LOG.trace("actionAnnotate() relation annotation - looking for attached layer");
        // FIXME REC I think this whole section which meddles around with the selected
        // annotation layer should be moved out of there to the place where we originally set
        // the annotation layer...!
        AnnotationFS originFS = selectByAddr(aJCas, state.getSelection().getOrigin());
        AnnotationLayer spanLayer = annotationService.getLayer(state.getProject(), originFS);
        if (state.getPreferences().isRememberLayer() && // i.e. new annotation
        state.getSelection().getAnnotation().isNotSet() && !spanLayer.equals(state.getDefaultAnnotationLayer())) {
            throw new AnnotationException("No relation annotation allowed on layer [" + state.getDefaultAnnotationLayer().getUiName() + "]");
        }
        AnnotationLayer previousLayer = state.getSelectedAnnotationLayer();
        // Chain layers consist of arcs and spans
        if (spanLayer.getType().equals(WebAnnoConst.CHAIN_TYPE)) {
            // one layer both for the span and arc annotation
            state.setSelectedAnnotationLayer(spanLayer);
        } else // Otherwise, look up the possible relation layer(s) in the database.
        {
            for (AnnotationLayer l : annotationService.listAnnotationLayer(state.getProject())) {
                if ((l.getAttachType() != null && l.getAttachType().equals(spanLayer)) || (l.getAttachFeature() != null && l.getAttachFeature().getType().equals(spanLayer.getName()))) {
                    if (state.getAnnotationLayers().contains(l)) {
                        state.setSelectedAnnotationLayer(l);
                    } else {
                        state.setSelectedAnnotationLayer(null);
                    }
                    break;
                }
            }
        }
        state.setDefaultAnnotationLayer(spanLayer);
        // If we switched layers, we need to initialize the feature editors for the new layer
        if (!Objects.equals(previousLayer, state.getSelectedAnnotationLayer())) {
            LOG.trace("Layer changed from {} to {} - need to reload feature editors", previousLayer, state.getSelectedAnnotationLayer());
            loadFeatureEditorModels(aJCas, aTarget);
        }
    } else {
        // 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);
    internalCompleteAnnotation(aTarget, aJCas);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 4 with AnnotationLayer

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

the class AnnotationDetailEditorPanel method getAttachedRels.

public Set<AnnotationFS> getAttachedRels(AnnotationFS aFs, AnnotationLayer aLayer) {
    CAS cas = aFs.getCAS();
    Set<AnnotationFS> toBeDeleted = new HashSet<>();
    for (AnnotationLayer relationLayer : annotationService.listAttachedRelationLayers(aLayer)) {
        ArcAdapter relationAdapter = (ArcAdapter) annotationService.getAdapter(relationLayer);
        Type relationType = CasUtil.getType(cas, relationLayer.getName());
        Feature sourceFeature = relationType.getFeatureByBaseName(relationAdapter.getSourceFeatureName());
        Feature targetFeature = relationType.getFeatureByBaseName(relationAdapter.getTargetFeatureName());
        // This code is already prepared for the day that relations can go between
        // different layers and may have different attach features for the source and
        // target layers.
        Feature relationSourceAttachFeature = null;
        Feature relationTargetAttachFeature = null;
        if (relationAdapter.getAttachFeatureName() != null) {
            relationSourceAttachFeature = sourceFeature.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
            relationTargetAttachFeature = targetFeature.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
        }
        for (AnnotationFS relationFS : CasUtil.select(cas, relationType)) {
            // Here we get the annotations that the relation is pointing to in the UI
            FeatureStructure sourceFS;
            if (relationSourceAttachFeature != null) {
                sourceFS = relationFS.getFeatureValue(sourceFeature).getFeatureValue(relationSourceAttachFeature);
            } else {
                sourceFS = relationFS.getFeatureValue(sourceFeature);
            }
            FeatureStructure targetFS;
            if (relationTargetAttachFeature != null) {
                targetFS = relationFS.getFeatureValue(targetFeature).getFeatureValue(relationTargetAttachFeature);
            } else {
                targetFS = relationFS.getFeatureValue(targetFeature);
            }
            if (isSame(sourceFS, aFs) || isSame(targetFS, aFs)) {
                toBeDeleted.add(relationFS);
                LOG.debug("Deleted relation [" + getAddr(relationFS) + "] from layer [" + relationLayer.getName() + "]");
            }
        }
    }
    return toBeDeleted;
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) 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 AnnotationLayer

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

the class AnnotationFeatureForm method isForwardable.

private boolean isForwardable() {
    AnnotatorState state = getModelObject();
    AnnotationLayer selectedLayer = state.getSelectedAnnotationLayer();
    if (isNull(selectedLayer) || isNull(selectedLayer.getId())) {
        return false;
    }
    if (!selectedLayer.getType().equals(WebAnnoConst.SPAN_TYPE)) {
        return false;
    }
    if (!selectedLayer.isLockToTokenOffset()) {
        return false;
    }
    // which are are both enabled and visible).
    if (getEnabledFeatures(selectedLayer).size() != 1) {
        return false;
    }
    // we allow forward annotation only for a feature with a tagset
    if (annotationService.listAnnotationFeature(selectedLayer).get(0).getTagset() != null) {
        // there should be at least one tag in the tagset
        TagSet tagSet = annotationService.listAnnotationFeature(selectedLayer).get(0).getTagset();
        return !annotationService.listTags(tagSet).isEmpty();
    }
    // Or layers with a single visible/enabled free-text feature.
    return true;
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

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