0% found this document useful (0 votes)
11 views3 pages

NLP7

The document describes a Python program that uses the NLTK library for chunking sentences. It defines a grammar for noun phrases and applies it to a sample sentence, 'The dog barked at the cat'. The program outputs the tagged words and visualizes the chunking results using a tree structure.

Uploaded by

Yash Chhaproo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

NLP7

The document describes a Python program that uses the NLTK library for chunking sentences. It defines a grammar for noun phrases and applies it to a sample sentence, 'The dog barked at the cat'. The program outputs the tagged words and visualizes the chunking results using a tree structure.

Uploaded by

Yash Chhaproo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXP 7: CHUNKING

PROGRAM:
import nltk
txt = "The dog barked at the cat"
grammar = ('''
NP: {<DT>?<JJ>*<NN>} # NP
''')
chunkParser = nltk.RegexpParser(grammar)
tagged = nltk.pos_tag(nltk.word_tokenize(txt))
print(tagged)
tree = chunkParser.parse(tagged)
for subtree in tree.subtrees():
print(subtree)
tree.draw()

OUTPUT:

You might also like