-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindOrigins.py
45 lines (35 loc) · 978 Bytes
/
findOrigins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import nltk
from nltk.corpus import wordnet as wn
from bs4 import BeautifulSoup
import urllib3
import html5lib
from tqdm import tqdm
def findOrigins(word):
urllib3.disable_warnings()
http = urllib3.PoolManager()
url = "http://www.dictionary.com/browse/antique"
response = http.request('GET', url)
soup = BeautifulSoup(response.data, "lxml")
ety = soup.findAll("a", {"class": "language-name"})
fin_ety = []
if len(ety) != 0:
for i in range(len(ety)):
fin_ety.append(ety[i].text)
return fin_ety
def rep(word):
return word.replace('_',' ')
words = []
for word in wn.words():
ts = rep(word)
words.append(ts)
origins = set()
for i in tqdm(range(len(words)), desc = 'Progress'):
if len(findOrigins(words[i])) != 0:
o = findOrigins(words[i])
for j in range(len(o)):
origins.add(o[j])
if i % 1000 == 0:
with open('interim_origins.txt', 'w') as f:
f.write(str(origins))
with open('origins.txt', 'w') as myFile:
myFile.write(str(origins))