Search in sources :

Example 6 with CasUtil.getType

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringTokenizer(java.util.StringTokenizer) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) IOException(java.io.IOException) Feature(org.apache.uima.cas.Feature)

Aggregations

Type (org.apache.uima.cas.Type)6 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)6 Feature (org.apache.uima.cas.Feature)5 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)5 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)4 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 SpanCreatedEvent (de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.SpanCreatedEvent)1 SpanDeletedEvent (de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.SpanDeletedEvent)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1