title: Extracting information from context-free phrase structure output from Stanford Parser
body: <p>The Stanford Parser (http://nlp.stanford.edu/software/lex-parser.shtml) gives context-free phrase structure trees as following. What is the best way to extract things like all the Noun Phrases(NP) and Verb Phrases(NP) in the tree? Is there any Python (or Java) library that can allow me to read structures like these? Thank you.</p>
  
  <pre><code>(ROOT
    (S
      (S
        (NP
          (NP (DT The) (JJS strongest) (NN rain))
          (VP
            (ADVP (RB ever))
            (VBN recorded)
            (PP (IN in)
              (NP (NNP India)))))
        (VP
          (VP (VBD shut)
            (PRT (RP down))
            (NP
              (NP (DT the) (JJ financial) (NN hub))
              (PP (IN of)
                (NP (NNP Mumbai)))))
          (, ,)
          (VP (VBD snapped)
            (NP (NN communication) (NNS lines)))
          (, ,)
          (VP (VBD closed)
            (NP (NNS airports)))
          (CC and)
          (VP (VBD forced)
            (NP
              (NP (NNS thousands))
              (PP (IN of)
                (NP (NNS people))))
            (S
              (VP (TO to)
                (VP
                  (VP (VB sleep)
                    (PP (IN in)
                      (NP (PRP$ their) (NNS offices))))
                  (CC or)
                  (VP (VB walk)
                    (NP (NN home))
                    (PP (IN during)
                      (NP (DT the) (NN night))))))))))
      (, ,)
      (NP (NNS officials))
      (VP (VBD said)
        (NP-TMP (NN today)))
      (. .)))
  </code></pre>