title: How do I traverse a syntactic parse tree to extract noun phrases using OpenNLP in R?
body: <p>I want to extract noun phrases out of each sentence in a set of documents using R. I used openNLP in R to generate parse trees for each sentence. I need help to traverse the parse tree to extract noun phrases. Here is my code:</p>
  
  <pre><code>install.packages("openNLP")
  library(openNLP)
  install.packages("openNLPmodels.en", repos = "http://datacube.wu.ac.at/", type = "source")
  library(openNLPmodels.en)
  install.package("tm")
  library(tm)
  
  s &lt;- c("The touch pad of my laptop does not work.", 
         "The boy saw the man with the binoculars.")
  s &lt;- as.String(s)
  sent_token_annotator &lt;- Maxent_Sent_Token_Annotator()
  word_token_annotator &lt;- Maxent_Word_Token_Annotator()
  parse_annotator &lt;- Parse_Annotator() 
  a &lt;- annotate(s, list(sent_token_annotator, word_token_annotator))
  p &lt;- parse_annotator(s, a) 
  ptexts &lt;- sapply(p$features, '[[', "parse") 
  ptrees &lt;- lapply(ptexts, Tree_parse) 
  ptrees
  </code></pre>
  
  <p>Here are the output trees:</p>
  
  <p>[[1]]
  (TOP
    (S
      (NP (NP (DT The) (NN touch) (NN pad)) (PP (IN of) (NP (PRP$ my) (NN laptop))))
      (VP (VBZ does) (RB not) (VP (VB work)))
      (. .)))</p>
  
  <p>[[2]]
  (TOP
    (S
      (NP (DT The) (NN boy))
      (VP
        (VBD saw)
        (NP (NP (DT the) (NN man)) (PP (IN with) (NP (DT the) (NNS binoculars)))))
      (. .)))</p>
  
  <p>My goal is to extract NP at any level. For example, "the man with the binoculars", "the man". I searched R openNLP documentation and stack overflow, but couldn't find solutions using R. Your help is appreciated.</p>