Search in sources :

Example 1 with Feature

use of org.apache.uima.cas.Feature in project lucene-solr by apache.

the class SampleEntityAnnotator method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
    Feature entityFeature = type.getFeatureByBaseName(ENTITY_FEATURE);
    Feature nameFeature = type.getFeatureByBaseName(NAME_FEATURE);
    for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
        String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
        if (NP.equals(tokenPOS) || NPS.equals(tokenPOS)) {
            AnnotationFS entityAnnotation = jcas.getCas().createAnnotation(type, annotation.getBegin(), annotation.getEnd());
            entityAnnotation.setStringValue(entityFeature, annotation.getCoveredText());
            // "OTHER" makes no sense. In practice, "PERSON", "COUNTRY", "E-MAIL", etc.
            String name = "OTHER";
            if (annotation.getCoveredText().equals("Apache"))
                name = "ORGANIZATION";
            entityAnnotation.setStringValue(nameFeature, name);
            jcas.addFsToIndexes(entityAnnotation);
        }
    }
}
Also used : TokenAnnotation(org.apache.uima.TokenAnnotation) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) Feature(org.apache.uima.cas.Feature) Annotation(org.apache.uima.jcas.tcas.Annotation) TokenAnnotation(org.apache.uima.TokenAnnotation)

Example 2 with Feature

use of org.apache.uima.cas.Feature in project lucene-solr by apache.

the class SamplePoSTagger method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
    Feature posFeature = type.getFeatureByBaseName(FEATURE_NAME);
    for (Annotation annotation : jcas.getAnnotationIndex(type)) {
        String text = annotation.getCoveredText();
        String pos = extractPoS(text);
        annotation.setStringValue(posFeature, pos);
    }
}
Also used : Type(org.apache.uima.cas.Type) Feature(org.apache.uima.cas.Feature) Annotation(org.apache.uima.jcas.tcas.Annotation)

Example 3 with Feature

use of org.apache.uima.cas.Feature 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 4 with Feature

use of org.apache.uima.cas.Feature 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 Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class WebannoTsv3Reader method addChainAnnotations.

/**
 * The individual link annotations are stored in a {@link TreeMap} (chainAnnosPerTye) with chain
 * number and link number references, sorted in an ascending order <br>
 * Iterate over each chain number and link number references and construct the chain.
 */
private void addChainAnnotations(JCas aJCas) {
    for (Type linkType : chainAnnosPerTyep.keySet()) {
        for (int chainNo : chainAnnosPerTyep.get(linkType).keySet()) {
            Type chainType = aJCas.getCas().getTypeSystem().getType(linkType.getName().substring(0, linkType.getName().length() - 4) + CHAIN);
            Feature firstF = chainType.getFeatureByBaseName(FIRST);
            Feature nextF = linkType.getFeatureByBaseName(NEXT);
            FeatureStructure chain = aJCas.getCas().createFS(chainType);
            aJCas.addFsToIndexes(chain);
            AnnotationFS firstFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(1);
            AnnotationFS linkFs = firstFs;
            chain.setFeatureValue(firstF, firstFs);
            for (int i = 2; i <= chainAnnosPerTyep.get(linkType).get(chainNo).size(); i++) {
                linkFs.setFeatureValue(nextF, chainAnnosPerTyep.get(linkType).get(chainNo).get(i));
                linkFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(i);
            }
        }
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) Feature(org.apache.uima.cas.Feature)

Aggregations

Feature (org.apache.uima.cas.Feature)84 Type (org.apache.uima.cas.Type)62 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)50 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)48 ArrayList (java.util.ArrayList)23 FeatureStructure (org.apache.uima.cas.FeatureStructure)18 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)18 JCas (org.apache.uima.jcas.JCas)18 List (java.util.List)15 Test (org.junit.Test)14 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)13 WebAnnoCasUtil.setFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature)12 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)12 CAS (org.apache.uima.cas.CAS)10 HashSet (java.util.HashSet)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 HashMap (java.util.HashMap)7 TypeSystem (org.apache.uima.cas.TypeSystem)7 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)6