Search in sources :

Example 1 with TextCorpusStored

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);
}
Also used : TextCorpusStored(eu.clarin.weblicht.wlfxb.tc.xb.TextCorpusStored) WLData(eu.clarin.weblicht.wlfxb.xb.WLData)

Example 2 with TextCorpusStored

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()));
}
Also used : CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) TextCorpusLayer(eu.clarin.weblicht.wlfxb.tc.api.TextCorpusLayer) InputSource(org.xml.sax.InputSource) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TextCorpusStored(eu.clarin.weblicht.wlfxb.tc.xb.TextCorpusStored) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) WLData(eu.clarin.weblicht.wlfxb.xb.WLData) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

TextCorpusStored (eu.clarin.weblicht.wlfxb.tc.xb.TextCorpusStored)2 WLData (eu.clarin.weblicht.wlfxb.xb.WLData)2 TextCorpusLayer (eu.clarin.weblicht.wlfxb.tc.api.TextCorpusLayer)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)1 CollectionReaderDescription (org.apache.uima.collection.CollectionReaderDescription)1 InputSource (org.xml.sax.InputSource)1