Skip to content

Instantly share code, notes, and snippets.

@alexbowe
Created September 12, 2010 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbowe/575759 to your computer and use it in GitHub Desktop.
Save alexbowe/575759 to your computer and use it in GitHub Desktop.
# Extracting nounphrase chunks from a parse tree
# from http://streamhacker.com/2009/02/23/chunk-extraction-with-nltk/
# for each noun phrase sub tree in the parse tree
for subtree in tree.subtrees(filter=lambda t: t.node == 'NP'):
# print the noun phrase as a list of part-of-speech tagged words
print subtree.leaves()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment