private static JsonNode loadCountriesJson(ObjectMapper mapper, UimaMonitor uimaMonitor) throws ResourceInitializationException { try (InputStream is = SharedCountryResource.class.getResourceAsStream("countries/countries.json"); ) { return mapper.readTree(is); } catch (IOException ioe) { uimaMonitor.error("Unable to read nationalities from countries.json", ioe); throw new ResourceInitializationException(ioe); } }
private static JsonNode loadCountriesJson(ObjectMapper mapper, UimaMonitor uimaMonitor) throws ResourceInitializationException { try (InputStream is = SharedCountryResource.class.getResourceAsStream("countries/countries.json"); ) { return mapper.readTree(is); } catch (IOException ioe) { uimaMonitor.error("Unable to read nationalities from countries.json", ioe); throw new ResourceInitializationException(ioe); } }
private void processAttachment(JCas jCas, File attachment) throws IOException { try (InputStream is = new FileInputStream(attachment); ) { extractContent(is, attachment.getAbsolutePath(), jCas); } // Delete attachment? if (deleteAttachmentsAfterProcessing) { try { Files.delete(attachment.toPath()); } catch (IOException ioe) { getMonitor().error("Unable to delete attachment", ioe); } } }
@Override protected boolean doInitialize(ResourceSpecifier specifier, Map<String, Object> additionalParams) throws ResourceInitializationException { try { stopwords = loadStoplist("SmartStoplist.txt"); } catch (IOException ioe) { getMonitor().error("Unable to read default stop words from SmartStoplist.txt", ioe); throw new ResourceInitializationException(ioe); } return true; }
@Override protected boolean doInitialize(ResourceSpecifier specifier, Map<String, Object> additionalParams) throws ResourceInitializationException { try { stopwords = loadStoplist("SmartStoplist.txt"); } catch (IOException ioe) { getMonitor().error("Unable to read default stop words from SmartStoplist.txt", ioe); throw new ResourceInitializationException(ioe); } return true; }
@Override protected void doDestroy() { getMonitor().debug("Disconnecting from ActiveMQ"); try { session.close(); connection.close(); } catch (JMSException e) { getMonitor().error("Could not close connection to ActiveMQ", e); } }
@Override public void doGetNext(JCas jCas) throws IOException, CollectionException { if (queue.isEmpty()) { getMonitor().error("No documents on the queue - this method should not have been called"); throw new CollectionException(); } Path path = queue.remove(0); getMonitor().info("Processing file {}", path.toString()); try (InputStream is = new FileInputStream(path.toFile()); ) { extractor.processStream(is, path.toString(), jCas); } }
@Override protected void doDestroy() { getMonitor().debug("Disconnecting from ActiveMQ"); try { session.close(); connection.close(); } catch (JMSException e) { getMonitor().error("Could not close connection to ActiveMQ", e); } }
@Override public void doGetNext(JCas jCas) throws IOException, CollectionException { if (queue.isEmpty()) { getMonitor().error("No documents on the queue - this method should not have been called"); throw new CollectionException(); } Path path = queue.remove(0); getMonitor().info("Processing file {}", path.toString()); try (InputStream is = new FileInputStream(path.toFile()); ) { extractContent(is, path.toString(), jCas); } }
/** Add a mapping to Elasticsearch. This will only be called if a new index has been created */ public void addMapping(XContentBuilder mapping) { try { HttpEntity entity = new StringEntity(mapping.string()); esrResource .getClient() .performRequest("PUT", "/" + index + "/_mapping/" + type, Collections.emptyMap(), entity); } catch (IOException ioe) { getMonitor().error("Unable to add mapping to index", ioe); } }
@Override public void addMapping(XContentBuilder mapping) { try { HttpEntity entity = new StringEntity(mapping.string()); esrResource .getClient() .performRequest("PUT", "/" + index + "/_mapping/" + type, Collections.emptyMap(), entity); } catch (IOException ioe) { getMonitor().error("Unable to add mapping to index", ioe); } }
private void save(final String index, final String type, final Object o, final String id) { try { esResource .getClient() .prepareIndex(index, type, id) .setSource(MAPPER.writeValueAsBytes(o), XContentType.JSON) .execute() .actionGet(); } catch (final Exception ee) { getMonitor().error("Couldn't persist entity to Elasticsearch", ee); } }
/** * Adds a event to the history for this CAS document. * * @param cas the target document for the event * @param event the event to add */ public void addToHistory(CAS cas, HistoryEvent event) { try { getDocumentHistory(cas.getJCas()).add(event); } catch (CASException e) { monitor.error("Unable to add to history on add", e); } }
@Override public void addDocument(String id, Map<String, Object> json) { try { esResource.getClient().prepareIndex(index, type, id).setSource(json).execute().actionGet(); } catch (ElasticsearchException ee) { getMonitor().error("Couldn't persist document to Elasticsearch", ee); } } }
/** Add the document (provided as JSON) to Elasticsearch, using the id provided. */ public void addDocument(String id, Map<String, Object> json) { try { esResource.getClient().prepareIndex(index, type, id).setSource(json).execute().actionGet(); } catch (ElasticsearchException ee) { getMonitor().error("Couldn't persist document to Elasticsearch", ee); } }
/** Add the document (provided as JSON) to Elasticsearch, using the id provided. */ public void addDocument(String id, Map<String, Object> json) { try { esResource.getClient().prepareIndex(index, type, id).setSource(json).execute().actionGet(); } catch (ElasticsearchException ee) { getMonitor().error("Couldn't persist document to Elasticsearch", ee); } }
@Override protected void doDestroy() { getMonitor().debug("Disconnecting from RabbitMQ"); try { connection.close(); } catch (final Exception e) { getMonitor().error("Could not close connection to RabbitMQ", e); } } }
@Override protected void doDestroy() { getMonitor().debug("Disconnecting from RabbitMQ"); try { connection.close(); } catch (final Exception e) { getMonitor().error("Could not close connection to RabbitMQ", e); } } }
private void addMergeToHistory(Annotation keep, Annotation removed) { if (keep instanceof Recordable && removed instanceof Base) { Recordable r = (Recordable) keep; Base b = (Base) removed; try { addToHistory( keep.getCAS().getJCas(), HistoryEvents.createMerged(r, referrer, b.getInternalId())); } catch (CASException e) { monitor.error("Unable to add merge to history", e); } } }
@Test public void testLogger() { UimaMonitor monitor = new UimaMonitor(PIPELINE, this.getClass()); monitor.trace("test"); monitor.debug("test"); monitor.info("test"); monitor.warn("test"); monitor.error("test"); } }