Search in sources :

Example 6 with VDocument

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument 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"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) CollectionReader(org.apache.uima.collection.CollectionReader) GetDocumentResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse) 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) JCas(org.apache.uima.jcas.JCas) File(java.io.File) Test(org.junit.Test)

Aggregations

VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)6 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)5 JCas (org.apache.uima.jcas.JCas)4 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)3 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)3 TypeUtil (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil)3 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 Type (org.apache.uima.cas.Type)3 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)3 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)2 VRange (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange)2 VSpan (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan)2 WebAnnoCasUtil.selectByAddr (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr)2 GetDocumentResponse (de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse)2 Map (java.util.Map)2 Feature (org.apache.uima.cas.Feature)2