Created
January 10, 2012 14:03
-
-
Save AlexDel/1589239 to your computer and use it in GitHub Desktop.
NLTK. Ex 2.17 Write a function that finds the 50 most frequently occurring words of a text that are not stopwords.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def freq_non_stopwords(text): | |
stopwords = nltk.corpus.stopwords.words('english') | |
clean_list = [w for w in text if w.lower() not in stopwords] #убираем частотные слова | |
freqdist = nltk.probability.FreqDist(clean_list) | |
return freqdist.keys()[:50] #возвращаем 50 первых нечастотных слов |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can we print the result