-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinterlinear.py
78 lines (63 loc) · 1.93 KB
/
interlinear.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
import _mysql
import json
db=_mysql.connect("localhost","root","","default")
stat_file = open("stats_quirk.json") # without 2 ki 22, 3 john 15
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
if __name__ == "__main__":
# iterate over all the books
for b in books:
# get data
name = b["n"]
bno=str(b["b"])
data = dump_book(name, bno)
# write out
book = open("interlinear/"+name+".json", "w")
jsdata = json.dumps(data)
book.write(jsdata)