Search in sources :

Example 6 with LinkWithRoleModel

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

the class LinkFeatureEditor method actionDel.

private void actionDel(AjaxRequestTarget aTarget) {
    @SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) LinkFeatureEditor.this.getModelObject().value;
    AnnotatorState state = LinkFeatureEditor.this.stateModel.getObject();
    links.remove(state.getArmedSlot());
    state.clearArmedSlot();
    aTarget.add(content);
    // Auto-commit if working on existing annotation
    if (state.getSelection().getAnnotation().isSet()) {
        try {
            actionHandler.actionCreateOrUpdate(aTarget, actionHandler.getEditorCas());
        } catch (Exception e) {
            handleException(this, aTarget, e);
        }
    }
}
Also used : LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) List(java.util.List) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException)

Example 7 with LinkWithRoleModel

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

the class LinkFeatureEditor method actionSet.

private void actionSet(AjaxRequestTarget aTarget) {
    @SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) LinkFeatureEditor.this.getModelObject().value;
    AnnotatorState state = LinkFeatureEditor.this.stateModel.getObject();
    // Update the slot
    LinkWithRoleModel m = links.get(state.getArmedSlot());
    m.role = (String) field.getModelObject();
    // avoid reordering
    links.set(state.getArmedSlot(), m);
    aTarget.add(content);
    // and leaves behind an armed slot pointing to a removed slot.
    if (m.targetAddr != -1) {
        try {
            actionHandler.actionCreateOrUpdate(aTarget, actionHandler.getEditorCas());
        } catch (Exception e) {
            handleException(this, aTarget, e);
        }
    }
}
Also used : LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) List(java.util.List) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException)

Example 8 with LinkWithRoleModel

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

the class AnnotationDetailEditorPanel method getAttachedLinks.

private Set<AnnotationFS> getAttachedLinks(AnnotationFS aFs, AnnotationLayer aLayer) {
    CAS cas = aFs.getCAS();
    Set<AnnotationFS> attachedLinks = new HashSet<>();
    TypeAdapter adapter = annotationService.getAdapter(aLayer);
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(aLayer)) {
            if (MultiValueMode.ARRAY.equals(linkFeature.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(linkFeature.getLinkMode())) {
                // Fetch slot hosts that could link to the current FS and check if any of
                // them actually links to the current FS
                Type linkType = CasUtil.getType(cas, linkFeature.getLayer().getName());
                for (AnnotationFS linkFS : CasUtil.select(cas, linkType)) {
                    List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
                    for (int li = 0; li < links.size(); li++) {
                        LinkWithRoleModel link = links.get(li);
                        AnnotationFS linkTarget = selectByAddr(cas, AnnotationFS.class, link.targetAddr);
                        // our list of attached links.
                        if (isSame(linkTarget, aFs)) {
                            attachedLinks.add(linkFS);
                        }
                    }
                }
            }
        }
    }
    return attachedLinks;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) 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) HashSet(java.util.HashSet) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 9 with LinkWithRoleModel

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

the class AnnotationDetailEditorPanel method setSlot.

@SuppressWarnings("unchecked")
private void setSlot(AjaxRequestTarget aTarget, JCas aJCas, int aAnnotationId) {
    AnnotatorState state = getModelObject();
    // Set an armed slot
    if (!state.getSelection().isArc() && state.isSlotArmed()) {
        List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) state.getFeatureState(state.getArmedFeature()).value;
        LinkWithRoleModel link = links.get(state.getArmedSlot());
        link.targetAddr = aAnnotationId;
        link.label = selectByAddr(aJCas, aAnnotationId).getCoveredText();
    }
    // Auto-commit if working on existing annotation
    if (state.getSelection().getAnnotation().isSet()) {
        try {
            actionCreateOrUpdate(aTarget, aJCas);
        } catch (Exception e) {
            handleException(this, aTarget, e);
        }
    }
    state.clearArmedSlot();
}
Also used : LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) List(java.util.List) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 10 with LinkWithRoleModel

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

the class AnnotationDetailEditorPanel method deleteAnnotation.

private void deleteAnnotation(JCas jCas, AnnotatorState state, AnnotationFS fs, AnnotationLayer layer, TypeAdapter adapter) {
    // is no longer set after UNATTACH SPANS!
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFS attachedFs : getAttachedRels(fs, layer)) {
            jCas.getCas().removeFsFromIndexes(attachedFs);
            info("The attached annotation for relation type [" + annotationService.getLayer(attachedFs.getType().getName(), state.getProject()).getUiName() + "] is deleted");
        }
    }
    // to look at span annotations that have the same offsets as the FS to be deleted.
    if (adapter instanceof SpanAdapter && layer.getAttachType() != null && layer.getAttachFeature() != null) {
        Type spanType = CasUtil.getType(jCas.getCas(), layer.getAttachType().getName());
        Feature attachFeature = spanType.getFeatureByBaseName(layer.getAttachFeature().getName());
        for (AnnotationFS attachedFs : getAttachedSpans(fs, layer)) {
            attachedFs.setFeatureValue(attachFeature, null);
            LOG.debug("Unattached [" + attachFeature.getShortName() + "] on annotation [" + getAddr(attachedFs) + "]");
        }
    }
    // to be deleted: the link feature must be the type of the FS or it must be generic.
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(layer)) {
            Type linkType = CasUtil.getType(jCas.getCas(), linkFeature.getLayer().getName());
            for (AnnotationFS linkFS : CasUtil.select(jCas.getCas(), linkType)) {
                List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
                Iterator<LinkWithRoleModel> i = links.iterator();
                boolean modified = false;
                while (i.hasNext()) {
                    LinkWithRoleModel link = i.next();
                    if (link.targetAddr == getAddr(fs)) {
                        i.remove();
                        LOG.debug("Cleared slot [" + link.role + "] in feature [" + linkFeature.getName() + "] on annotation [" + getAddr(linkFS) + "]");
                        modified = true;
                    }
                }
                if (modified) {
                    setFeature(linkFS, linkFeature, links);
                }
            }
        }
    }
    // relation.
    if (adapter instanceof ArcAdapter) {
    // Do nothing ;)
    }
    // Actually delete annotation
    adapter.delete(state, jCas, state.getSelection().getAnnotation());
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) 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) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)11 List (java.util.List)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)5 Type (org.apache.uima.cas.Type)5 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)4 ArrayList (java.util.ArrayList)4 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)3 HashSet (java.util.HashSet)3 UIMAException (org.apache.uima.UIMAException)3 Feature (org.apache.uima.cas.Feature)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)1 VRange (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange)1