use of eu.clarin.weblicht.wlfxb.tc.xb.TextCorpusStored in project webanno by webanno.
the class TcfWriter method casToTcfWriter.
/**
* Create TCF File from scratch
*
* @param aJCas
* the JCas.
* @param aOs
* the output stream.
* @throws WLFormatException
* if a TCF problem occurs.
*/
public void casToTcfWriter(JCas aJCas, OutputStream aOs) throws WLFormatException {
// create TextCorpus object, specifying its language from the aJcas Object
TextCorpusStored textCorpus = new TextCorpusStored(aJCas.getDocumentLanguage());
// create text annotation layer and add the string of the text into the layer
textCorpus.createTextLayer().addText(aJCas.getDocumentText());
write(aJCas, textCorpus);
// write the annotated data object into the output stream
WLData wldata = new WLData(textCorpus);
WLDObjector.write(wldata, aOs);
}
use of eu.clarin.weblicht.wlfxb.tc.xb.TextCorpusStored in project webanno by webanno.
the class TcfReaderWriterTest method testOneWay.
public void testOneWay(String aInputFile, String aExpectedFile) throws Exception {
CollectionReaderDescription reader = createReaderDescription(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, "src/test/resources/", TcfReader.PARAM_PATTERNS, aInputFile);
AnalysisEngineDescription writer = createEngineDescription(TcfWriter.class, TcfWriter.PARAM_TARGET_LOCATION, "target/test-output/oneway", TcfWriter.PARAM_FILENAME_SUFFIX, ".xml", TcfWriter.PARAM_STRIP_EXTENSION, true);
AnalysisEngineDescription dumper = createEngineDescription(CasDumpWriter.class, CasDumpWriter.PARAM_OUTPUT_FILE, "target/test-output/oneway/dump.txt");
runPipeline(reader, writer, dumper);
InputStream isReference = new FileInputStream(new File("src/test/resources/" + aExpectedFile));
InputStream isActual = new FileInputStream(new File("target/test-output/oneway/" + aInputFile));
WLData wLDataReference = WLDObjector.read(isReference);
TextCorpusStored aCorpusDataReference = wLDataReference.getTextCorpus();
WLData wLDataActual = WLDObjector.read(isActual);
TextCorpusStored aCorpusDataActual = wLDataActual.getTextCorpus();
// check if layers maintained
assertEquals(aCorpusDataReference.getLayers().size(), aCorpusDataActual.getLayers().size());
// Check if every layers have the same number of annotations
for (TextCorpusLayer layer : aCorpusDataReference.getLayers()) {
assertEquals("Layer size mismatch in [" + layer.getClass().getName() + "]", layer.size(), getLayer(aCorpusDataActual, layer.getClass()).size());
}
XMLAssert.assertXMLEqual(new InputSource("src/test/resources/" + aExpectedFile), new InputSource(new File("target/test-output/oneway/" + aInputFile).getPath()));
}
Aggregations