PlainTextWriter extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { String id = new File(ViewUriUtil.getURI(jCas)).getName(); File outFile = new File(this.outputDirectory, id + ".txt"); try { FileUtils.saveString2File(jCas.getDocumentText(), outFile); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }  @Override void initialize(UimaContext context); @Override void process(JCas jCas); void setOutputDirectoryName(String outputDirectoryName); static final String PARAM_OUTPUT_DIRECTORY_NAME; }
@Test public void test() throws Exception { try { AnalysisEngineFactory.createEngine(PlainTextWriter.class); Assert.fail("expected exception with output directory not specified"); } catch (ResourceInitializationException e) { } AnalysisEngine engine = AnalysisEngineFactory.createEngine( PlainTextWriter.class, PlainTextWriter.PARAM_OUTPUT_DIRECTORY_NAME, this.outputDirectory.getPath()); String text = "What if we built a large\r\n, wooden badger?"; tokenBuilder.buildTokens( jCas, text, "What if we built a large \n, wooden badger ?", "WDT TO PRP VBN DT JJ , JJ NN ."); ViewUriUtil.setURI(jCas, new File("identifier").toURI()); engine.process(jCas); engine.collectionProcessComplete(); File outputFile = new File(this.outputDirectory, "identifier.txt"); String actualText = FileUtils.file2String(outputFile); Assert.assertEquals(text, actualText); jCas.reset(); text = "What if we built a large\n, wooden badger?"; tokenBuilder.buildTokens( jCas, text, "What if we built a large \n, wooden badger ?", "WDT TO PRP VBN DT JJ , JJ NN ."); ViewUriUtil.setURI(jCas, new File("1234").toURI()); engine.process(jCas); engine.collectionProcessComplete(); outputFile = new File(this.outputDirectory, "1234.txt"); actualText = FileUtils.file2String(outputFile); Assert.assertEquals(text, actualText); }