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;
}
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;
}
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;
}
}
}
}
}
}
Aggregations