Search in sources :

Example 6 with ArcAdapter

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

Example 7 with ArcAdapter

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

the class AnnotationDetailEditorPanel method createNewAnnotation.

private void createNewAnnotation(AjaxRequestTarget aTarget, TypeAdapter aAdapter, JCas aJCas) throws AnnotationException, IOException {
    AnnotatorState state = getModelObject();
    if (state.getSelection().isArc()) {
        if (aAdapter instanceof SpanAdapter) {
            error("Layer [" + aAdapter.getLayer().getUiName() + "] does not support arc annotation.");
            aTarget.addChildren(getPage(), IFeedback.class);
        } else if (aAdapter instanceof ArcAdapter) {
            createNewRelationAnnotation((ArcAdapter) aAdapter, aJCas);
        } else if (aAdapter instanceof ChainAdapter) {
            createNewChainLinkAnnotation((ChainAdapter) aAdapter, aJCas);
        } else {
            throw new IllegalStateException("I don't know how to use [" + aAdapter.getClass().getSimpleName() + "] in this situation.");
        }
    } else {
        if (aAdapter instanceof SpanAdapter) {
            createNewSpanAnnotation(aTarget, (SpanAdapter) aAdapter, aJCas);
        } else if (aAdapter instanceof ChainAdapter) {
            createNewChainElement((ChainAdapter) aAdapter, aJCas);
        } else {
            throw new IllegalStateException("I don't know how to use [" + aAdapter.getClass().getSimpleName() + "] in this situation.");
        }
    }
}
Also used : ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) ChainAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter)

Example 8 with ArcAdapter

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

the class AutomationUtil method deleteRelationAnnotation.

public static void deleteRelationAnnotation(AnnotatorState aBModel, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, AnnotationSchemaService aAnnotationService, AnnotationFS fs, AnnotationFeature aFeature, String aValue) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    for (SourceDocument d : aDocumentService.listSourceDocuments(aBModel.getProject())) {
        loadDocument(d, aAnnotationService, aDocumentService, aCorrectionDocumentService, aBModel.getUser());
        JCas jCas = aCorrectionDocumentService.readCorrectionCas(d);
        ArcAdapter adapter = (ArcAdapter) aAnnotationService.getAdapter(aFeature.getLayer());
        String sourceFName = adapter.getSourceFeatureName();
        String targetFName = adapter.getTargetFeatureName();
        Type type = getType(jCas.getCas(), aFeature.getLayer().getName());
        Type spanType = getType(jCas.getCas(), adapter.getAttachTypeName());
        Feature arcSpanFeature = spanType.getFeatureByBaseName(adapter.getAttachFeatureName());
        Feature dependentFeature = type.getFeatureByBaseName(targetFName);
        Feature governorFeature = type.getFeatureByBaseName(sourceFName);
        AnnotationFS dependentFs = null;
        AnnotationFS governorFs = null;
        if (adapter.getAttachFeatureName() != null) {
            dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
            governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
        } else {
            dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature);
            governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature);
        }
        int beginOffset = 0;
        int endOffset = jCas.getDocumentText().length() - 1;
        String depCoveredText = dependentFs.getCoveredText();
        String govCoveredText = governorFs.getCoveredText();
        adapter.delete(aBModel, jCas, aFeature, beginOffset, endOffset, depCoveredText, govCoveredText, aValue);
        aCorrectionDocumentService.writeCorrectionCas(jCas, d);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 9 with ArcAdapter

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

the class CasDiff2 method getAdapters.

public static List<DiffAdapter> getAdapters(AnnotationSchemaService annotationService, Project project) {
    List<DiffAdapter> adapters = new ArrayList<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(project)) {
        Set<String> labelFeatures = new LinkedHashSet<>();
        for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
            if (!f.isEnabled()) {
                continue;
            }
            // Link features are treated separately from primitive label features
            if (!LinkMode.NONE.equals(f.getLinkMode())) {
                continue;
            }
            labelFeatures.add(f.getName());
        }
        DiffAdapter_ImplBase adpt;
        switch(layer.getType()) {
            case SPAN_TYPE:
                {
                    adpt = new SpanDiffAdapter(layer.getName(), labelFeatures);
                    break;
                }
            case RELATION_TYPE:
                {
                    ArcAdapter typeAdpt = (ArcAdapter) annotationService.getAdapter(layer);
                    adpt = new ArcDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
                    break;
                }
            case CHAIN_TYPE:
                // FIXME Currently, these are ignored.
                continue;
            default:
                throw new IllegalStateException("Unknown layer type [" + layer.getType() + "]");
        }
        adapters.add(adpt);
        for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
            if (!f.isEnabled()) {
                continue;
            }
            switch(f.getLinkMode()) {
                case NONE:
                    // Nothing to do here
                    break;
                case SIMPLE:
                    adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
                    break;
                case WITH_ROLE:
                    adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
                    break;
                default:
                    throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
            }
            labelFeatures.add(f.getName());
        }
    }
    return adapters;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)9 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 Feature (org.apache.uima.cas.Feature)5 Type (org.apache.uima.cas.Type)5 JCas (org.apache.uima.jcas.JCas)4 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 ArrayList (java.util.ArrayList)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)3 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)2 WebAnnoCasUtil.setFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)2 ChainAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)1