Description:
- A suite of open source Python modules, data sets, and tutorials supporting research and development in Natural Language Processing
Resources:
- [GitHub] https://github.com/nltk/nltk
- [Docs] https://www.nltk.org/
- [Examples] https://www.nltk.org/howto.html
Example 1
Section titled “Example 1”Example utility
from nltk.util import *
print_string("This is a long string, therefore it should break", 25)Example 2
Section titled “Example 2”Create a tree
from nltk.tree import Tree
tree = Tree(5,[Tree(4, [Tree(2, [1, 3])]), Tree(8, [Tree(6, [7]), 9])])
for x in breadth_first(tree): if isinstance(x, int): print(x) else: print(x.label())Example 3
Section titled “Example 3”Chunking
from nltk.chunk import *from nltk.chunk.util import *from nltk.chunk.regexp import *from nltk import Tree
tagged_text = "[ The/DT cat/NN ] sat/VBD on/IN [ the/DT mat/NN ] [ the/DT dog/NN ] chewed/VBD ./."gold_chunked_text = tagstr2tree(tagged_text)unchunked_text = gold_chunked_text.flatten()print(unchunked_text)Example 4
Section titled “Example 4”Parsing
import pickleimport subprocessimport sysfrom nltk import Nonterminal, nonterminals, Production, CFG
nt1 = Nonterminal('NP')nt2 = Nonterminal('VP')nt1.symbol()ganymede is made by Eugo