BC2GMFormatWriter extends JCasAnnotator_ImplBase { @Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); outputDir = new File((String) aContext.getConfigParameterValue(PARAM_OUTPUT_DIR)); sentencesFile = (String) aContext.getConfigParameterValue(PARAM_SENTENCES_FILE); genesFile = (String) aContext.getConfigParameterValue(PARAM_GENE_FILE); try { sentenceWriter = FileUtilities.getWriterToFile(Path.of(outputDir.getAbsolutePath(), sentencesFile).toFile()); genesWriter = FileUtilities.getWriterToFile(Path.of(outputDir.getAbsolutePath(), genesFile).toFile()); } catch (IOException e) { log.error("IO error when trying to open the output files", e); } wsMatcher = Pattern.compile("\\s").matcher(""); log.info("{}: {}", PARAM_OUTPUT_DIR, outputDir); log.info("{}: {}", PARAM_SENTENCES_FILE, sentencesFile); log.info("{}: {}", PARAM_GENE_FILE, genesFile); }  @Override void initialize(UimaContext aContext); @Override void process(JCas aJCas); @Override void collectionProcessComplete(); TreeMap<Integer, Integer> buildWSMap(String text); static final String PARAM_OUTPUT_DIR; static final String PARAM_SENTENCES_FILE; static final String PARAM_GENE_FILE; }
@Test public void testBuildMap() throws Exception { BC2GMFormatWriter writer = new BC2GMFormatWriter(); writer.initialize(UimaContextFactory.createUimaContext(BC2GMFormatWriter.PARAM_GENE_FILE, "dummy1", BC2GMFormatWriter.PARAM_OUTPUT_DIR, "src/test/resources", BC2GMFormatWriter.PARAM_SENTENCES_FILE, "dummy3")); Method m = writer.getClass().getDeclaredMethod("buildWSMap", String.class); m.setAccessible(true); String string = "This is a test string."; @SuppressWarnings("unchecked") TreeMap<Integer, Integer> wsMap = (TreeMap<Integer, Integer>) m.invoke(writer, string); assertNotNull(wsMap); assertEquals(Integer.valueOf(0), wsMap.floorEntry(1).getValue()); assertEquals(Integer.valueOf(0), wsMap.floorEntry(4).getValue()); assertEquals(Integer.valueOf(2), wsMap.floorEntry(8).getValue()); assertEquals(Integer.valueOf(2), wsMap.floorEntry(9).getValue()); assertEquals(Integer.valueOf(2), wsMap.floorEntry(9).getValue()); assertEquals(Integer.valueOf(4), wsMap.floorEntry(15).getValue()); }