Created
October 9, 2015 01:45
-
-
Save technocrat/9ae8db10da4be357efd8 to your computer and use it in GitHub Desktop.
Preparation of text to find specific pattern of words and then collect matches with a specific keyword in a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nltk | |
| from nltk.chunk import * | |
| from nltk.chunk.util import * | |
| from nltk.chunk.regexp import * | |
| from nltk import Tree | |
| cp = nltk.RegexpParser('CHUNK: {<NN> <VB> <IN> <NN>}') | |
| bucket = [] | |
| brown = nltk.corpus.brown | |
| for sent in brown.tagged_sents(): | |
| tree = cp.parse(sent) | |
| for subtree in tree.subtrees(): | |
| if subtree.label() == 'CHUNK': | |
| if 'sciatica' in ' '.join([(''.join(''.join(leaf[0]))) for leaf in subtree]): | |
| bucket.append(' '.join([(''.join(''.join(leaf[0]))) for leaf in subtree])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment