Search in sources :

Example 51 with AnnotationFeature

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

the class SemPredArgLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer semArgLayer = new AnnotationLayer(SemArg.class.getName(), "SemArg", SPAN_TYPE, aProject, true);
    semArgLayer.setAllowStacking(true);
    semArgLayer.setCrossSentence(false);
    semArgLayer.setLockToTokenOffset(false);
    semArgLayer.setMultipleTokens(true);
    annotationSchemaService.createLayer(semArgLayer);
    AnnotationLayer semPredLayer = new AnnotationLayer(SemPred.class.getName(), "SemPred", SPAN_TYPE, aProject, true);
    semPredLayer.setAllowStacking(true);
    semPredLayer.setCrossSentence(false);
    semPredLayer.setLockToTokenOffset(false);
    semPredLayer.setMultipleTokens(true);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, semPredLayer, "category", "category", CAS.TYPE_NAME_STRING, "Category of the semantic predicate, e.g. the frame identifier.", null));
    AnnotationFeature semPredArgumentsFeature = new AnnotationFeature();
    semPredArgumentsFeature.setName("arguments");
    semPredArgumentsFeature.setUiName("arguments");
    semPredArgumentsFeature.setDescription("Arguments of the semantic predicate");
    semPredArgumentsFeature.setType(SemArg.class.getName());
    semPredArgumentsFeature.setProject(aProject);
    semPredArgumentsFeature.setTagset(null);
    semPredArgumentsFeature.setMode(MultiValueMode.ARRAY);
    semPredArgumentsFeature.setLinkMode(LinkMode.WITH_ROLE);
    semPredArgumentsFeature.setLinkTypeName(SemArgLink.class.getName());
    semPredArgumentsFeature.setLinkTypeRoleFeatureName("role");
    semPredArgumentsFeature.setLinkTypeTargetFeatureName("target");
    semPredArgumentsFeature.setLayer(semPredLayer);
    annotationSchemaService.createFeature(semPredArgumentsFeature);
    annotationSchemaService.createLayer(semPredLayer);
}
Also used : SemPred(de.tudarmstadt.ukp.dkpro.core.api.semantics.type.SemPred) SemArgLink(de.tudarmstadt.ukp.dkpro.core.api.semantics.type.SemArgLink) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) SemArg(de.tudarmstadt.ukp.dkpro.core.api.semantics.type.SemArg) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 52 with AnnotationFeature

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

the class SurfaceFormLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer surfaceFormLayer = new AnnotationLayer(SurfaceForm.class.getName(), "Surface form", SPAN_TYPE, aProject, true);
    surfaceFormLayer.setAllowStacking(false);
    // The surface form must be locked to tokens for CoNLL-U writer to work properly
    surfaceFormLayer.setLockToTokenOffset(false);
    surfaceFormLayer.setMultipleTokens(true);
    annotationSchemaService.createLayer(surfaceFormLayer);
    AnnotationFeature surfaceFormValueFeature = new AnnotationFeature();
    surfaceFormValueFeature.setDescription("Original surface text");
    surfaceFormValueFeature.setName("value");
    surfaceFormValueFeature.setType(CAS.TYPE_NAME_STRING);
    surfaceFormValueFeature.setProject(aProject);
    surfaceFormValueFeature.setUiName("Form");
    surfaceFormValueFeature.setLayer(surfaceFormLayer);
    annotationSchemaService.createFeature(surfaceFormValueFeature);
}
Also used : SurfaceForm(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.SurfaceForm) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 53 with AnnotationFeature

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

the class PrimitiveUimaFeatureSupport method getFeatureValue.

@Override
public <T> T getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS) {
    Feature feature = aFS.getType().getFeatureByBaseName(aFeature.getName());
    final String effectiveType = aFeature.getType();
    // Sanity check
    if (!Objects.equals(effectiveType, feature.getRange().getName())) {
        throw new IllegalArgumentException("Actual feature type [" + feature.getRange().getName() + "] does not match expected feature type [" + effectiveType + "].");
    }
    return WebAnnoCasUtil.getFeature(aFS, aFeature.getName());
}
Also used : Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 54 with AnnotationFeature

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

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

AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)73 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)34 Feature (org.apache.uima.cas.Feature)20 ArrayList (java.util.ArrayList)16 Type (org.apache.uima.cas.Type)16 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)15 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 JCas (org.apache.uima.jcas.JCas)10 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)9 File (java.io.File)9 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)8 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)6 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)6 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 List (java.util.List)6 FeatureStructure (org.apache.uima.cas.FeatureStructure)6 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)5 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)5 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)5