ParentheticalAnnotator extends JCasAnnotator_ImplBase { public static AnalysisEngineDescription getDescription( Class<? extends Annotation> parentheticalClass) throws ResourceInitializationException { return getDescription(parentheticalClass, null, '(', ')'); }  void initialize(UimaContext uimaContext); @Override void process(JCas jCas); static AnalysisEngineDescription getDescription(
      Class<? extends Annotation> parentheticalClass); static AnalysisEngineDescription getDescription(
      Class<? extends Annotation> parentheticalClass,
      Class<? extends Annotation> windowClass); static AnalysisEngineDescription getDescription(
      Class<? extends Annotation> parentheticalClass,
      Class<? extends Annotation> windowClass,
      char leftParen,
      char rightParen); static final String PARAM_WINDOW_TYPE_NAME; static final String PARAM_PARENTHETICAL_TYPE_NAME; static final String PARAM_LEFT_PARENTHESIS; static final String PARAM_RIGHT_PARENTHESIS; }
@Test public void testDefault() throws Exception { AnalysisEngineDescription aed = ParentheticalAnnotator.getDescription(Parenthetical.class); testParens("(hello!)", aed, "(hello!)"); testParens("((a) and b)", aed, "((a) and b)", "(a)"); testParens( "from the following options ((a) and (b) and (c)).", aed, "((a) and (b) and (c))", "(a)", "(b)", "(c)"); testParens( "Brain weights of the two high strains, BXD5 (540 9 mg SEM) and BALB / cJ (527 13 mg), are significantly greater (P < .001)", aed, "(540 9 mg SEM)", "(527 13 mg)", "(P < .001)"); testParens( "(A (B C (D E)) F)(G H I)(J K (L M N) O)", aed, "(A (B C (D E)) F)", "(B C (D E))", "(D E)", "(G H I)", "(J K (L M N) O)", "(L M N)"); testParens("(ASDF (FDSA)", aed, "(FDSA)"); testParens("ASDF FDSA)", aed); }
@Test public void testNoSentence() throws Exception { AnalysisEngineDescription aed = ParentheticalAnnotator.getDescription(Sentence.class); testParens("(hello!)", aed); }
@Test public void testSentence() throws Exception { AnalysisEngineDescription aed = ParentheticalAnnotator.getDescription( Parenthetical.class, Sentence.class); tokenBuilder.buildTokens(jCas, "(hello!)"); testParens(aed, "(hello!)"); jCas.reset(); tokenBuilder.buildTokens(jCas, "((he(llo!))(asdf)(asdf))", "((he(llo!))(asdf)\n(asdf))"); testParens(aed, "(he(llo!))", "(llo!)", "(asdf)", "(asdf)"); jCas.reset(); tokenBuilder.buildTokens(jCas, "((he(llo!))(asdf)(asdf))"); testParens(aed, "((he(llo!))(asdf)(asdf))", "(he(llo!))", "(llo!)", "(asdf)", "(asdf)"); jCas.reset(); tokenBuilder.buildTokens( jCas, "1) They lauged and cried (because they were fond of both. 2) Then did neither.", "1) They lauged and cried (because they were fond of both.\n 2) Then did neither."); testParens(aed); }
@Test public void testTypes() throws Exception { AnalysisEngineDescription aed = ParentheticalAnnotator.getDescription(NamedEntityMention.class); ConfigurationParameterFactory.addConfigurationParameter( aed, ParentheticalAnnotator.PARAM_PARENTHETICAL_TYPE_NAME, Chunk.class.getName()); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); String text = "((a))(((abc)bc)def)"; jCas.setDocumentText(text); new NamedEntityMention(jCas, 0, text.length()).addToIndexes(); SimplePipeline.runPipeline(jCas, ae); Collection<Chunk> chunks = JCasUtil.select(jCas, Chunk.class); assertEquals(5, chunks.size()); Iterator<Chunk> chunksIter = chunks.iterator(); assertEquals("((a))", chunksIter.next().getCoveredText()); assertEquals("(a)", chunksIter.next().getCoveredText()); assertEquals("(((abc)bc)def)", chunksIter.next().getCoveredText()); assertEquals("((abc)bc)", chunksIter.next().getCoveredText()); assertEquals("(abc)", chunksIter.next().getCoveredText()); }
@Test public void testBrackets() throws Exception { AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( ParentheticalAnnotator.class, ParentheticalAnnotator.PARAM_LEFT_PARENTHESIS, "[", ParentheticalAnnotator.PARAM_RIGHT_PARENTHESIS, "]", ParentheticalAnnotator.PARAM_PARENTHETICAL_TYPE_NAME, "org.cleartk.test.util.type.Parenthetical"); testParens("[[[a]b]ccc]", aed, "[[[a]b]ccc]", "[[a]b]", "[a]"); AnalysisEngineDescription aed2 = ParentheticalAnnotator.getDescription(Parenthetical.class); AnalysisEngineDescription aed3 = AnalysisEngineFactory.createEngineDescription( ParentheticalAnnotator.class, ParentheticalAnnotator.PARAM_LEFT_PARENTHESIS, "{", ParentheticalAnnotator.PARAM_RIGHT_PARENTHESIS, "}", ParentheticalAnnotator.PARAM_PARENTHETICAL_TYPE_NAME, "org.cleartk.test.util.type.Parenthetical"); jCas.reset(); jCas.setDocumentText("testBrackets(){ SimplePipeline.runPipeline(jCas, aed, aed2, aed3); Collection<Parenthetical> chunks = JCasUtil.select(jCas, Parenthetical.class); Iterator<Parenthetical> chunksIter = chunks.iterator(); assertEquals(3, chunks.size()); assertEquals("()", chunksIter.next().getCoveredText()); assertEquals("{ assertEquals("[some code here]", chunksIter.next().getCoveredText()); }