Search in sources :

Example 26 with Type

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

the class ChainAdapter method newLink.

/**
 * Create a new link annotation. Already adds the chain to the CAS.
 */
private AnnotationFS newLink(JCas aJCas, int aBegin, int aEnd) {
    String baseName = StringUtils.substringBeforeLast(getAnnotationTypeName(), CHAIN) + LINK;
    Type linkType = CasUtil.getType(aJCas.getCas(), baseName);
    AnnotationFS newLink = aJCas.getCas().createAnnotation(linkType, aBegin, aEnd);
    aJCas.getCas().addFsToIndexes(newLink);
    return newLink;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type)

Example 27 with Type

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

the class ChainAdapter method getSpan.

// get feature Value of existing span annotation
public Serializable getSpan(JCas aJCas, int aBegin, int aEnd, AnnotationFeature aFeature, String aLabelValue) {
    List<Token> tokens = selectOverlapping(aJCas, Token.class, aBegin, aEnd);
    int begin = tokens.get(0).getBegin();
    int end = tokens.get(tokens.size() - 1).getEnd();
    String baseName = StringUtils.substringBeforeLast(getAnnotationTypeName(), CHAIN) + LINK;
    Type linkType = CasUtil.getType(aJCas.getCas(), baseName);
    for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), linkType, begin, end)) {
        if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) {
            return getFeatureValue(aFeature, fs);
        }
    }
    return null;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)

Example 28 with Type

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

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

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

the class WebAnnoTsv3WriterTestBase method testMultiTokenChain.

@Test
public void testMultiTokenChain() 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);
    Token t4 = tokens.get(3);
    Type head = cas.getTypeSystem().getType("webanno.custom.SimpleChain");
    Type link = cas.getTypeSystem().getType("webanno.custom.SimpleLink");
    makeChainHead(head, makeChainLink(link, cas, t1.getBegin(), t2.getEnd(), null, null, makeChainLink(link, cas, t3.getBegin(), t4.getEnd(), null, null, null)));
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_CHAIN_LAYERS, asList("webanno.custom.Simple"));
}
Also used : 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

Type (org.apache.uima.cas.Type)160 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)112 JCas (org.apache.uima.jcas.JCas)75 ArrayList (java.util.ArrayList)72 Feature (org.apache.uima.cas.Feature)62 Test (org.junit.Test)59 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)54 CAS (org.apache.uima.cas.CAS)47 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)40 FeatureStructure (org.apache.uima.cas.FeatureStructure)39 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)29 List (java.util.List)25 IOException (java.io.IOException)17 HashMap (java.util.HashMap)15 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)14 LinkedHashMap (java.util.LinkedHashMap)14 NamedEntity (de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity)13 Map (java.util.Map)13 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)13 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)13