Search in sources :

Example 56 with FeatureStructure

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

the class WebAnnoTsv3WriterTestBase method testComplexSlotFeatureWithoutValues.

@Test
public void testComplexSlotFeatureWithoutValues() 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, "webanno.custom.ComplexLinkType", null, s2);
    FeatureStructure link2 = makeLinkFS(jcas, "webanno.custom.ComplexLinkType", null, s3);
    makeLinkHostFS(jcas, "webanno.custom.ComplexLinkHost", t1.getBegin(), t1.getEnd(), link1, link2);
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.ComplexLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.ComplexLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.ComplexLinkType"), 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 57 with FeatureStructure

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

the class ReindexFeatureAttachedSpanAnnotationsRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    Map<FeatureStructure, FeatureStructure> nonIndexed = getNonIndexedFSesWithOwner(aCas);
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
            continue;
        }
        int count = 0;
        // anno -> e.g. Lemma
        for (AnnotationFS attach : select(aCas, getType(aCas, layer.getAttachType().getName()))) {
            AnnotationFS anno = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
            if (anno != null && nonIndexed.containsKey(anno)) {
                aCas.addFsToIndexes(anno);
                count++;
            }
        }
        if (count > 0) {
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Reindexed [%d] unindexed spans in layer [" + layer.getName() + "].", count));
        }
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 58 with FeatureStructure

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

the class RemoveDanglingChainLinksRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!WebAnnoConst.CHAIN_TYPE.equals(layer.getType())) {
            continue;
        }
        List<FeatureStructure> chains = new ArrayList<>(selectFS(aCas, getType(aCas, layer.getName() + "Chain")));
        List<AnnotationFS> links = new ArrayList<>(select(aCas, getType(aCas, layer.getName() + "Link")));
        for (FeatureStructure chain : chains) {
            AnnotationFS link = FSUtil.getFeature(chain, "first", AnnotationFS.class);
            while (link != null) {
                links.remove(link);
                link = FSUtil.getFeature(link, "next", AnnotationFS.class);
            }
        }
        // Delete those relations that pointed to deleted spans
        if (!links.isEmpty()) {
            links.forEach(aCas::removeFsFromIndexes);
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Removed [%d] dangling links in layer [" + layer.getName() + "].", links.size()));
        }
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 59 with FeatureStructure

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

the class RemoveDanglingRelationsRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    Set<FeatureStructure> nonIndexed = getNonIndexedFSes(aCas);
    Set<FeatureStructure> toDelete = new LinkedHashSet<>();
    for (AnnotationFS fs : aCas.getAnnotationIndex()) {
        Type t = fs.getType();
        Feature sourceFeat = t.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
        Feature targetFeat = t.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
        // Is this a relation?
        if (!(sourceFeat != null && targetFeat != null)) {
            continue;
        }
        FeatureStructure source = fs.getFeatureValue(sourceFeat);
        FeatureStructure target = fs.getFeatureValue(targetFeat);
        // Does it point to deleted spans?
        if (nonIndexed.contains(source) || nonIndexed.contains(target)) {
            toDelete.add(fs);
        }
    }
    // Delete those relations that pointed to deleted spans
    if (!toDelete.isEmpty()) {
        toDelete.forEach(aCas::removeFsFromIndexes);
        aMessages.add(new LogMessage(this, LogLevel.INFO, "Removed [%d] dangling relations.", nonIndexed.size()));
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) LinkedHashSet(java.util.LinkedHashSet) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) Feature(org.apache.uima.cas.Feature)

Example 60 with FeatureStructure

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

the class Tsv3XSerializer method writeSlotTarget.

private static void writeSlotTarget(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol, AnnotationFS aFS) {
    FeatureStructure[] links = getFeature(aFS, aCol.uimaFeature, FeatureStructure[].class);
    if (links != null && links.length > 0) {
        for (int i = 0; i < links.length; i++) {
            if (i > 0) {
                aOut.print(SLOT_SEP);
            }
            AnnotationFS targetFS = getFeature(links[i], TsvSchema.FEAT_SLOT_TARGET, AnnotationFS.class);
            if (targetFS == null) {
                throw new IllegalStateException("Slot link has no target: " + links[i]);
            }
            TsvUnit target = aDoc.findIdDefiningUnit(targetFS);
            if (target == null) {
                throw new IllegalStateException("Unable to find ID-defining unit for annotation: " + targetFS);
            }
            aOut.print(target.getId());
            writeDisambiguationId(aOut, aDoc, targetFS);
        }
    } else {
        aOut.print(NULL_COLUMN);
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) TsvUnit(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvUnit)

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