Skip to content

Instantly share code, notes, and snippets.

@AlexDel
Created January 11, 2012 07:39
Show Gist options
  • Save AlexDel/1593588 to your computer and use it in GitHub Desktop.
Save AlexDel/1593588 to your computer and use it in GitHub Desktop.
NLTK EX 2.20 Write a function word_freq() that takes a word and the name of a section of the Brown Corpus as arguments, and computes the frequency of the word in that section of the corpus.
def word_freq(word, section):
freq = nltk.probability.FreqDist(nltk.corpus.brown.words(categories = section))
word_frequency = freq[word]
return word_frequency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment