@Test public void testProcessCasWithHeaderSource() throws Exception { String sourceValue = "test_1"; CAS cas = createCas(); JCas jcas = cas.getJCas(); jcas.setDocumentText(TEST_TEXT); Header header = new Header(jcas); header.setDocId(sourceValue); header.addToIndexes(); consumer.process(cas); File expectedXMI = new File(OUTPUT_FOLDER_XMI + "/" + sourceValue + XMI_EXTENSION); assertTrue(expectedXMI.exists()); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { doc.incrementAndGet(); CAS aCAS; aCAS = jcas.getCas(); StringBuilder outFileName = new StringBuilder(); Type fileNameType = aCAS.getTypeSystem().getType(fileNameTypeName); if (fileNameType != null) { Feature fileNameFeature = fileNameType .getFeatureByBaseName(fileNameFeatureName); if (fileNameFeature != null) { JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator iter = indexes.getAllIndexedFS(fileNameType); if (iter.hasNext()) { FeatureStructure fs = (FeatureStructure) iter.next(); try { String value = fs.getStringValue(fileNameFeature); if (value != null) { value = value.trim(); if (!value.isEmpty()) { if (value.contains(File.separator)) { String[] path = value.split(File.separator); outFileName.append(path[path.length - 1]); } else { outFileName.append(value); } } } else { LOGGER.debug("No feature value found of type.feature " + fileNameTypeName + "." + fileNameFeatureName); } } catch (CASRuntimeException e) { LOGGER.warn("Choose feature with String value!"); try { throw new ResourceProcessException(); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } } else { LOGGER.debug("No annotation found of type " + fileNameTypeName); } } else { LOGGER.debug("No feature of type " + fileNameTypeName + " found with name " + fileNameFeatureName); } } else { LOGGER.debug("No type found with name " + fileNameTypeName); } if (outFileName.length() == 0) { outFileName.append(doc); } outFileName.append(XMI_EXTENSION); if (compress) { outFileName.append(GZIP_EXTENSION); } String fileName = outFileName.toString(); try { writeXmi(jcas.getCas(), fileName); LOGGER.info(" Wrote file " + fileName); } catch (IOException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (SAXException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (ResourceProcessException e) { e.printStackTrace(); } }
CasToXmiConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { doc.incrementAndGet(); CAS aCAS; aCAS = jcas.getCas(); StringBuilder outFileName = new StringBuilder(); Type fileNameType = aCAS.getTypeSystem().getType(fileNameTypeName); if (fileNameType != null) { Feature fileNameFeature = fileNameType .getFeatureByBaseName(fileNameFeatureName); if (fileNameFeature != null) { JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator iter = indexes.getAllIndexedFS(fileNameType); if (iter.hasNext()) { FeatureStructure fs = (FeatureStructure) iter.next(); try { String value = fs.getStringValue(fileNameFeature); if (value != null) { value = value.trim(); if (!value.isEmpty()) { if (value.contains(File.separator)) { String[] path = value.split(File.separator); outFileName.append(path[path.length - 1]); } else { outFileName.append(value); } } } else { LOGGER.debug("No feature value found of type.feature " + fileNameTypeName + "." + fileNameFeatureName); } } catch (CASRuntimeException e) { LOGGER.warn("Choose feature with String value!"); try { throw new ResourceProcessException(); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } } else { LOGGER.debug("No annotation found of type " + fileNameTypeName); } } else { LOGGER.debug("No feature of type " + fileNameTypeName + " found with name " + fileNameFeatureName); } } else { LOGGER.debug("No type found with name " + fileNameTypeName); } if (outFileName.length() == 0) { outFileName.append(doc); } outFileName.append(XMI_EXTENSION); if (compress) { outFileName.append(GZIP_EXTENSION); } String fileName = outFileName.toString(); try { writeXmi(jcas.getCas(), fileName); LOGGER.info(" Wrote file " + fileName); } catch (IOException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (SAXException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (ResourceProcessException e) { e.printStackTrace(); } } }
CasToXmiConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { doc.incrementAndGet(); CAS aCAS; aCAS = jcas.getCas(); StringBuilder outFileName = new StringBuilder(); Type fileNameType = aCAS.getTypeSystem().getType(fileNameTypeName); if (fileNameType != null) { Feature fileNameFeature = fileNameType .getFeatureByBaseName(fileNameFeatureName); if (fileNameFeature != null) { JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator iter = indexes.getAllIndexedFS(fileNameType); if (iter.hasNext()) { FeatureStructure fs = (FeatureStructure) iter.next(); try { String value = fs.getStringValue(fileNameFeature); if (value != null) { value = value.trim(); if (!value.isEmpty()) { if (value.contains(File.separator)) { String[] path = value.split(File.separator); outFileName.append(path[path.length - 1]); } else { outFileName.append(value); } } } else { LOGGER.debug("No feature value found of type.feature " + fileNameTypeName + "." + fileNameFeatureName); } } catch (CASRuntimeException e) { LOGGER.warn("Choose feature with String value!"); try { throw new ResourceProcessException(); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } } else { LOGGER.debug("No annotation found of type " + fileNameTypeName); } } else { LOGGER.debug("No feature of type " + fileNameTypeName + " found with name " + fileNameFeatureName); } } else { LOGGER.debug("No type found with name " + fileNameTypeName); } if (outFileName.length() == 0) { outFileName.append(doc); } outFileName.append(XMI_EXTENSION); if (compress) { outFileName.append(GZIP_EXTENSION); } String fileName = outFileName.toString(); try { writeXmi(jcas.getCas(), fileName); LOGGER.info(" Wrote file " + fileName); } catch (IOException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (SAXException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (ResourceProcessException e) { e.printStackTrace(); } }  }
CasToXmiConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { doc.incrementAndGet(); CAS aCAS; aCAS = jcas.getCas(); StringBuilder outFileName = new StringBuilder(); Type fileNameType = aCAS.getTypeSystem().getType(fileNameTypeName); if (fileNameType != null) { Feature fileNameFeature = fileNameType .getFeatureByBaseName(fileNameFeatureName); if (fileNameFeature != null) { JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator iter = indexes.getAllIndexedFS(fileNameType); if (iter.hasNext()) { FeatureStructure fs = (FeatureStructure) iter.next(); try { String value = fs.getStringValue(fileNameFeature); if (value != null) { value = value.trim(); if (!value.isEmpty()) { if (value.contains(File.separator)) { String[] path = value.split(File.separator); outFileName.append(path[path.length - 1]); } else { outFileName.append(value); } } } else { LOGGER.debug("No feature value found of type.feature " + fileNameTypeName + "." + fileNameFeatureName); } } catch (CASRuntimeException e) { LOGGER.warn("Choose feature with String value!"); try { throw new ResourceProcessException(); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } } else { LOGGER.debug("No annotation found of type " + fileNameTypeName); } } else { LOGGER.debug("No feature of type " + fileNameTypeName + " found with name " + fileNameFeatureName); } } else { LOGGER.debug("No type found with name " + fileNameTypeName); } if (outFileName.length() == 0) { outFileName.append(doc); } outFileName.append(XMI_EXTENSION); if (compress) { outFileName.append(GZIP_EXTENSION); } String fileName = outFileName.toString(); try { writeXmi(jcas.getCas(), fileName); LOGGER.info(" Wrote file " + fileName); } catch (IOException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (SAXException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (ResourceProcessException e) { e.printStackTrace(); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); void batchProcessComplete(ProcessTrace processTrace); void collectionProcessComplete(ProcessTrace processTrace); }
CasToXmiConsumer extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { doc.incrementAndGet(); CAS aCAS; aCAS = jcas.getCas(); StringBuilder outFileName = new StringBuilder(); Type fileNameType = aCAS.getTypeSystem().getType(fileNameTypeName); if (fileNameType != null) { Feature fileNameFeature = fileNameType .getFeatureByBaseName(fileNameFeatureName); if (fileNameFeature != null) { JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator iter = indexes.getAllIndexedFS(fileNameType); if (iter.hasNext()) { FeatureStructure fs = (FeatureStructure) iter.next(); try { String value = fs.getStringValue(fileNameFeature); if (value != null) { value = value.trim(); if (!value.isEmpty()) { if (value.contains(File.separator)) { String[] path = value.split(File.separator); outFileName.append(path[path.length - 1]); } else { outFileName.append(value); } } } else { LOGGER.debug("No feature value found of type.feature " + fileNameTypeName + "." + fileNameFeatureName); } } catch (CASRuntimeException e) { LOGGER.warn("Choose feature with String value!"); try { throw new ResourceProcessException(); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } } else { LOGGER.debug("No annotation found of type " + fileNameTypeName); } } else { LOGGER.debug("No feature of type " + fileNameTypeName + " found with name " + fileNameFeatureName); } } else { LOGGER.debug("No type found with name " + fileNameTypeName); } if (outFileName.length() == 0) { outFileName.append(doc); } outFileName.append(XMI_EXTENSION); if (compress) { outFileName.append(GZIP_EXTENSION); } String fileName = outFileName.toString(); try { writeXmi(jcas.getCas(), fileName); LOGGER.info(" Wrote file " + fileName); } catch (IOException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (SAXException e) { try { throw new ResourceProcessException(e); } catch (ResourceProcessException e1) { e1.printStackTrace(); } } catch (ResourceProcessException e) { e.printStackTrace(); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas jcas); void batchProcessComplete(ProcessTrace processTrace); void collectionProcessComplete(ProcessTrace processTrace); static final String PARAM_OUTPUTDIR; static final String CREATE_BATCH_SUBDIRS; static final String PARAM_COMPRESS; static final String PARAM_COMPRESS_SINGLE; static final String PARAM_FILE_NAME_TYPE; static final String PARAM_FILE_NAME_FEATURE; }