Search in sources :

Example 6 with LowLevelCAS

use of org.apache.uima.cas.impl.LowLevelCAS in project webanno by webanno.

the class CasDoctorUtils method collectIndexed.

public static Set<FeatureStructure> collectIndexed(CAS aCas) {
    LowLevelCAS llcas = aCas.getLowLevelCAS();
    Set<FeatureStructure> fses = new TreeSet<>(Comparator.comparingInt(llcas::ll_getFSRef));
    FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS(aCas.getTypeSystem().getTopType());
    i.forEachRemaining(fses::add);
    return fses;
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) TreeSet(java.util.TreeSet) LowLevelCAS(org.apache.uima.cas.impl.LowLevelCAS)

Example 7 with LowLevelCAS

use of org.apache.uima.cas.impl.LowLevelCAS in project webanno by webanno.

the class CasDoctorUtils method getNonIndexedFSesWithOwner.

public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas) {
    TypeSystem ts = aCas.getTypeSystem();
    LowLevelCAS llcas = aCas.getLowLevelCAS();
    Set<FeatureStructure> allIndexedFS = collectIndexed(aCas);
    Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>(Comparator.comparingInt(llcas::ll_getFSRef));
    FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS(aCas.getTypeSystem().getTopType());
    i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs));
    // Remove all that are not annotations
    allReachableFS.entrySet().removeIf(e -> !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType()));
    // Remove all that are indexed
    allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue());
    // All that is left are non-index annotations
    return allReachableFS;
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) TypeSystem(org.apache.uima.cas.TypeSystem) TreeMap(java.util.TreeMap) LowLevelCAS(org.apache.uima.cas.impl.LowLevelCAS)

Example 8 with LowLevelCAS

use of org.apache.uima.cas.impl.LowLevelCAS in project webanno by webanno.

the class WebannoTsv2Writer method setTokenAnnos.

private void setTokenAnnos(CAS aCas, Map<Integer, String> aTokenAnnoMap, Type aType, Feature aFeature) {
    LowLevelCAS llCas = aCas.getLowLevelCAS();
    for (AnnotationFS annoFs : CasUtil.select(aCas, aType)) {
        boolean first = true;
        // exists previous annotation, place-holed O-_ should be kept
        boolean previous = false;
        for (Token token : selectCovered(Token.class, annoFs)) {
            if (annoFs.getBegin() <= token.getBegin() && annoFs.getEnd() >= token.getEnd()) {
                String annotation = annoFs.getFeatureValueAsString(aFeature);
                if (annotation == null) {
                    annotation = aType.getName() + "_";
                }
                if (aTokenAnnoMap.get(llCas.ll_getFSRef(token)) == null) {
                    if (previous) {
                        if (!multipleSpans.contains(aType.getName())) {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), annotation);
                        } else {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), "O-_|" + (first ? "B-" : "I-") + annotation);
                            first = false;
                        }
                    } else {
                        if (!multipleSpans.contains(aType.getName())) {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), annotation);
                        } else {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), (first ? "B-" : "I-") + annotation);
                            first = false;
                        }
                    }
                } else {
                    if (!multipleSpans.contains(aType.getName())) {
                        aTokenAnnoMap.put(llCas.ll_getFSRef(token), aTokenAnnoMap.get(llCas.ll_getFSRef(token)) + "|" + annotation);
                        previous = true;
                    } else {
                        aTokenAnnoMap.put(llCas.ll_getFSRef(token), aTokenAnnoMap.get(llCas.ll_getFSRef(token)) + "|" + (first ? "B-" : "I-") + annotation);
                        first = false;
                        previous = true;
                    }
                }
            }
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) LowLevelCAS(org.apache.uima.cas.impl.LowLevelCAS)

Aggregations

LowLevelCAS (org.apache.uima.cas.impl.LowLevelCAS)8 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)5 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 Feature (org.apache.uima.cas.Feature)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 CoreferenceLink (de.tudarmstadt.ukp.dkpro.core.api.coref.type.CoreferenceLink)1 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)1 DocumentMetaData (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)1 TagsetDescription (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.TagsetDescription)1 Dependency (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 Type (org.apache.uima.cas.Type)1 TypeSystem (org.apache.uima.cas.TypeSystem)1