use of org.apache.uima.fit.util.CasUtil.getType in project webanno by webanno.
the class WebannoTsv2Reader method getLayerAndFeature.
private int getLayerAndFeature(JCas aJcas, int columns, Map<Type, Set<Feature>> spanLayers, Map<Type, Type> relationayers, String line) throws IOException {
StringTokenizer headerTk = new StringTokenizer(line, "#");
while (headerTk.hasMoreTokens()) {
String layerNames = headerTk.nextToken().trim();
StringTokenizer layerTk = new StringTokenizer(layerNames, "|");
Set<Feature> features = new LinkedHashSet<>();
String layerName = layerTk.nextToken().trim();
Iterator<Type> types = aJcas.getTypeSystem().getTypeIterator();
boolean layerExists = false;
while (types.hasNext()) {
if (types.next().getName().equals(layerName)) {
layerExists = true;
break;
}
}
if (!layerExists) {
throw new IOException(fileName + " This is not a valid TSV File. The layer " + layerName + " is not created in the project.");
}
Type layer = CasUtil.getType(aJcas.getCas(), layerName);
while (layerTk.hasMoreTokens()) {
String ft = layerTk.nextToken().trim();
if (ft.startsWith("AttachTo=")) {
Type attachLayer = CasUtil.getType(aJcas.getCas(), ft.substring(9));
relationayers.put(layer, attachLayer);
columns++;
continue;
}
Feature feature = layer.getFeatureByBaseName(ft);
if (feature == null) {
throw new IOException(fileName + " This is not a valid TSV File. The feature " + ft + " is not created for the layer " + layerName);
}
features.add(feature);
columns++;
}
spanLayers.put(layer, features);
}
return columns;
}
Aggregations