Search in sources :

Example 16 with FeatureStructure

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

the class TypeAdapter_ImplBase method setFeatureValue.

@Override
public void setFeatureValue(AnnotatorState aState, JCas aJcas, int aAddress, AnnotationFeature aFeature, Object aValue) {
    FeatureStructure fs = selectByAddr(aJcas, aAddress);
    Object oldValue = getValue(fs, aFeature);
    featureSupportRegistry.getFeatureSupport(aFeature).setFeatureValue(aJcas, aFeature, aAddress, aValue);
    Object newValue = getValue(fs, aFeature);
    if (!Objects.equals(oldValue, newValue)) {
        publishEvent(new FeatureValueUpdatedEvent(this, aState.getDocument(), aState.getUser().getUsername(), fs, aFeature, newValue, oldValue));
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) FeatureValueUpdatedEvent(de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.FeatureValueUpdatedEvent)

Example 17 with FeatureStructure

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

the class WebAnnoCasUtil method setLinkFeatureValue.

public static void setLinkFeatureValue(FeatureStructure aFS, Feature aFeature, List<FeatureStructure> linkFSes) {
    // Create a new array if size differs otherwise re-use existing one
    ArrayFS array = (ArrayFS) WebAnnoCasUtil.getFeatureFS(aFS, aFeature.getShortName());
    if (array == null || (array.size() != linkFSes.size())) {
        array = aFS.getCAS().createArrayFS(linkFSes.size());
    }
    // Fill in links
    array.copyFromArray(linkFSes.toArray(new FeatureStructure[linkFSes.size()]), 0, 0, linkFSes.size());
    aFS.setFeatureValue(aFeature, array);
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) ArrayFS(org.apache.uima.cas.ArrayFS)

Example 18 with FeatureStructure

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

the class WebAnnoCasUtil method setLinkFeature.

private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeature, List<LinkWithRoleModel> aValue, Feature feature) {
    Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName());
    Feature roleFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeRoleFeatureName());
    Feature targetFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeTargetFeatureName());
    // Create all the links
    // FIXME: actually we could re-use existing link link feature structures
    List<FeatureStructure> linkFSes = new ArrayList<>();
    if (aValue != null) {
        // remove duplicate links
        Set<LinkWithRoleModel> links = new HashSet<>(aValue);
        for (LinkWithRoleModel e : links) {
            // set
            if (e.targetAddr == -1) {
                continue;
            }
            FeatureStructure link = aFS.getCAS().createFS(linkType);
            link.setStringValue(roleFeat, e.role);
            link.setFeatureValue(targetFeat, selectByAddr(aFS.getCAS(), e.targetAddr));
            linkFSes.add(link);
        }
    }
    setLinkFeatureValue(aFS, feature, linkFSes);
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) ArrayList(java.util.ArrayList) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) HashSet(java.util.HashSet)

Example 19 with FeatureStructure

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

the class WebAnnoTsv3WriterTestBase method testZeroLengthSlotFeature1.

@Test
public void testZeroLengthSlotFeature1() throws Exception {
    JCas jcas = makeJCasOneSentence();
    CAS cas = jcas.getCas();
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
    Token t1 = tokens.get(0);
    Token t2 = tokens.get(1);
    Token t3 = tokens.get(2);
    Type type = cas.getTypeSystem().getType("webanno.custom.SimpleSpan");
    AnnotationFS s2 = cas.createAnnotation(type, t2.getBegin(), t3.getEnd());
    cas.addFsToIndexes(s2);
    AnnotationFS s3 = cas.createAnnotation(type, t2.getBegin(), t3.getEnd());
    cas.addFsToIndexes(s3);
    FeatureStructure link1 = makeLinkFS(jcas, "p1", s2);
    FeatureStructure link2 = makeLinkFS(jcas, "p2", s3);
    makeLinkHostFS(jcas, t1.getBegin(), t1.getBegin(), link1, link2);
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.SimpleLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.SimpleLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"), WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan"));
}
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) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Test(org.junit.Test)

Example 20 with FeatureStructure

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

the class WebAnnoTsv3WriterTestBase method testStackedSimpleSlotFeatureWithoutValues.

@Test
public void testStackedSimpleSlotFeatureWithoutValues() throws Exception {
    JCas jcas = makeJCasOneSentence();
    CAS cas = jcas.getCas();
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
    Token t1 = tokens.get(0);
    Token t2 = tokens.get(1);
    Token t3 = tokens.get(2);
    Type type = cas.getTypeSystem().getType("webanno.custom.SimpleSpan");
    AnnotationFS s2 = cas.createAnnotation(type, t2.getBegin(), t2.getEnd());
    cas.addFsToIndexes(s2);
    AnnotationFS s3 = cas.createAnnotation(type, t3.getBegin(), t3.getEnd());
    cas.addFsToIndexes(s3);
    {
        FeatureStructure link1 = makeLinkFS(jcas, null, s2);
        FeatureStructure link2 = makeLinkFS(jcas, null, s3);
        makeLinkHostFS(jcas, t1.getBegin(), t1.getEnd(), link1, link2);
    }
    {
        FeatureStructure link1 = makeLinkFS(jcas, null, s2);
        FeatureStructure link2 = makeLinkFS(jcas, null, s3);
        makeLinkHostFS(jcas, t1.getBegin(), t1.getEnd(), link1, link2);
    }
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.SimpleLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.SimpleLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"), WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan"));
}
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) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Test(org.junit.Test)

Aggregations

FeatureStructure (org.apache.uima.cas.FeatureStructure)60 Type (org.apache.uima.cas.Type)38 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)37 ArrayList (java.util.ArrayList)29 JCas (org.apache.uima.jcas.JCas)20 Feature (org.apache.uima.cas.Feature)17 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)16 CAS (org.apache.uima.cas.CAS)16 Test (org.junit.Test)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)13 List (java.util.List)12 ArrayFS (org.apache.uima.cas.ArrayFS)8 Arrays.asList (java.util.Arrays.asList)6 LinkedHashMap (java.util.LinkedHashMap)6 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)6 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)5 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)4 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)4 TsvColumn (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvColumn)4 Map (java.util.Map)4