@Test public void testProcessAndSaveDoc() throws UIMAException, IOException { String text = "Title: US Abdomen\n\nDr. Doolitle asked patient\nto take a deep breath\nand exhale slowly. Patient coughed. Prescribed acetominophen"; AnalysisEngine engine = TestUtils.createTokenizerAE(null); JCas jCas = engine.newJCas(); jCas.setDocumentText(text); long key = System.currentTimeMillis(); DocKey docKey = new DocKey(jCas); KeyValuePair kvp = new KeyValuePair(jCas); kvp.setKey("instance_id"); kvp.setValueLong(key); FSArray fsa = new FSArray(jCas, 1); fsa.set(0, kvp); docKey.setKeyValuePairs(fsa); docKey.addToIndexes(); engine.process(jCas); DataSource ds = ctx.getBean(DataSource.class); Properties ytexProperties = (Properties) ctx.getBean("ytexProperties"); String schema = ytexProperties.getProperty("db.schema"); String schemaPrefix = Strings.isNullOrEmpty(schema) ? "" : schema + "."; JdbcTemplate jt = new JdbcTemplate(ds); String query = String.format( "select count(*) from %sdocument where instance_id=%s", schemaPrefix, key); Assert.assertTrue(query, jt.queryForObject(query,Integer.class) == 1); query = String .format("select count(*) from %sdocument d inner join %sanno_base ab on ab.document_id = d.document_id inner join %sanno_segment s on s.anno_base_id = ab.anno_base_id where d.instance_id=%s", schemaPrefix, schemaPrefix, schemaPrefix, key); Assert.assertTrue(query, jt.queryForObject(query,Integer.class) == 1); query = String .format("select count(*) from %sdocument d inner join %sanno_base ab on ab.document_id = d.document_id inner join %sanno_sentence s on s.anno_base_id = ab.anno_base_id where d.instance_id=%s", schemaPrefix, schemaPrefix, schemaPrefix, key); Assert.assertTrue(query, jt.queryForObject(query,Integer.class) > 1); query = String .format("select count(*) from %sdocument d inner join %sanno_base ab on ab.document_id = d.document_id inner join %sanno_token s on s.anno_base_id = ab.anno_base_id where d.instance_id=%s", schemaPrefix, schemaPrefix, schemaPrefix, key); Assert.assertTrue(query, jt.queryForObject(query,Integer.class) > 1); }
@Override public void process(JCas jcas) { Integer documentID = documentMapperService.saveDocument(jcas, analysisBatch, bStoreDocText, bStoreCAS, bInsertAnnotationContainmentLinks, setTypesToIgnore); if (documentID != null && xmiOutputDirectory != null && xmiOutputDirectory.length() > 0) { File dirOut = new File(xmiOutputDirectory); if (!dirOut.exists() && !dirOut.isDirectory()) { log.error(xmiOutputDirectory + " does not exist"); } else { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter( xmiOutputDirectory + File.separatorChar + documentID.toString() + ".xmi")); XmiCasSerializer ser = new XmiCasSerializer( jcas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(writer, false); ser.serialize(jcas.getCas(), xmlSer.getContentHandler()); } catch (IOException e) { log.error("error writing xmi, documentID=" + documentID, e); } catch (SAXException e) { log.error("error writing xmi, documentID=" + documentID, e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } } } }
DBConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) { Integer documentID = documentMapperService.saveDocument(jcas, analysisBatch, bStoreDocText, bStoreCAS, bInsertAnnotationContainmentLinks, setTypesToIgnore); if (documentID != null && xmiOutputDirectory != null && xmiOutputDirectory.length() > 0) { File dirOut = new File(xmiOutputDirectory); if (!dirOut.exists() && !dirOut.isDirectory()) { log.error(xmiOutputDirectory + " does not exist"); } else { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter( xmiOutputDirectory + File.separatorChar + documentID.toString() + ".xmi")); XmiCasSerializer ser = new XmiCasSerializer( jcas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(writer, false); ser.serialize(jcas.getCas(), xmlSer.getContentHandler()); } catch (IOException e) { log.error("error writing xmi, documentID=" + documentID, e); } catch (SAXException e) { log.error("error writing xmi, documentID=" + documentID, e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } } } } }
DBConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) { Integer documentID = documentMapperService.saveDocument(jcas, analysisBatch, bStoreDocText, bStoreCAS, bInsertAnnotationContainmentLinks, setTypesToIgnore); if (documentID != null && xmiOutputDirectory != null && xmiOutputDirectory.length() > 0) { File dirOut = new File(xmiOutputDirectory); if (!dirOut.exists() && !dirOut.isDirectory()) { log.error(xmiOutputDirectory + " does not exist"); } else { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter( xmiOutputDirectory + File.separatorChar + documentID.toString() + ".xmi")); XmiCasSerializer ser = new XmiCasSerializer( jcas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(writer, false); ser.serialize(jcas.getCas(), xmlSer.getContentHandler()); } catch (IOException e) { log.error("error writing xmi, documentID=" + documentID, e); } catch (SAXException e) { log.error("error writing xmi, documentID=" + documentID, e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } } } }  }
DBConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) { Integer documentID = documentMapperService.saveDocument(jcas, analysisBatch, bStoreDocText, bStoreCAS, bInsertAnnotationContainmentLinks, setTypesToIgnore); if (documentID != null && xmiOutputDirectory != null && xmiOutputDirectory.length() > 0) { File dirOut = new File(xmiOutputDirectory); if (!dirOut.exists() && !dirOut.isDirectory()) { log.error(xmiOutputDirectory + " does not exist"); } else { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter( xmiOutputDirectory + File.separatorChar + documentID.toString() + ".xmi")); XmiCasSerializer ser = new XmiCasSerializer( jcas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(writer, false); ser.serialize(jcas.getCas(), xmlSer.getContentHandler()); } catch (IOException e) { log.error("error writing xmi, documentID=" + documentID, e); } catch (SAXException e) { log.error("error writing xmi, documentID=" + documentID, e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); }
DBConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) { Integer documentID = documentMapperService.saveDocument(jcas, analysisBatch, bStoreDocText, bStoreCAS, bInsertAnnotationContainmentLinks, setTypesToIgnore); if (documentID != null && xmiOutputDirectory != null && xmiOutputDirectory.length() > 0) { File dirOut = new File(xmiOutputDirectory); if (!dirOut.exists() && !dirOut.isDirectory()) { log.error(xmiOutputDirectory + " does not exist"); } else { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter( xmiOutputDirectory + File.separatorChar + documentID.toString() + ".xmi")); XmiCasSerializer ser = new XmiCasSerializer( jcas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(writer, false); ser.serialize(jcas.getCas(), xmlSer.getContentHandler()); } catch (IOException e) { log.error("error writing xmi, documentID=" + documentID, e); } catch (SAXException e) { log.error("error writing xmi, documentID=" + documentID, e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas);  }