Search in sources :

Example 1 with BratRenderer

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

the class BratAnnotationEditor method render.

private void render(GetDocumentResponse response, CAS aCas) {
    AnnotatorState aState = getModelObject();
    VDocument vdoc = render(aCas, aState.getWindowBeginOffset(), aState.getWindowEndOffset());
    BratRenderer renderer = new BratRenderer(annotationService, coloringService);
    renderer.render(response, aState, vdoc, aCas);
}
Also used : BratRenderer(de.tudarmstadt.ukp.clarin.webanno.brat.render.BratRenderer) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Example 2 with BratRenderer

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

the class BratRendererTest method thatSentenceOrientedStrategyRenderCorrectly.

@Test
public void thatSentenceOrientedStrategyRenderCorrectly() throws Exception {
    String jsonFilePath = "target/test-output/output-sentence-oriented.json";
    String file = "src/test/resources/tcf04-karin-wl.xml";
    CAS cas = JCasFactory.createJCas().getCas();
    CollectionReader reader = createReader(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, file);
    reader.getNext(cas);
    AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
    state.setAllAnnotationLayers(schemaService.listAnnotationLayer(project));
    state.setPagingStrategy(new SentenceOrientedPagingStrategy());
    state.getPreferences().setWindowSize(10);
    state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(cas));
    state.setProject(project);
    VDocument vdoc = new VDocument();
    preRenderer.render(vdoc, state.getWindowBeginOffset(), state.getWindowEndOffset(), cas, schemaService.listAnnotationLayer(project));
    GetDocumentResponse response = new GetDocumentResponse();
    BratRenderer renderer = new BratRenderer(schemaService, new ColoringServiceImpl(schemaService));
    renderer.render(response, state, vdoc, cas);
    JSONUtil.generatePrettyJson(response, new File(jsonFilePath));
    assertThat(contentOf(new File("src/test/resources/output-sentence-oriented.json"), UTF_8)).isEqualToNormalizingNewlines(contentOf(new File(jsonFilePath), UTF_8));
}
Also used : BratRenderer(de.tudarmstadt.ukp.clarin.webanno.brat.render.BratRenderer) CollectionReader(org.apache.uima.collection.CollectionReader) CAS(org.apache.uima.cas.CAS) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) File(java.io.File) ColoringServiceImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringServiceImpl) SentenceOrientedPagingStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy) Test(org.junit.Test)

Example 3 with BratRenderer

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

the class BratRendererTest method thatLineOrientedStrategyRenderCorrectly.

/**
 * generate brat JSON data for the document
 */
@Test
public void thatLineOrientedStrategyRenderCorrectly() throws Exception {
    String jsonFilePath = "target/test-output/multiline.json";
    String file = "src/test/resources/multiline.txt";
    CAS cas = JCasFactory.createJCas().getCas();
    CollectionReader reader = createReader(TextReader.class, TextReader.PARAM_SOURCE_LOCATION, file);
    reader.getNext(cas);
    AnalysisEngine segmenter = createEngine(BreakIteratorSegmenter.class);
    segmenter.process(cas);
    AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
    state.setPagingStrategy(new LineOrientedPagingStrategy());
    state.getPreferences().setWindowSize(10);
    state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(cas));
    state.setProject(project);
    VDocument vdoc = new VDocument();
    preRenderer.render(vdoc, state.getWindowBeginOffset(), state.getWindowEndOffset(), cas, schemaService.listAnnotationLayer(project));
    GetDocumentResponse response = new GetDocumentResponse();
    BratRenderer renderer = new BratRenderer(schemaService, new ColoringServiceImpl(schemaService));
    renderer.render(response, state, vdoc, cas);
    JSONUtil.generatePrettyJson(response, new File(jsonFilePath));
    assertThat(contentOf(new File("src/test/resources/multiline.json"), UTF_8)).isEqualToNormalizingNewlines(contentOf(new File(jsonFilePath), UTF_8));
}
Also used : BratRenderer(de.tudarmstadt.ukp.clarin.webanno.brat.render.BratRenderer) CollectionReader(org.apache.uima.collection.CollectionReader) CAS(org.apache.uima.cas.CAS) LineOrientedPagingStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.LineOrientedPagingStrategy) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) File(java.io.File) ColoringServiceImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringServiceImpl) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine) Test(org.junit.Test)

Example 4 with BratRenderer

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

the class SuggestionViewPanel method render.

private String render(CAS aCas, 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(), aCas, layersToRender);
    GetDocumentResponse response = new GetDocumentResponse();
    BratRenderer renderer = new BratRenderer(schemaService, coloringService);
    renderer.render(response, aBratAnnotatorModel, vdoc, aCas, aCurationColoringStrategy);
    return JSONUtil.toInterpretableJsonString(response);
}
Also used : BratRenderer(de.tudarmstadt.ukp.clarin.webanno.brat.render.BratRenderer) GetDocumentResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Aggregations

VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)4 BratRenderer (de.tudarmstadt.ukp.clarin.webanno.brat.render.BratRenderer)4 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 ColoringServiceImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringServiceImpl)2 AnnotatorStateImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl)2 File (java.io.File)2 CAS (org.apache.uima.cas.CAS)2 CollectionReader (org.apache.uima.collection.CollectionReader)2 Test (org.junit.Test)2 LineOrientedPagingStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.LineOrientedPagingStrategy)1 SentenceOrientedPagingStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy)1 GetDocumentResponse (de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 ArrayList (java.util.ArrayList)1 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)1