use of de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse in project webanno by webanno.
the class SuggestionViewPanel method render.
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, aJcas, layersToRender);
GetDocumentResponse response = new GetDocumentResponse();
BratRenderer.render(response, aBratAnnotatorModel, vdoc, aJcas, annotationService, aCurationColoringStrategy);
return JSONUtil.toInterpretableJsonString(response);
}
use of de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse in project webanno by webanno.
the class BratAnnotationEditor method actionGetDocument.
private String actionGetDocument(JCas jCas) {
StopWatch timer = new StopWatch();
timer.start();
GetDocumentResponse response = new GetDocumentResponse();
String json;
if (getModelObject().getProject() != null) {
render(response, jCas);
json = toJson(response);
lastRenderedJson = json;
} else {
json = toJson(response);
}
timer.stop();
metrics.renderComplete(RenderType.FULL, timer.getTime(), json, null);
return json;
}
use of de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse in project webanno by webanno.
the class BratAnnotationEditor method bratRenderCommand.
private String bratRenderCommand(JCas aJCas) {
StopWatch timer = new StopWatch();
timer.start();
GetDocumentResponse response = new GetDocumentResponse();
render(response, aJCas);
String json = toJson(response);
// By default, we do a full rendering...
RenderType renderType = RenderType.FULL;
String cmd = "renderData";
String data = json;
// ... try to render diff
String diff = null;
JsonNode current = null;
JsonNode previous = null;
try {
ObjectMapper mapper = JSONUtil.getJsonConverter().getObjectMapper();
current = mapper.readTree(json);
previous = lastRenderedJson != null ? mapper.readTree(lastRenderedJson) : null;
} catch (IOException e) {
LOG.error("Unable to generate diff, falling back to full render.", e);
// Fall-through
}
if (previous != null && current != null) {
diff = JsonDiff.asJson(previous, current).toString();
// pages, the patch usually ends up being twice as large as the full data.
if (diff.length() < json.length()) {
cmd = "renderDataPatch";
data = diff;
renderType = RenderType.DIFFERENTIAL;
}
// LOG.info("Diff: " + diff);
// LOG.info("Full: {} Patch: {} Diff time: {}", json.length(), diff.length(), timer);
}
// Storing the last rendered JSON as string because JsonNodes are not serializable.
lastRenderedJson = json;
timer.stop();
metrics.renderComplete(renderType, timer.getTime(), json, diff);
return "Wicket.$('" + vis.getMarkupId() + "').dispatcher.post('" + cmd + "', [" + data + "]);";
}
use of de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse in project webanno by webanno.
the class CasToBratJsonTest method testGenerateBratJsonGetDocument.
/**
* generate brat JSON data for the document
*/
@Test
public void testGenerateBratJsonGetDocument() throws Exception {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
String jsonFilePath = "target/test-output/output_cas_to_json_document.json";
String file = "src/test/resources/tcf04-karin-wl.xml";
CAS cas = JCasFactory.createJCas().getCas();
CollectionReader reader = CollectionReaderFactory.createReader(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, file);
reader.getNext(cas);
JCas jCas = cas.getJCas();
AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
state.getPreferences().setWindowSize(10);
state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(jCas));
state.setProject(project);
VDocument vdoc = new VDocument();
preRenderer.render(vdoc, state, jCas, annotationSchemaService.listAnnotationLayer(project));
GetDocumentResponse response = new GetDocumentResponse();
BratRenderer.render(response, state, vdoc, jCas, annotationSchemaService);
JSONUtil.generatePrettyJson(jsonConverter, response, new File(jsonFilePath));
assertThat(linesOf(new File("src/test/resources/output_cas_to_json_document_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Aggregations