Search in sources :

Example 61 with Feature

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

the class MergeCas method getAllFeatures.

public static Feature[] getAllFeatures(FeatureStructure aFS) {
    Feature[] cachedSortedFeatures = new Feature[aFS.getType().getNumberOfFeatures()];
    int i = 0;
    for (Feature f : aFS.getType().getFeatures()) {
        cachedSortedFeatures[i] = f;
        i++;
    }
    return cachedSortedFeatures;
}
Also used : 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)

Example 62 with Feature

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

the class MergeCas method copySpanAnnotation.

/**
 * Copy this same annotation from the user annotation to the mergeview
 */
private static void copySpanAnnotation(AnnotatorState aState, AnnotationSchemaService aAnnotationService, AnnotationLayer aAnnotationLayer, AnnotationFS aOldFs, JCas aJCas) throws AnnotationException {
    SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aAnnotationLayer);
    // Create the annotation - this also takes care of attaching to an annotation if necessary
    int id = adapter.add(aState, aJCas, aOldFs.getBegin(), aOldFs.getEnd());
    List<AnnotationFeature> features = aAnnotationService.listAnnotationFeature(adapter.getLayer());
    // Copy the features
    for (AnnotationFeature feature : features) {
        Type oldType = adapter.getAnnotationType(aOldFs.getCAS());
        Feature oldFeature = oldType.getFeatureByBaseName(feature.getName());
        if (isLinkOrBasicFeatures(aOldFs, oldFeature)) {
            continue;
        }
        Object value = adapter.getFeatureValue(feature, aOldFs);
        adapter.setFeatureValue(aState, aJCas, id, feature, value);
    }
}
Also used : Type(org.apache.uima.cas.Type) 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 63 with Feature

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

the class CopyAnnotationTest method simpleCopyRelationToEmptyAnnoTest.

@Test
public void simpleCopyRelationToEmptyAnnoTest() throws Exception {
    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(Dependency.class.getTypeName());
    Type posType = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS originClickedToken = createTokenAnno(jcas, 0, 0);
    AnnotationFS targetClickedToken = createTokenAnno(jcas, 1, 1);
    AnnotationFS originClicked = createPOSAnno(jcas, posType, "NN", 0, 0);
    AnnotationFS targetClicked = createPOSAnno(jcas, posType, "NN", 1, 1);
    jcas.addFsToIndexes(originClicked);
    jcas.addFsToIndexes(targetClicked);
    originClickedToken.setFeatureValue(originClickedToken.getType().getFeatureByBaseName("pos"), originClicked);
    targetClickedToken.setFeatureValue(targetClickedToken.getType().getFeatureByBaseName("pos"), targetClicked);
    Feature sourceFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
    Feature targetFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
    AnnotationFS clickedFs = jcas.getCas().createAnnotation(type, 0, 1);
    clickedFs.setFeatureValue(sourceFeature, originClickedToken);
    clickedFs.setFeatureValue(targetFeature, targetClickedToken);
    jcas.addFsToIndexes(clickedFs);
    JCas mergeCAs = JCasFactory.createJCas();
    AnnotationFS origin = createPOSAnno(mergeCAs, posType, "NN", 0, 0);
    AnnotationFS target = createPOSAnno(mergeCAs, posType, "NN", 1, 1);
    mergeCAs.addFsToIndexes(origin);
    mergeCAs.addFsToIndexes(target);
    AnnotationFS originToken = createTokenAnno(mergeCAs, 0, 0);
    AnnotationFS targetToken = createTokenAnno(mergeCAs, 1, 1);
    originToken.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin);
    targetToken.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target);
    mergeCAs.addFsToIndexes(originToken);
    mergeCAs.addFsToIndexes(targetToken);
    MergeCas.addRelationArcAnnotation(mergeCAs, clickedFs, true, false, originToken, targetToken);
    assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 1).size());
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) JCas(org.apache.uima.jcas.JCas) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Example 64 with Feature

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

the class CopyAnnotationTest method simpleCopyToDiffExistingAnnoWithNoStackingTest.

@Test
public void simpleCopyToDiffExistingAnnoWithNoStackingTest() throws Exception {
    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
    JCas mergeCAs = JCasFactory.createJCas();
    AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
    Feature posValue = type.getFeatureByBaseName("PosValue");
    existingFs.setStringValue(posValue, "NE");
    mergeCAs.addFsToIndexes(existingFs);
    MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService, posLayer, mergeCAs, clickedFs, false);
    assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) JCas(org.apache.uima.jcas.JCas) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Example 65 with Feature

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

the class CopyAnnotationTest method simpleCopyStackedRelationTest.

@Test
public void simpleCopyStackedRelationTest() throws Exception {
    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(Dependency.class.getTypeName());
    Type posType = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS originClickedToken = createTokenAnno(jcas, 0, 0);
    AnnotationFS targetClickedToken = createTokenAnno(jcas, 1, 1);
    AnnotationFS originClicked = createPOSAnno(jcas, posType, "NN", 0, 0);
    AnnotationFS targetClicked = createPOSAnno(jcas, posType, "NN", 1, 1);
    jcas.addFsToIndexes(originClicked);
    jcas.addFsToIndexes(targetClicked);
    originClickedToken.setFeatureValue(originClickedToken.getType().getFeatureByBaseName("pos"), originClicked);
    targetClickedToken.setFeatureValue(targetClickedToken.getType().getFeatureByBaseName("pos"), targetClicked);
    Feature sourceFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
    Feature targetFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
    AnnotationFS clickedFs = jcas.getCas().createAnnotation(type, 0, 1);
    clickedFs.setFeatureValue(sourceFeature, originClickedToken);
    clickedFs.setFeatureValue(targetFeature, targetClickedToken);
    jcas.addFsToIndexes(clickedFs);
    JCas mergeCAs = JCasFactory.createJCas();
    AnnotationFS origin = createPOSAnno(mergeCAs, posType, "NN", 0, 0);
    AnnotationFS target = createPOSAnno(mergeCAs, posType, "NN", 1, 1);
    mergeCAs.addFsToIndexes(origin);
    mergeCAs.addFsToIndexes(target);
    AnnotationFS originToken = createTokenAnno(mergeCAs, 0, 0);
    AnnotationFS targetToken = createTokenAnno(mergeCAs, 1, 1);
    originToken.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin);
    targetToken.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target);
    mergeCAs.addFsToIndexes(originToken);
    mergeCAs.addFsToIndexes(targetToken);
    AnnotationFS existing = mergeCAs.getCas().createAnnotation(type, 0, 1);
    existing.setFeatureValue(sourceFeature, originToken);
    existing.setFeatureValue(targetFeature, targetToken);
    mergeCAs.addFsToIndexes(clickedFs);
    exception.expect(AnnotationException.class);
    MergeCas.addRelationArcAnnotation(mergeCAs, clickedFs, true, false, originToken, targetToken);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) JCas(org.apache.uima.jcas.JCas) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

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