-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathC_make_browser.py
More file actions
62 lines (50 loc) · 1.66 KB
/
C_make_browser.py
File metadata and controls
62 lines (50 loc) · 1.66 KB
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
from lingpy import *
wl = Wordlist('O_shijing.tsv', col='shijing', row='stanza')
# first make a link between a character in a section and its occurrence as
# rhyme word
chars = []
for k in wl:
char = wl[k,'character']
poem = wl[k,'number']
stanza = wl[k,'stanza']
section = wl[k,'section_number']
ocbs = wl[k,'ocbs']
pwy = wl[k,'pwy']
mch = wl[k,'mchascii']
pin = wl[k,'pinyin']
gls = wl[k,'och_gloss']
gsr = wl[k,'gsr']
chars += [[k, char, pin, gls, mch, ocbs, pwy, gsr, poem, stanza, section]]
# now assemble poems under their id
poems = {}
for k in wl:
poem = int(wl[k,'number'])
name = wl[k,'title']
block = wl[k,'block'] + '·'+wl[k,'chapter']
rhyme = wl[k,'rhyme']
arhyme = wl[k,'alternative_rhyme']
section = wl[k,'raw_section']
stanza = wl[k,'stanza']
ocbs = wl[k,'ocbs']
pwy = wl[k,'pwy']
mch = wl[k,'mch']
yun = wl[k,'ocbsyun']
char = wl[k,'character']
try:
poems[poem]['sections'] += [[stanza, section, rhyme, arhyme, ocbs, pwy,
mch, yun, char]]
except KeyError:
poems[poem] = { "name" : name, "block" : block }
poems[poem]['sections'] = [[stanza, section, rhyme, arhyme, ocbs, pwy,
mch, yun, char]]
import json
import os
import shutil
if not os.path.isdir('browser'):
os.mkdir('browser')
shutil.copyfile('T_main.js', 'browser/main.js')
shutil.copyfile('T_index.html', 'browser/index.html')
shutil.copyfile('T_style.css', 'browser/style.css')
with open('browser/shijing.js', 'w') as f:
f.write('var POEMS = '+json.dumps(poems,indent=2)+';\n')
f.write('var CHARS = '+json.dumps(chars,indent=2)+';\n')