GazetteerAnnotator extends JCasAnnotator_ImplBase { static boolean filterParenthesis(String chunkText) { Stack<Character> parenthesisStack = new Stack<>(); for (int i = 0; i < chunkText.length(); i++) { char current = chunkText.charAt(i); if (isParentheses(current)) { if (isOpenedParentheses(current)) { parenthesisStack.add(current); } else { if (parenthesisStack.isEmpty()) return true; if (!isParenthesisCounterpart(parenthesisStack.pop(), current)) return true; } } } if (!parenthesisStack.isEmpty()) return true; return false; }  void initialize(UimaContext aContext); void process(JCas aJCas); static final String CHUNKER_RESOURCE_NAME; final static String PARAM_CHECK_ACRONYMS; final static String PARAM_OUTPUT_TYPE; }
@Test public void testFilterParenthesis() { String chunkText; boolean filtered; chunkText = "glutathione transferases ("; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = ") transferases"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "BTM) alpha"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "interleukin-2 (IL-2"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "interleukin-2 ["; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "] interleukin-2"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "interleukin-2 {IL-2"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "interleukin-2 } IL-2"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "BMT {mobile unit]"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "GSTA4)"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertTrue(filtered); chunkText = "glutathione transferases"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertFalse(filtered); chunkText = "Di(hydroxy)-transferase"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertFalse(filtered); chunkText = "4[mg]"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertFalse(filtered); chunkText = "tri{ferrus} iron"; filtered = GazetteerAnnotator.filterParenthesis(chunkText); assertFalse(filtered); }