ExamplePosPlainTextWriter extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { String id = new File(ViewUriUtil.getURI(jCas)).getName(); PrintWriter outputWriter; try { outputWriter = new PrintWriter(new File(this.outputDir, id + ".pos")); } catch (FileNotFoundException e) { throw new AnalysisEngineProcessException(e); } for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) { for (Token token : JCasUtil.selectCovered(jCas, Token.class, sentence)) { outputWriter.print(token.getCoveredText()); outputWriter.print('/'); outputWriter.print(token.getPos()); outputWriter.print(' '); } outputWriter.println(); } outputWriter.close(); }  @Override void initialize(UimaContext context); @Override void process(JCas jCas); void setOutputDirectoryName(String outputDirectoryName); static final String DEFAULT_OUTPUT_DIRECTORY; static final String PARAM_OUTPUT_DIRECTORY_NAME; }
@Test public void test() throws Exception { AnalysisEngine engine = AnalysisEngineFactory.createEngine( ExamplePosPlainTextWriter.class, ExamplePosPlainTextWriter.PARAM_OUTPUT_DIRECTORY_NAME, this.outputDirectory.getPath()); tokenBuilder.buildTokens( jCas, "I walked home. It was a nice day!", "I walked home .\nIt was a nice day !", "PRP VBD NN . PRP VBD DT JJ NN ."); ViewUriUtil.setURI(jCas, new File("xxx").toURI()); engine.process(jCas); engine.collectionProcessComplete(); String text = "I/PRP walked/VBD home/NN ./. \nIt/PRP was/VBD a/DT nice/JJ day/NN !/. \n"; File outputFile = new File(this.outputDirectory, "xxx.pos"); Assert.assertEquals(text, FileUtils.file2String(outputFile).replace("\r", "")); }