Search in sources :

Example 1 with Renderer

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.Renderer in project webanno by webanno.

the class AttachedAnnotationListPanel method getRelationInfo.

private List<AttachedAnnotationInfo> getRelationInfo() {
    Selection selection = getModelObject().getSelection();
    if (!selection.isSet() || selection.getAnnotation().getId() == NONE) {
        return Collections.emptyList();
    }
    CAS cas;
    try {
        cas = page.getEditorCas();
    } catch (IOException e) {
        // If we have trouble accessing the CAS, we probably never get here anyway...
        // the AnnotationPageBase should already have found the issue and displayed some
        // error to the user.
        LOG.error("Unable to access editor CAS", e);
        return Collections.emptyList();
    }
    AnnotationFS annoFs = selectAnnotationByAddr(cas, selection.getAnnotation().getId());
    VID localVid = new VID(annoFs);
    List<AttachedAnnotation> attachedAnnotations = new ArrayList<>();
    attachedAnnotations.addAll(schemaService.getAttachedRels(getModelObject().getSelectedAnnotationLayer(), annoFs));
    attachedAnnotations.addAll(schemaService.getAttachedLinks(getModelObject().getSelectedAnnotationLayer(), annoFs));
    Map<AnnotationLayer, List<AnnotationFeature>> featureCache = new HashMap<>();
    Map<AnnotationLayer, Renderer> rendererCache = new HashMap<>();
    Map<AnnotationLayer, TypeAdapter> adapterCache = new HashMap<>();
    List<AttachedAnnotationInfo> result = new ArrayList<>();
    for (AttachedAnnotation rel : attachedAnnotations) {
        AnnotationLayer layer = rel.getLayer();
        List<AnnotationFeature> features = featureCache.get(layer);
        TypeAdapter adapter;
        Renderer renderer;
        if (features == null) {
            features = schemaService.listSupportedFeatures(layer);
            featureCache.put(layer, features);
            adapter = schemaService.getAdapter(layer);
            adapterCache.put(layer, adapter);
            renderer = layerRegistry.getLayerSupport(layer).createRenderer(layer, () -> featureCache.get(layer));
            rendererCache.put(layer, renderer);
        } else {
            adapter = adapterCache.get(layer);
            renderer = rendererCache.get(layer);
        }
        Map<String, String> renderedFeatures;
        if (rel.getRelation() != null) {
            renderedFeatures = renderer.renderLabelFeatureValues(adapter, rel.getRelation(), features);
        } else {
            renderedFeatures = renderer.renderLabelFeatureValues(adapter, rel.getEndpoint(), features);
        }
        String labelText = TypeUtil.getUiLabelText(adapter, renderedFeatures);
        if (isEmpty(labelText)) {
            labelText = rel.getLayer().getUiName();
        } else {
            labelText = rel.getLayer().getUiName() + ": " + labelText;
        }
        AttachedAnnotationInfo i = new AttachedAnnotationInfo(layer, localVid, rel.getRelation() != null ? new VID(rel.getRelation()) : null, new VID(rel.getEndpoint()), labelText, rel.getEndpoint().getCoveredText(), rel.getDirection());
        result.add(i);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) CAS(org.apache.uima.cas.CAS) Renderer(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.Renderer) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AttachedAnnotation(de.tudarmstadt.ukp.clarin.webanno.api.AttachedAnnotation) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

AttachedAnnotation (de.tudarmstadt.ukp.clarin.webanno.api.AttachedAnnotation)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 Renderer (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.Renderer)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CAS (org.apache.uima.cas.CAS)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1