Search in sources :

Example 1 with SentenceComment

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

the class BratRenderer method render.

/**
 * wrap JSON responses to BRAT visualizer
 *
 * @param aResponse
 *            the response.
 * @param aState
 *            the annotator model.
 * @param aJCas
 *            the JCas.
 * @param aAnnotationService
 *            the annotation service.s
 */
public static void render(GetDocumentResponse aResponse, AnnotatorState aState, VDocument aVDoc, JCas aJCas, AnnotationSchemaService aAnnotationService, ColoringStrategy aColoringStrategy) {
    aResponse.setRtlMode(ScriptDirection.RTL.equals(aState.getScriptDirection()));
    aResponse.setFontZoom(aState.getPreferences().getFontZoom());
    // Render invisible baseline annotations (sentence, tokens)
    renderTokenAndSentence(aJCas, aResponse, aState);
    // Render visible (custom) layers
    Map<String[], Queue<String>> colorQueues = new HashMap<>();
    for (AnnotationLayer layer : aVDoc.getAnnotationLayers()) {
        ColoringStrategy coloringStrategy = aColoringStrategy != null ? aColoringStrategy : ColoringStrategy.getStrategy(aAnnotationService, layer, aState.getPreferences(), colorQueues);
        TypeAdapter typeAdapter = aAnnotationService.getAdapter(layer);
        for (VSpan vspan : aVDoc.spans(layer.getId())) {
            List<Offsets> offsets = toOffsets(vspan.getRanges());
            String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures());
            String bratHoverText = TypeUtil.getUiHoverText(typeAdapter, vspan.getHoverFeatures());
            String color;
            if (vspan.getColorHint() == null) {
                color = getColor(vspan, coloringStrategy, bratLabelText);
            } else {
                color = vspan.getColorHint();
            }
            aResponse.addEntity(new Entity(vspan.getVid(), vspan.getType(), offsets, bratLabelText, color, bratHoverText));
        }
        for (VArc varc : aVDoc.arcs(layer.getId())) {
            String bratLabelText;
            if (varc.getLabelHint() == null) {
                bratLabelText = TypeUtil.getUiLabelText(typeAdapter, varc.getFeatures());
            } else {
                bratLabelText = varc.getLabelHint();
            }
            String color;
            if (varc.getColorHint() == null) {
                color = getColor(varc, coloringStrategy, bratLabelText);
            } else {
                color = varc.getColorHint();
            }
            aResponse.addRelation(new Relation(varc.getVid(), varc.getType(), getArgument(varc.getSource(), varc.getTarget()), bratLabelText, color));
        }
    }
    List<Sentence> sentences = new ArrayList<>(select(aJCas, Sentence.class));
    for (VComment vcomment : aVDoc.comments()) {
        String type;
        switch(vcomment.getCommentType()) {
            case ERROR:
                type = AnnotationComment.ANNOTATION_ERROR;
                break;
            case INFO:
                type = AnnotationComment.ANNOTATOR_NOTES;
                break;
            case YIELD:
                type = "Yield";
                break;
            default:
                type = AnnotationComment.ANNOTATOR_NOTES;
                break;
        }
        AnnotationFS fs;
        if (!vcomment.getVid().isSynthetic() && ((fs = selectByAddr(aJCas, vcomment.getVid().getId())) instanceof Sentence)) {
            int index = sentences.indexOf(fs) + 1;
            aResponse.addComment(new SentenceComment(index, type, vcomment.getComment()));
        } else {
            aResponse.addComment(new AnnotationComment(vcomment.getVid(), type, vcomment.getComment()));
        }
    }
    // Render markers
    for (VMarker vmarker : aVDoc.getMarkers()) {
        if (vmarker instanceof VAnnotationMarker) {
            VAnnotationMarker marker = (VAnnotationMarker) vmarker;
            aResponse.addMarker(new AnnotationMarker(vmarker.getType(), marker.getVid()));
        } else if (vmarker instanceof VSentenceMarker) {
            VSentenceMarker marker = (VSentenceMarker) vmarker;
            aResponse.addMarker(new SentenceMarker(vmarker.getType(), marker.getIndex()));
        } else if (vmarker instanceof VTextMarker) {
            VTextMarker marker = (VTextMarker) vmarker;
            aResponse.addMarker(new TextMarker(marker.getType(), marker.getBegin(), marker.getEnd()));
        } else {
            LOG.warn("Unknown how to render marker: [" + vmarker + "]");
        }
    }
}
Also used : Entity(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Entity) VAnnotationMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker) VTextMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VTextMarker) HashMap(java.util.HashMap) AnnotationMarker(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.AnnotationMarker) VAnnotationMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker) ArrayList(java.util.ArrayList) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Offsets(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Offsets) TextMarker(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.TextMarker) VTextMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VTextMarker) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) VSentenceMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSentenceMarker) SentenceMarker(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.SentenceMarker) Relation(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Relation) Queue(java.util.Queue) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) AnnotationComment(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.AnnotationComment) VSentenceMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSentenceMarker) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SentenceComment(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.SentenceComment) VMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VMarker)

Aggregations

TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 ColoringStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy)1 VAnnotationMarker (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1 VMarker (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VMarker)1 VSentenceMarker (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSentenceMarker)1 VSpan (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan)1 VTextMarker (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VTextMarker)1 AnnotationComment (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.AnnotationComment)1 AnnotationMarker (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.AnnotationMarker)1 Entity (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Entity)1 Offsets (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Offsets)1 Relation (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Relation)1 SentenceComment (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.SentenceComment)1 SentenceMarker (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.SentenceMarker)1 TextMarker (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.TextMarker)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)1 ArrayList (java.util.ArrayList)1