AcronymAnnotator extends JCasAnnotator_ImplBase { public void process(JCas aJCas) { LOGGER.debug("[JACRO] processing document..."); try { JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); FSIterator sentenceIter = indexes.getAnnotationIndex(Sentence.type).iterator(); String sentenceText; while (sentenceIter.hasNext()) { Sentence sentence = (Sentence) sentenceIter.next(); sentenceText = sentence.getCoveredText(); annotate(sentenceText, aJCas, sentence.getBegin()); } if (consistencyAnno) { ConsistencyAnnotator ca = new ConsistencyAnnotator(); ca.consistencyAnnotate(aJCas); } if (postprocessing) { Postprocessing.doPostprocessing(aJCas); } } catch (StringIndexOutOfBoundsException e) { LOGGER.error("typical Error in AcronymAnnotator.process() : StringIndexOutOfBounds"); } }  void initialize(UimaContext aContext); void process(JCas aJCas); static final String PARAM_ACROLIST; static final String PARAM_CONSISTENCY_ANNO; static final String PARAM_MAXLENGTH_FACTOR; }
@Test public void testFindFullFormInParentheses() throws Exception { CAS cas = CasCreationUtils.createCas( UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(FILE_DESCRIPTOR_AE))); JCas testCas = null; testCas = cas.getJCas(); ResourceSpecifier spec; spec = UIMAFramework.getXMLParser().parseResourceSpecifier(new XMLInputSource(AA_DESCRIPTOR)); AnalysisEngine abbreAn = UIMAFramework.produceAnalysisEngine(spec); String text = "The Drosophila retinal-specific protein, TRP (transient receptor potential), is the founding member of a family of store-operated channels (SOCs) conserved from C. elegans to humans."; testCas.setDocumentText(text); Sentence sent = new Sentence(testCas, 0, text.length()); sent.addToIndexes(); abbreAn.process(cas); FSIterator<Annotation> abbrIt = testCas.getAnnotationIndex(Abbreviation.type).iterator(); assertTrue(abbrIt.hasNext()); Abbreviation abbreviation = (Abbreviation) abbrIt.next(); assertEquals("TRP", abbreviation.getCoveredText()); assertEquals("transient receptor potential", abbreviation.getExpan()); assertEquals("transient receptor potential", abbreviation.getTextReference().getCoveredText()); }
@Test public void testUimaFitAndClassPathResource() throws Exception { JCas jCas = JCasFactory.createJCas(ALL_TYPES_NAME); jCas.setDocumentText("We observed interleukin-2 (IL2) in the cell"); Sentence sentence = new Sentence(jCas, 0, jCas.getDocumentText().length()); sentence.addToIndexes(); AnalysisEngine engine = AnalysisEngineFactory.createEngine(AcronymAnnotator.class, AcronymAnnotator.PARAM_ACROLIST, BASE_PATH + "testresources/acrolist.txt"); engine.process(jCas.getCas()); FSIterator<Annotation> iterator = jCas.getAnnotationIndex(Abbreviation.type).iterator(); assertTrue(iterator.hasNext()); iterator.next(); assertFalse(iterator.hasNext()); }
@Test public void testPostprocessing() throws Exception { JCas jCas = JCasFactory.createJCas(ALL_TYPES_NAME); jCas.setDocumentText("Tumor necrosis factor (TNF) is one thing. The TNF receptor(TNF-R) is another."); new Sentence(jCas, 0, 41).addToIndexes(); new Sentence(jCas, 42, jCas.getDocumentText().length()).addToIndexes(); AnalysisEngine engine = AnalysisEngineFactory.createEngine(AcronymAnnotator.class, AcronymAnnotator.PARAM_ACROLIST, BASE_PATH + "testresources/acrolist.txt"); engine.process(jCas.getCas()); Collection<Abbreviation> acronyms = JCasUtil.select(jCas, Abbreviation.class); assertEquals(2, acronyms.size()); Collection<AbbreviationLongform> longForms = JCasUtil.select(jCas, AbbreviationLongform.class); assertEquals(2, longForms.size()); }
@Test public void testPostprocessing2() throws Exception { JCas jCas = JCasFactory.createJCas(ALL_TYPES_NAME); String docText = new String( Files.readAllBytes( Paths.get("src/test/resources/de/julielab/jcore/ae/acronymtagger/testresources/1698610.txt")), "UTF-8"); jCas.setDocumentText(docText); int fromIndex = 0; int toIndex; while((toIndex = docText.indexOf('.', fromIndex)) != -1) { if (fromIndex > 0) ++fromIndex; new Sentence(jCas, fromIndex, toIndex + 1).addToIndexes(); fromIndex = toIndex+1; } AnalysisEngine engine = AnalysisEngineFactory.createEngine(AcronymAnnotator.class, AcronymAnnotator.PARAM_ACROLIST, BASE_PATH + "testresources/acrolist.txt"); engine.process(jCas.getCas()); Collection<Abbreviation> acronyms = JCasUtil.select(jCas, Abbreviation.class); assertEquals(16, acronyms.size()); Collection<AbbreviationLongform> longForms = JCasUtil.select(jCas, AbbreviationLongform.class); assertEquals(4, longForms.size()); }