ParserAnnotator extends ParserWrapper_ImplBase<TOKEN_TYPE, SENTENCE_TYPE, Parse, TOP_NODE_TYPE> { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { String text = jCas.getDocumentText(); List<SENTENCE_TYPE> sentenceList = inputTypesHelper.getSentences(jCas); for (SENTENCE_TYPE sentence : sentenceList) { Parse parse = new Parse( text, new Span(sentence.getBegin(), sentence.getEnd()), AbstractBottomUpParser.INC_NODE, 1, null); List<TOKEN_TYPE> tokenList = inputTypesHelper.getTokens(jCas, sentence); for (TOKEN_TYPE token : tokenList) { parse.insert(new Parse( text, new Span(token.getBegin(), token.getEnd()), AbstractBottomUpParser.TOK_NODE, 0, 0)); } if (useTagsFromCas) { this.casTagger.setTokens(tokenList); } parse = this.parser.parse(parse); if (parse.getType() == AbstractBottomUpParser.TOP_NODE) { outputTypesHelper.addParse(jCas, parse, sentence, tokenList); } if (!useTagsFromCas) { setPOSTags(parse, tokenList.iterator(), jCas); } } }  @SuppressWarnings("unchecked") @Override void initialize(UimaContext ctx); @Override void process(JCas jCas); static AnalysisEngineDescription getDescription(); static final String DEFAULT_PARSER_MODEL_PATH; static final int DEFAULT_BEAM_SIZE; static final float DEFAULT_ADVANCE_PERCENTAGE; static final String PARAM_PARSER_MODEL_PATH; static final String PARAM_BEAM_SIZE; static final String PARAM_ADVANCE_PERCENTAGE; static final String PARAM_USE_TAGS_FROM_CAS; }
@Test public void test() throws UIMAException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( ParserAnnotator.class, ParserAnnotator.PARAM_PARSER_MODEL_PATH, MODEL_PATH, ParserAnnotator.PARAM_USE_TAGS_FROM_CAS, true, ParserWrapper_ImplBase.PARAM_OUTPUT_TYPES_HELPER_CLASS_NAME, DefaultOutputTypesHelper.class.getName()); tokenBuilder.buildTokens( jCas, "Two recent papers provide new evidence relevant to the role of the breast cancer susceptibility gene BRCA2 in DNA repair.", "Two recent papers provide new evidence relevant to the role of the breast cancer susceptibility gene BRCA2 in DNA repair .", "DT JJ NN VBP JJ NN JJ IN DT NN IN DT NN NN NN NN NN IN NN NN ." ); engine.process(jCas); engine.collectionProcessComplete(); TopTreebankNode tree = JCasUtil.selectSingle(jCas, TopTreebankNode.class); Assert.assertNotNull(tree); Assert.assertEquals("TOP", tree.getNodeType()); Assert.assertEquals(1, tree.getChildren().size()); TreebankNode sNode = tree.getChildren(0); Assert.assertEquals("S", sNode.getNodeType()); Assert.assertEquals(3, sNode.getChildren().size()); TreebankNode npNode = sNode.getChildren(0); TreebankNode vpNode = sNode.getChildren(1); TreebankNode periodNode = sNode.getChildren(2); Assert.assertEquals("NP", npNode.getNodeType()); Assert.assertEquals("VP", vpNode.getNodeType()); Assert.assertEquals(".", periodNode.getNodeType()); Assert.assertEquals(3, npNode.getChildren().size()); Assert.assertEquals(3, npNode.getChildren().size()); Assert.assertEquals(3, JCasUtil.selectCovered(this.jCas, TreebankNode.class, npNode).size()); TreebankNode twoNode = npNode.getChildren(0); TreebankNode recentNode = npNode.getChildren(1); TreebankNode papersNode = npNode.getChildren(2); Assert.assertEquals("DT", twoNode.getNodeType()); Assert.assertEquals("JJ", recentNode.getNodeType()); Assert.assertEquals("NN", papersNode.getNodeType()); Assert.assertEquals("Two", twoNode.getNodeValue()); Assert.assertEquals("recent", recentNode.getNodeValue()); Assert.assertEquals("papers", papersNode.getNodeValue()); TreebankNode provideNode = vpNode.getChildren(0); TreebankNode newEvidenceNode = vpNode.getChildren(1); Assert.assertEquals("VBP", provideNode.getNodeType()); Assert.assertEquals("provide", provideNode.getNodeValue()); Assert.assertEquals("NP", newEvidenceNode.getNodeType()); Assert.assertEquals( "new evidence relevant to the role of the breast cancer susceptibility gene BRCA2 in DNA repair", newEvidenceNode.getCoveredText()); }
@Test public void test2() throws UIMAException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( ParserAnnotator.class, ParserAnnotator.PARAM_PARSER_MODEL_PATH, MODEL_PATH, ParserAnnotator.PARAM_USE_TAGS_FROM_CAS, false, ParserWrapper_ImplBase.PARAM_INPUT_TYPES_HELPER_CLASS_NAME, TestInputTypesHelper.class.getName(), ParserWrapper_ImplBase.PARAM_OUTPUT_TYPES_HELPER_CLASS_NAME, DefaultOutputTypesHelper.class.getName()); TokenBuilder<org.cleartk.test.util.type.Token, org.cleartk.test.util.type.Sentence> tokBuilder = new TokenBuilder<org.cleartk.test.util.type.Token, org.cleartk.test.util.type.Sentence>( org.cleartk.test.util.type.Token.class, org.cleartk.test.util.type.Sentence.class); tokBuilder.buildTokens( jCas, "Two recent papers provide new evidence relevant to the role of the breast cancer susceptibility gene BRCA2 in DNA repair.", "Two recent papers provide new evidence relevant to the role of the breast cancer susceptibility gene BRCA2 in DNA repair ."); engine.process(jCas); engine.collectionProcessComplete(); TopTreebankNode tree = JCasUtil.selectSingle(jCas, TopTreebankNode.class); Assert.assertNotNull(tree); Assert.assertEquals("TOP", tree.getNodeType()); Assert.assertEquals(1, tree.getChildren().size()); TreebankNode sNode = tree.getChildren(0); Assert.assertEquals("S", sNode.getNodeType()); Assert.assertEquals(3, sNode.getChildren().size()); TreebankNode npNode = sNode.getChildren(0); TreebankNode vpNode = sNode.getChildren(1); TreebankNode periodNode = sNode.getChildren(2); Assert.assertEquals("NP", npNode.getNodeType()); Assert.assertEquals("VP", vpNode.getNodeType()); Assert.assertEquals(".", periodNode.getNodeType()); Assert.assertEquals(3, npNode.getChildren().size()); TreebankNode twoNode = npNode.getChildren(0); TreebankNode recentNode = npNode.getChildren(1); TreebankNode papersNode = npNode.getChildren(2); Assert.assertEquals("CD", twoNode.getNodeType()); Assert.assertEquals("JJ", recentNode.getNodeType()); Assert.assertEquals("NNS", papersNode.getNodeType()); Assert.assertEquals("Two", twoNode.getNodeValue()); Assert.assertEquals("recent", recentNode.getNodeValue()); Assert.assertEquals("papers", papersNode.getNodeValue()); TreebankNode provideNode = vpNode.getChildren(0); TreebankNode newEvidenceNode = vpNode.getChildren(1); Assert.assertEquals("VBP", provideNode.getNodeType()); Assert.assertEquals("provide", provideNode.getNodeValue()); Assert.assertEquals("NP", newEvidenceNode.getNodeType()); Assert.assertEquals( "new evidence relevant to the role of the breast cancer susceptibility gene BRCA2 in DNA repair", newEvidenceNode.getCoveredText()); }
@Test public void testTerminals() throws UIMAException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( ParserAnnotator.class, ParserAnnotator.PARAM_PARSER_MODEL_PATH, MODEL_PATH, ParserAnnotator.PARAM_USE_TAGS_FROM_CAS, true, ParserWrapper_ImplBase.PARAM_OUTPUT_TYPES_HELPER_CLASS_NAME, DefaultOutputTypesHelper.class.getName()); this.tokenBuilder.buildTokens( jCas, "The skunk thought the stump stunk.", "The skunk thought the stump stunk .", "DT NN VBD DT NN VBD ."); engine.process(this.jCas); engine.collectionProcessComplete(); Collection<TopTreebankNode> roots = JCasUtil.select(jCas, TopTreebankNode.class); Assert.assertEquals(1, roots.size()); TopTreebankNode root = roots.iterator().next(); Assert.assertEquals(7, root.getTerminals().size()); Assert.assertEquals("DT", root.getTerminals(0).getNodeType()); Assert.assertEquals("The", root.getTerminals(0).getCoveredText()); Assert.assertEquals("VBD", root.getTerminals(2).getNodeType()); Assert.assertEquals("thought", root.getTerminals(2).getCoveredText()); Assert.assertEquals(".", root.getTerminals(6).getNodeType()); Assert.assertEquals(".", root.getTerminals(6).getCoveredText()); }
@Test public void testNoPos() throws UIMAException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( ParserAnnotator.class, ParserAnnotator.PARAM_PARSER_MODEL_PATH, MODEL_PATH, ParserAnnotator.PARAM_USE_TAGS_FROM_CAS, true, ParserWrapper_ImplBase.PARAM_OUTPUT_TYPES_HELPER_CLASS_NAME, DefaultOutputTypesHelper.class.getName()); tokenBuilder.buildTokens( jCas, "The brown fox jumped quickly over the lazy dog.", "The brown fox jumped quickly over the lazy dog ."); Level level = DisableLogging.disableLogging(); try { engine.process(jCas); } catch (AnalysisEngineProcessException e) { if (!e.getCause().getMessage().contains("part of speech")) { Assert.fail("expected exception for no part of speech tags"); } } finally { engine.collectionProcessComplete(); DisableLogging.enableLogging(level); } }