Search in sources :

Example 1 with RelationType

use of de.tudarmstadt.ukp.clarin.webanno.brat.render.model.RelationType in project webanno by webanno.

the class BratRenderer method buildEntityTypes.

/**
 * Generates brat type definitions from the WebAnno layer definitions.
 *
 * @param aAnnotationLayers
 *            the layers
 * @param aAnnotationService
 *            the annotation service
 * @return the brat type definitions
 */
public static Set<EntityType> buildEntityTypes(List<AnnotationLayer> aAnnotationLayers, AnnotationSchemaService aAnnotationService) {
    // Sort layers
    List<AnnotationLayer> layers = new ArrayList<>(aAnnotationLayers);
    layers.sort(Comparator.comparing(AnnotationLayer::getName));
    // Now build the actual configuration
    Set<EntityType> entityTypes = new LinkedHashSet<>();
    for (AnnotationLayer layer : layers) {
        EntityType entityType = configureEntityType(layer);
        List<RelationType> arcs = new ArrayList<>();
        // For link features, we also need to configure the arcs, even though there is no arc
        // layer here.
        boolean hasLinkFeatures = false;
        for (AnnotationFeature f : aAnnotationService.listAnnotationFeature(layer)) {
            if (!LinkMode.NONE.equals(f.getLinkMode())) {
                hasLinkFeatures = true;
                break;
            }
        }
        if (hasLinkFeatures) {
            String bratTypeName = getBratTypeName(layer);
            arcs.add(new RelationType(layer.getName(), layer.getUiName(), bratTypeName, bratTypeName, null, "triangle,5", "3,3"));
        }
        // Styles for the remaining relation and chain layers
        for (AnnotationLayer attachingLayer : getAttachingLayers(layer, layers, aAnnotationService)) {
            arcs.add(configureRelationType(layer, attachingLayer));
        }
        entityType.setArcs(arcs);
        entityTypes.add(entityType);
    }
    return entityTypes;
}
Also used : EntityType(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.EntityType) LinkedHashSet(java.util.LinkedHashSet) RelationType(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.RelationType) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

EntityType (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.EntityType)1 RelationType (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.RelationType)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1