Created
March 8, 2015 10:56
-
-
Save abevieiramota/e8ddc17a4dea903d4393 to your computer and use it in GitHub Desktop.
freqdist archive
This file contains hidden or 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
import requests | |
from bs4 import BeautifulSoup | |
import nltk | |
URL = "https://archive.org/stream/TheH.P.LovecraftNovellas/H.P.Lovecraft-TheCaseOfCharlesDexterWard.txt" | |
# https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html | |
PERMITTED_TAGS = set(['NN', 'NNS', 'NNP', 'NNPS']) | |
req = requests.get(URL) | |
soup = BeautifulSoup(req.text) | |
pre = soup.find_all('pre')[0] | |
text = pre.get_text() | |
tagged = nltk.pos_tag(nltk.word_tokenize(text)) | |
permitted_words = [word[0] for word in tagged if word[1] in PERMITTED_TAGS] | |
fd = nltk.FreqDist(permitted_words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment