def noun_chunks(obj):
<EOL>labels = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT:root>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]<EOL>doc = obj.doc  <EOL>np_label = doc.vocab.strings.add("<STR_LIT>")<EOL>np_deps = set(doc.vocab.strings.add(label) for label in labels)<EOL>close_app = doc.vocab.strings.add("<STR_LIT>")<EOL>rbracket = <NUM_LIT:0><EOL>for i, word in enumerate(obj):<EOL><INDENT>if i < rbracket:<EOL><INDENT>continue<EOL><DEDENT>if word.pos in (NOUN, PROPN, PRON) and word.dep in np_deps:<EOL><INDENT>rbracket = word.i + <NUM_LIT:1><EOL>for rdep in doc[word.i].rights:<EOL><INDENT>if rdep.pos in (NOUN, PROPN) and rdep.dep == close_app:<EOL><INDENT>rbracket = rdep.i + <NUM_LIT:1><EOL><DEDENT><DEDENT>yield word.left_edge.i, rbracket, np_label<EOL><DEDENT><DEDENT>
Detect base noun phrases from a dependency parse. Works on both Doc and Span.