use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSentenceMarker 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 + "]");
}
}
}
Aggregations