-
Notifications
You must be signed in to change notification settings - Fork 58
Release #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Release #52
Changes from all commits
2a632ef
adf06a8
38ef318
7a9770e
ed3b36c
26633f2
b126fb8
f1648ae
36c6aaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # TextMining | ||
| This is the base repo for the text mining and analysis project for Software Design, Spring 2016 at Olin College. | ||
| https://github.com/msausville/TextMining/blob/master/Finalwriteup.pdf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from bs4 import BeautifulSoup | ||
| import requests | ||
| from numpy.random import choice | ||
|
|
||
|
|
||
| """ | ||
| Function that pulls text from web | ||
| """ | ||
| megalist = [] | ||
| markovdict = {} | ||
| # print("in global scope", id(markovdict)) | ||
| def words_from_internet(link='http://www.olin.edu/academic-life/student-affairs-resources/student-life/honor-code/', start='The Olin Honor Code Values', stop='Quick Links'): | ||
| html = BeautifulSoup(requests.get(link).text, 'lxml') | ||
| startpoint = html.get_text().find(start) | ||
| stoppoint = html.get_text().find(stop) | ||
|
|
||
| honor = html.get_text()[startpoint:stoppoint] | ||
| listhonor = str(honor).split() | ||
|
|
||
| # Combing all text into listhonor | ||
| return megalist.extend(listhonor) | ||
|
|
||
|
|
||
| """ | ||
| Make dictionary | ||
| """ | ||
|
|
||
|
|
||
| def markov(megalist): | ||
| i = 0 | ||
| # print("in markov", id(markovdict)) | ||
| for i in range(len(megalist)-1): | ||
| if megalist[i] not in markovdict: | ||
| markovdict[megalist[i]] = [] | ||
| markovdict[megalist[i]].append(megalist[i+1]) | ||
| return markovdict | ||
|
|
||
|
|
||
| def smushit(markovdict, megalist): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use a bit more by way of documentation. You've cleaned up the script/jumbles into clean functions, but it's not immediately clear what the functions themselves do. |
||
|
|
||
| finallist = [] | ||
| capitals = filter(lambda x: x.lower() != x, megalist) | ||
| word = choice(list(capitals)) | ||
| finallist.append(word) | ||
| while not word.endswith("."): | ||
| finallist.append(word) | ||
| return " ".join(finallist) | ||
|
|
||
|
|
||
| def main_important_part(): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, not the ideal name, but it gets the point across! |
||
| words_from_internet(link='http://www.olin.edu/academic-life/student-affairs-resources/student-life/honor-code/', | ||
| start='The Olin Honor Code Values', stop='Quick Links') | ||
| words_from_internet(link='https://en.wikipedia.org/wiki/Felony', | ||
| start='Broadly, felonies', stop='are the least serious') | ||
| words_from_internet(link='http://www.olin.edu', | ||
| start='At Olin', stop='institutions.') | ||
| markov(megalist) | ||
| print(smushit(markovdict, megalist)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main_important_part() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: commented test code.