def noun_chunks(obj):
<EOL>labels = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>doc = obj.doc  <EOL>np_deps = [doc.vocab.strings.add(label) for label in labels]<EOL>conj = doc.vocab.strings.add("<STR_LIT>")<EOL>nmod = doc.vocab.strings.add("<STR_LIT>")<EOL>np_label = doc.vocab.strings.add("<STR_LIT>")<EOL>seen = set()<EOL>for i, word in enumerate(obj):<EOL><INDENT>if word.pos not in (NOUN, PROPN, PRON):<EOL><INDENT>continue<EOL><DEDENT>if word.i in seen:<EOL><INDENT>continue<EOL><DEDENT>if word.dep in np_deps:<EOL><INDENT>if any(w.i in seen for w in word.subtree):<EOL><INDENT>continue<EOL><DEDENT>flag = False<EOL>if word.pos == NOUN:<EOL><INDENT>for potential_nmod in word.rights:<EOL><INDENT>if potential_nmod.dep == nmod:<EOL><INDENT>seen.update(<EOL>j for j in range(word.left_edge.i, potential_nmod.i + <NUM_LIT:1>)<EOL>)<EOL>yield word.left_edge.i, potential_nmod.i + <NUM_LIT:1>, np_label<EOL>flag = True<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if flag is False:<EOL><INDENT>seen.update(j for j in range(word.left_edge.i, word.i + <NUM_LIT:1>))<EOL>yield word.left_edge.i, word.i + <NUM_LIT:1>, np_label<EOL><DEDENT><DEDENT>elif word.dep == conj:<EOL><INDENT>head = word.head<EOL>while head.dep == conj and head.head.i < head.i:<EOL><INDENT>head = head.head<EOL><DEDENT>if head.dep in np_deps:<EOL><INDENT>if any(w.i in seen for w in word.subtree):<EOL><INDENT>continue<EOL><DEDENT>seen.update(j for j in range(word.left_edge.i, word.i + <NUM_LIT:1>))<EOL>yield word.left_edge.i, word.i + <NUM_LIT:1>, np_label<EOL><DEDENT><DEDENT><DEDENT>
Detect base noun phrases. Works on both Doc and Span.