private String render(JCas aJcas, AnnotatorState aBratAnnotatorModel, ColoringStrategy aCurationColoringStrategy) throws IOException { List<AnnotationLayer> layersToRender = new ArrayList<>(); for (AnnotationLayer layer : aBratAnnotatorModel.getAnnotationLayers()) { boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName()); boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE); if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) { layersToRender.add(layer); } } VDocument vdoc = new VDocument(); preRenderer.render(vdoc, aBratAnnotatorModel.getWindowBeginOffset(), aBratAnnotatorModel.getWindowEndOffset(), aJcas, layersToRender); GetDocumentResponse response = new GetDocumentResponse(); BratRenderer.render(response, aBratAnnotatorModel, vdoc, aJcas, annotationService, aCurationColoringStrategy); return JSONUtil.toInterpretableJsonString(response); }
@Override public void onRender(TypeAdapter aAdapter, VDocument aResponse, Map<AnnotationFS, VSpan> annoToSpanIdx) { if (aAdapter.getLayer().isCrossSentence()) { return; } // Since we split spans into multiple ranges at sentence boundaries, we can simply check // if there are multiple ranges for a given span. This is cheaper than checking for // every annotation whether the begin/end offset is in the same sentence. for (Entry<AnnotationFS, VSpan> e : annoToSpanIdx.entrySet()) { if (e.getValue().getRanges().size() > 1) { aResponse.add(new VComment(new VID(e.getKey()), ERROR, "Crossing sentence bounardies is not permitted.")); } } }
aVDoc.getMarkers().removeIf(marker -> marker.getSource() == this); aVDoc.add(new VAnnotationMarker(this, VMarker.FOCUS, highlightVID)); if (state.getWindowBeginOffset() <= highlightSpan.getBegin() && highlightSpan.getEnd() <= state.getWindowEndOffset()) { aVDoc.add(new VTextMarker(this, VMarker.FOCUS, highlightSpan.getBegin() - state.getWindowBeginOffset(), highlightSpan.getEnd() - state.getWindowBeginOffset()));
if (!aVDoc.getAnnotationLayers().contains(layer)) { continue; for (VSpan vspan : aVDoc.spans(layer.getId())) { List<Offsets> offsets = toOffsets(vspan.getRanges()); String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures()); for (VArc varc : aVDoc.arcs(layer.getId())) { String bratLabelText; if (varc.getLabelHint() == null) { for (VComment vcomment : aVDoc.comments()) { String type; switch (vcomment.getCommentType()) { for (VMarker vmarker : aVDoc.getMarkers()) { if (vmarker instanceof VAnnotationMarker) { VAnnotationMarker marker = (VAnnotationMarker) vmarker;
JCas jcas = getJCasProvider().get(); VDocument vdoc = new VDocument(); preRenderer.render(vdoc, aState.getWindowBeginOffset(), aState.getWindowEndOffset(), jcas, getLayersToRender()); for (AnnotationLayer layer : vdoc.getAnnotationLayers()) { for (VSpan vspan : vdoc.spans(layer.getId())) { String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures());
if (!aVDoc.getAnnotationLayers().contains(layer)) { continue; for (VSpan vspan : aVDoc.spans(layer.getId())) { String labelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures()); String color; for (VArc varc : aVDoc.arcs(layer.getId())) { String labelText; if (varc.getLabelHint() == null) {
if (!aVDoc.getAnnotationLayers().contains(layer)) { continue; for (VSpan vspan : aVDoc.spans(layer.getId())) { List<Offsets> offsets = toOffsets(vspan.getRanges()); String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures()); for (VArc varc : aVDoc.arcs(layer.getId())) { String bratLabelText; if (varc.getLabelHint() == null) { for (VComment vcomment : aVDoc.comments()) { String type; switch (vcomment.getCommentType()) { for (VMarker vmarker : aVDoc.getMarkers()) { if (vmarker instanceof VAnnotationMarker) { VAnnotationMarker marker = (VAnnotationMarker) vmarker;
JCas jcas = getJCasProvider().get(); VDocument vdoc = new VDocument(); preRenderer.render(vdoc, aState.getWindowBeginOffset(), aState.getWindowEndOffset(), jcas, getLayersToRender()); for (AnnotationLayer layer : vdoc.getAnnotationLayers()) { for (VSpan vspan : vdoc.spans(layer.getId())) { String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures());
@Test public void thatSpanCrossSentenceBehaviorOnRenderGeneratesErrors() { neLayer.setCrossSentence(false); jcas.setDocumentText(StringUtils.repeat("a", 20)); new Sentence(jcas, 0, 10).addToIndexes(); new Sentence(jcas, 10, 20).addToIndexes(); NamedEntity ne = new NamedEntity(jcas, 5, 15); ne.addToIndexes(); SpanAdapter adapter = new SpanAdapter(featureSupportRegistry, null, neLayer, asList(), asList(new SpanCrossSentenceBehavior())); SpanRenderer sut = new SpanRenderer(adapter, featureSupportRegistry, asList(new SpanCrossSentenceBehavior())); VDocument vdoc = new VDocument(); sut.render(jcas, asList(), vdoc, 0, jcas.getDocumentText().length()); assertThat(vdoc.comments()) .usingFieldByFieldElementComparator() .containsExactlyInAnyOrder(new VComment(ne, VCommentType.ERROR, "Crossing sentence bounardies is not permitted.")); }
if (!aVDoc.getAnnotationLayers().contains(layer)) { continue; for (VSpan vspan : aVDoc.spans(layer.getId())) { String labelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures()); String color; for (VArc varc : aVDoc.arcs(layer.getId())) { String labelText; if (varc.getLabelHint() == null) {
@Override public void onRender(TypeAdapter aAdapter, VDocument aResponse, Map<AnnotationFS, VSpan> annoToSpanIdx) { if (aAdapter.getLayer().isCrossSentence()) { return; } // Since we split spans into multiple ranges at sentence boundaries, we can simply check // if there are multiple ranges for a given span. This is cheaper than checking for // every annotation whether the begin/end offset is in the same sentence. for (Entry<AnnotationFS, VSpan> e : annoToSpanIdx.entrySet()) { if (e.getValue().getRanges().size() > 1) { aResponse.add(new VComment(new VID(e.getKey()), ERROR, "Crossing sentence bounardies is not permitted.")); } } }
@Test public void thatSpanStackingBehaviorOnRenderGeneratesErrors() { neLayer.setAllowStacking(false); jcas.setDocumentText(StringUtils.repeat("a", 10)); new Sentence(jcas, 0, 10).addToIndexes(); NamedEntity ne1 = new NamedEntity(jcas, 3, 8); ne1.addToIndexes(); NamedEntity ne2 = new NamedEntity(jcas, 3, 8); ne2.addToIndexes(); SpanAdapter adapter = new SpanAdapter(featureSupportRegistry, null, neLayer, asList(), asList(new SpanStackingBehavior())); SpanRenderer sut = new SpanRenderer(adapter, featureSupportRegistry, asList(new SpanStackingBehavior())); VDocument vdoc = new VDocument(); sut.render(jcas, asList(), vdoc, 0, jcas.getDocumentText().length()); assertThat(vdoc.comments()) .usingFieldByFieldElementComparator() .containsExactlyInAnyOrder( new VComment(ne1, VCommentType.ERROR, "Stacking is not permitted."), new VComment(ne2, VCommentType.ERROR, "Stacking is not permitted.")); } }
aVDoc.getMarkers().removeIf(marker -> marker.getSource() == this); aVDoc.add(new VAnnotationMarker(this, VMarker.FOCUS, highlightVID)); if (state.getWindowBeginOffset() <= highlightSpan.getBegin() && highlightSpan.getEnd() <= state.getWindowEndOffset()) { aVDoc.add(new VTextMarker(this, VMarker.FOCUS, highlightSpan.getBegin() - state.getWindowBeginOffset(), highlightSpan.getEnd() - state.getWindowBeginOffset()));
private String render(JCas aJcas, AnnotatorState aBratAnnotatorModel, ColoringStrategy aCurationColoringStrategy) throws IOException { List<AnnotationLayer> layersToRender = new ArrayList<>(); for (AnnotationLayer layer : aBratAnnotatorModel.getAnnotationLayers()) { boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName()); boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE); if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) { layersToRender.add(layer); } } VDocument vdoc = new VDocument(); preRenderer.render(vdoc, aBratAnnotatorModel.getWindowBeginOffset(), aBratAnnotatorModel.getWindowEndOffset(), aJcas, layersToRender); GetDocumentResponse response = new GetDocumentResponse(); BratRenderer.render(response, aBratAnnotatorModel, vdoc, aJcas, annotationService, aCurationColoringStrategy); return JSONUtil.toInterpretableJsonString(response); }
VDocument vdoc = new VDocument(); preRenderer.render(vdoc, state.getWindowBeginOffset(), state.getWindowEndOffset(), jCas, schemaService.listAnnotationLayer(project));