Extracting noun phrases from a text file using stanford typed parser

S Gaber picture S Gaber · Jun 11, 2012 · Viewed 17.8k times · Source

I have a text which I want to extract the noun phrases from it. I can easily get the typed parser for the text that i have, but wondering how i can extract the noun phrases in the text ?

Answer

alan turing picture alan turing · Feb 11, 2013

You can extract noun phrases from Tree by using following code. It assumes you have parsed sentence stored in parse (i.e. parse is output of LexicalizedParser class apply method)

public static List<Tree> GetNounPhrases()
{

    List<Tree> phraseList=new ArrayList<Tree>();
    for (Tree subtree: parse)
    {

      if(subtree.label().value().equals("NP"))
      {

        phraseList.add(subtree);
        System.out.println(subtree);

      }
    }

      return phraseList;

}