-
Notifications
You must be signed in to change notification settings - Fork 8
/
lexicon.py
94 lines (78 loc) · 2.44 KB
/
lexicon.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
import _mysql
import json
db=_mysql.connect("localhost","root","","lexicon_hebrew")
stat_file = open("stats_quirk.json")
stats = json.load(stat_file)
book_file = open("books.json")
books = json.load(book_file)
def dump_book(name, bno):
interlinear = []
# get num chapters
nchapters = int(len(stats[bno].keys()))
print (name, nchapters)
# iterate over each chapter of the book
for i in xrange(1,nchapters+1):
cno = str(i)
nverses = int(stats[bno][cno])+1
for j in xrange(1,nverses):
vno = str(j)
db.query("""select strongs from bible_original where book={} and chapter={} and verse={}""".format(bno, cno, vno))
r=db.use_result()
words = []
doc_id = "{}{}{}".format(bno.zfill(2), cno.zfill(3), vno.zfill(3))
# load json chapter
path="src/"+name+"/"
filename = path+cno+".json"
i = 0
with open(filename) as data_file:
# get the unordered json verse
uverse = json.load(data_file)[vno]
while True:
val = r.fetch_row()
if len(val) == 0:
break
# get strongs num
strongs_prefix = 'h'
if int(bno) >= 40:
strongs_prefix = 'g'
strongs = strongs_prefix+val[0][0]
# lookup interlinear text
match = [v for v in uverse if v['number'] == strongs]
# append word
doc = None
if len(match) > 0:
doc = match[0]
else:
doc = {"text": "", "number": strongs}
doc["i"] = i
words.append(doc)
i += 1
# append verse
interlinear.append({"id": doc_id, "verse": words})
return interlinear
def filter_func(char):
return char == '\n' or 32 <= ord(char) <= 126
if __name__ == "__main__":
db.query("""select * from lexicon_hebrew""")
r=db.use_result()
# id, strongs, base_word, data, usage
lexicon = []
while True:
row = r.fetch_row()
if len(row) == 0:
break
val = row[0]
_id = val[0]
strongs = "h"+val[1]
base_word = val[2]
usage = filter(filter_func, val[4]).lower()
filtered_data = filter(filter_func, val[3]).lower()
data = json.loads(filtered_data)
del data["pronun"]
doc = {"strongs": strongs,
"word": usage,
"data": data}
lexicon.append(doc)
output = open("lexicon/hebrew.json", "w")
jsdata = json.dumps(lexicon)
output.write(jsdata)