-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverbReader.py
94 lines (63 loc) · 1.67 KB
/
verbReader.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
## Copyright 2009-2012 Joey
##
## Jobot is released under Affero GPL. Please read the license before continuing.
##
## The latest source can be found here:
## https://github.com/MOSW/wallybot
##
import sys
import re
import traceback
import PorterStemmer
import pickle
try:
def _uniquify(seq, idfun=None):
# order preserving
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
# in old Python versions:
# if seen.has_key(marker)
# but in new ones:
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result
def uniquify(seq):
# not order preserving
return list({}.fromkeys(seq).keys())
def genList(fileName):
try:
f = open(fileName, 'r', buffering=1, encoding='utf8', errors='replace')
except:
input('Could not open list.')
return None
stemmer = PorterStemmer.PorterStemmer()
rawVerbs = []
for line in f:
if line[0] == ">":
rawVerbs.append(list(map(lambda x:str.lower(stemmer.stem(x,0,len(x)-1)), re.split(r'[\s\\/]', line[1:])[:-2])))
print(rawVerbs[-1])
wordlist = []
for verbs in rawVerbs:
uVerbs = uniquify(verbs)
if len(uVerbs) < 2: continue
wordlist.append(uVerbs)
return wordlist
wordlist = genList('Verblist.vrb')
wordlist.extend(genList('replaceable.txt'))
#wordlist.append(list(map(lambda x:stemmer.stem(x,0,len(x)-1),['i','you','he','she','it','we','they'])))
for i in wordlist:
print(i)
input('Continue... (dump)')
wf = open('replaceable.list', 'wb')
pickle.dump(wordlist, wf)
wf.close()
wf.close()
input('Done!')
except:
traceback.print_exc()
input()