Skip to content

Description:

  • A suite of open source Python modules, data sets, and tutorials supporting research and development in Natural Language Processing

Resources:

Example utility

from nltk.util import *
print_string("This is a long string, therefore it should break", 25)

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())

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)

Parsing

import pickle
import subprocess
import sys
from nltk import Nonterminal, nonterminals, Production, CFG
nt1 = Nonterminal('NP')
nt2 = Nonterminal('VP')
nt1.symbol()

ganymede is made by Eugo