Ben Chuanlong Du's Blog

It is never too late to learn.

Nature Language Processing Using NLTK

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

nltk.util.ngrams nltk.bigrams nltk.PorterStemmer

from nltk.util import ngrams
sentence = 'this is a foo bar sentences and i want to ngramize it'
n = 6
sixgrams = ngrams(sentence.split(), n)
for grams in sixgrams:
    print grams

Comments