I have a parse tree, which is an object of the class Parse
class in opennlp. I want to print the text from the parse tree. For example consider the sentence: Wikipedia is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation.
. I have identified the noun phrases in the sentence:
(NP (NNP Wikipedia))
(NP (NP (DT a) (RB collaboratively) (JJ edited,) (JJ multilingual,) (JJ free) (NNP Internet) (NN encyclopedia)) (VP (VBN supported) (PP (IN by) (NP (DT the) (JJ non-profit) (NNP Wikimedia) (NNP Foundation.)))))
(NP (DT a) (RB collaboratively) (JJ edited,) (JJ multilingual,) (JJ free) (NNP Internet) (NN encyclopedia))
(NP (DT the) (JJ non-profit) (NNP Wikimedia) (NNP Foundation.))
I want to output the list ["Wikipedia", "collaboratively edited...", "non profit wikimedia foundation"]
. The getText
method in Parse
returns the whole sentence, instead of just the string associated with the parse tree. Is there a way to do that directly in OpenNLP?
I found the solution, the function is: Parse.getCoveredText()
.