def sentence_chunk(sentence): """ Chunks a tagged sentence into syntactically correlated parts of words. """ tagged = sentence_tag(sentence) tagged = str(tagged) leaves = nltk_tree.chunk(tagged).leaves() tree = nltk_tree.Tree("", leaves) for tag, rule, desc in chunk_rules: r = nltk_chunk.ChunkRule(rule, "") chunker = nltk_chunk.RegexpChunk([r], chunk_node=tag) tree = chunker.parse(tree) return _traverse_chunktree(tree)
from nltk_lite.parse import chunk chunkParser = chunk.RegexpChunk() print chunkParser.parse(['This', 'is', 'a', 'test'])