def dispersion_plot(self, words): """ Produce a plot showing the distribution of the words through the text. Requires pylab to be installed. :param words: The words to be plotted :type words: list(str) :seealso: nltk.draw.dispersion_plot() """ from nltk.draw import dispersion_plot dispersion_plot(self, words)
def dispersion_plot(self, words): """ Produce a plot showing the distribution of the words through the text. Requires pylab to be installed. :param words: The words to be plotted :type word: str :seealso: nltk.draw.dispersion_plot() """ from nltk.draw import dispersion_plot dispersion_plot(self, words)
# dispersion_example.py # uses nltk v0.9.5 # # plots dispersion of word occurences in # Sense and Sensibility by Jane Austen from nltk.corpus import gutenberg from nltk.draw import dispersion_plot words = ['Elinor', 'Marianne', 'Edward', 'Willoughby'] dispersion_plot(gutenberg.words('austen-sense.txt'), words)
# plots dispersion of word occurences in # Sense and Sensibility by Jane Austen from nltk.corpus import gutenberg from nltk.draw import dispersion_plot from nltk import stem p = stem.PorterStemmer() text = gutenberg.words('austen-sense.txt') words = ['walking','talking','hunting'] vocab = set(text) #build a vocabulary for word in vocab: if p.stem(word) == 'walk' or p.stem(word) == 'talk' or p.stem(word) =='hunt': words.append(word) dispersion_plot(gutenberg.words('austen-sense.txt'), words)