Skip to content

Commit 7e3a67d

Browse files
committed
render dpd from db
1 parent 9cc91cb commit 7e3a67d

File tree

168 files changed

+228401
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+228401
-1160
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
appdata.sqlite3
22
*.log
33
tests/data/assets/
4+
node_modules/
5+
profile_time_chart.png
46

57
# build folders
68
build/

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ bootstrap-db:
3434

3535
count-code:
3636
tokei --type Python --exclude simsapa/assets/ --exclude simsapa/keyboard/ --exclude simsapa/app/lookup.py . | grep -vE '===|Total'
37+
38+
simsapa.js:
39+
npx webpack
40+
41+
profile_time_chart.png:
42+
@gnuplot < scripts/profile_time_chart.gp

package-lock.json

+1,731
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "simsapa",
3+
"version": "0.1.0",
4+
"description": "A sutta reader and Pali dictionary application.",
5+
"main": "",
6+
"scripts": {},
7+
"author": "Gambhiro",
8+
"license": "GPLv3",
9+
"devDependencies": {
10+
"sass": "^1.69.5",
11+
"ts-loader": "^9.5.1",
12+
"typescript": "^5.3.3",
13+
"webpack": "^5.89.0",
14+
"webpack-cli": "^5.1.4"
15+
}
16+
}

poetry.lock

+838-851
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ tantivy = { git = "https://github.com/simsapa/tantivy-py.git", branch = "simsapa
8989
# tantivy = { git = "https://github.com/simsapa/tantivy-py.git", branch = "simsapa", rev = "229c10213b32de3ad4c905c2e968798f693afc28" }
9090
# tantivy = { path = "../libs-src/tantivy-py-simsapa", develop = true }
9191
# tantivy = { path = "../libs-src/tantivy-py-simsapa/target/wheels/tantivy-0.20.2rc4-cp311-cp311-manylinux_2_34_x86_64.whl" }
92+
colorama = "^0.4.6"
93+
blessings = "^1.7"
9294

9395
[tool.poetry.scripts]
9496
simsapa = 'simsapa.runner:main'

scripts/bootstrap_appdata.py

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def main():
146146

147147
multi_refs.populate_sutta_multi_refs(appdata_db, limit)
148148

149-
# FIXME improve synonym parsing
150149
populate_dict_words_from_stardict(appdata_db, stardict_base_path, ignore_synonyms=True, limit=limit)
151150

152151
# === All dict words are added above ===

scripts/cst4.py

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
logger.error("Missing env variable: BOOTSTRAP_ASSETS_DIR")
2727
sys.exit(1)
2828

29+
assert(s is not None)
30+
2931
bootstrap_assets_dir = Path(s)
3032

3133
CST4_DIR = bootstrap_assets_dir.joinpath('cst4')
@@ -1178,6 +1180,7 @@ def _parse_path(p: Path) -> Am.Sutta:
11781180
title_ascii = title_ascii,
11791181
uid = uid,
11801182
sutta_ref = uid,
1183+
nikaya = helpers.uid_to_nikaya(uid),
11811184
language = lang,
11821185
content_html = body,
11831186
content_plain = compact_rich_text(body),
@@ -1288,6 +1291,7 @@ def group_to_sutta(g: Group) -> Am.Sutta:
12881291
title_pali = consistent_nasal_m(g.title),
12891292
uid = uid,
12901293
sutta_ref = helpers.uid_to_ref(ref),
1294+
nikaya = helpers.uid_to_nikaya(ref),
12911295
language = lang,
12921296
content_html = content_html,
12931297
content_plain = compact_rich_text(content_html),

scripts/dhammapada_munindo.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def parse_sutta(p: Path) -> Am.Sutta:
6767
title_pali = '',
6868
uid = uid,
6969
sutta_ref = helpers.uid_to_ref(ref),
70+
nikaya = helpers.uid_to_nikaya(ref),
7071
language = lang,
7172
content_html = content_html,
7273
content_plain = compact_rich_text(content_html),

scripts/dhammapada_tipitaka_net.py

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def parse_sutta(ref: str, content_html: str) -> Am.Sutta:
8686
title_pali = title_pali,
8787
uid = uid,
8888
sutta_ref = helpers.uid_to_ref(ref),
89+
nikaya = helpers.uid_to_nikaya(ref),
8990
language = lang,
9091
content_html = content_html,
9192
content_plain = compact_rich_text(content_html),

scripts/dhammatalks_org.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from simsapa import logger
1717

1818
import helpers
19-
from simsapa.app.helpers import consistent_nasal_m, compact_rich_text, pali_to_ascii
19+
from simsapa.app.helpers import consistent_nasal_m, compact_rich_text
2020
from simsapa.app.lookup import DHP_CHAPTERS_TO_RANGE
2121
from simsapa.app.types import QueryType
2222

@@ -127,7 +127,6 @@ def parse_sutta(p: Path) -> Am.Sutta:
127127
title = title.replace('&nbsp;', '')
128128
title = title.replace('&amp;', 'and')
129129
title = consistent_nasal_m(title)
130-
title_ascii = pali_to_ascii(title)
131130

132131
if '/Ud/' in f"{p}":
133132
# 2 Appāyuka Sutta | Short-lived
@@ -159,6 +158,7 @@ def parse_sutta(p: Path) -> Am.Sutta:
159158
title_pali = title_pali,
160159
uid = uid,
161160
sutta_ref = helpers.uid_to_ref(ref),
161+
nikaya = helpers.uid_to_nikaya(ref),
162162
language = lang,
163163
content_html = content_html,
164164
content_plain = compact_rich_text(content_html),

scripts/dpd.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
3+
def main():
4+
pass
5+
6+
if __name__ == "__main__":
7+
main()

scripts/helpers.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_simsapa_db(db_path: Path, schema: DbSchemaName, remove_if_exists: bool)
3737
if remove_if_exists and db_path.exists():
3838
db_path.unlink()
3939

40-
find_or_create_db(db_path, schema.value)
40+
find_or_create_db(db_path, schema)
4141

4242
try:
4343
# Create an in-memory database
@@ -47,8 +47,12 @@ def get_simsapa_db(db_path: Path, schema: DbSchemaName, remove_if_exists: bool)
4747

4848
if schema == DbSchemaName.AppData:
4949
db_conn.execute(text(f"ATTACH DATABASE '{db_path}' AS appdata;"))
50-
else:
50+
elif schema == DbSchemaName.UserData:
5151
db_conn.execute(text(f"ATTACH DATABASE '{db_path}' AS userdata;"))
52+
elif schema == DbSchemaName.Dpd:
53+
db_conn.execute(text(f"ATTACH DATABASE '{db_path}' AS dpd;"))
54+
else:
55+
raise Exception(f"Unknown schema_name: {schema}")
5256

5357
Session = sessionmaker(engine)
5458
Session.configure(bind=engine)
@@ -78,6 +82,10 @@ def uid_to_ref(uid: str) -> str:
7882

7983
return uid
8084

85+
def uid_to_nikaya(uid: str) -> str:
86+
'''sn12.23 to sn'''
87+
nikaya = re.sub(r'^([a-z]+).*', r'\1', uid)
88+
return nikaya
8189

8290
def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> Optional[UMultiRef]:
8391
ref_text = ref_text.lower()
@@ -133,13 +141,15 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
133141
edition = "1st ed. Feer (1884)",
134142
)
135143

136-
else:
144+
elif schema == DbSchemaName.UserData:
137145
item = Um.MultiRef(
138146
collection = collection,
139147
ref_type = "pts",
140148
ref = normalize_sutta_ref(ref_text),
141149
edition = "1st ed. Feer (1884)",
142150
)
151+
else:
152+
raise Exception("Only appdata and userdata schema are allowed.")
143153

144154
return item
145155

@@ -154,14 +164,17 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
154164
edition = "2nd ed. Somaratne (1998)",
155165
)
156166

157-
else:
167+
elif schema == DbSchemaName.UserData:
158168
item = Um.MultiRef(
159169
collection = collection,
160170
ref_type = "pts",
161171
ref = normalize_sutta_ref(ref_text),
162172
edition = "2nd ed. Somaratne (1998)",
163173
)
164174

175+
else:
176+
raise Exception("Only appdata and userdata schema are allowed.")
177+
165178
return item
166179

167180
refs = []
@@ -184,13 +197,16 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
184197
ref = ", ".join(refs),
185198
)
186199

187-
else:
200+
elif schema == DbSchemaName.UserData:
188201
item = Um.MultiRef(
189202
collection = collection,
190203
ref_type = "pts",
191204
ref = ", ".join(refs),
192205
)
193206

207+
else:
208+
raise Exception("Only appdata and userdata schema are allowed.")
209+
194210
return item
195211

196212
# Ref may contain roman numerals.
@@ -210,13 +226,16 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
210226
ref = ", ".join(refs),
211227
)
212228

213-
else:
229+
elif schema == DbSchemaName.UserData:
214230
item = Um.MultiRef(
215231
collection = collection,
216232
ref_type = "pts",
217233
ref = ", ".join(refs),
218234
)
219235

236+
else:
237+
raise Exception("Only appdata and userdata schema are allowed.")
238+
220239
return item
221240

222241
return None

scripts/nyanadipa.py

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def parse_sutta(p: Path) -> Am.Sutta:
6464
title_pali = '',
6565
uid = uid,
6666
sutta_ref = helpers.uid_to_ref(ref),
67+
nikaya = helpers.uid_to_nikaya(ref),
6768
language = lang,
6869
content_html = content_html,
6970
content_plain = compact_rich_text(content_html),

scripts/profile_time_chart.gp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
set key off
2+
3+
set terminal png size 1500,600
4+
# set terminal pngcairo size 1200,500 enhanced font 'Helvetica,15'
5+
set output 'profile_time_chart.png'
6+
7+
# set xlabel "Time"
8+
set ylabel "Δt since last point"
9+
10+
set yrange [0:]
11+
set xrange [0:]
12+
set datafile separator "\t"
13+
14+
set xtics out nomirror
15+
16+
set style fill solid
17+
18+
#set xtics time format "%tM:%.3tS"
19+
#set xtics rotate by 90 offset 0.0,-4.5
20+
#set bmargin 20
21+
22+
set xtics time format "%tM:%S"
23+
set xtics rotate by 90 offset 0.0,-2.5
24+
set bmargin 17
25+
26+
## Evenly spaced bars.
27+
# set boxwidth 0.2
28+
# plot "profile_time.dat" using ($0+0.25):1:xtic(2) with boxes notitle, \
29+
# '' using ($0+0.25):1:1 with labels offset 0.5,0.5 notitle
30+
31+
# X axis is elapsed total time.
32+
# Y axis is a box plot, delta time since last point.
33+
# Place delta time number above the box.
34+
# Drop the delta time label if it is 0, by replacing it with an invalid value 1/0.
35+
# Place the label text under the X axis.
36+
set boxwidth 0.5
37+
plot "profile_time.dat" using 1:2 with boxes notitle, \
38+
'' using 1:($2 != 0 ? $2 : 1/0):2 with labels offset 0.5,1.0 font ',12' notitle, \
39+
'' using 1:($2 != 0 ? 0 : 0):3 with labels right offset 0.0,-5.0 rotate by 90 font ',10' notitle

scripts/sanskrit_texts.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def get_gretil_suttas(limit: Optional[int] = None) -> List[Am.Sutta]:
102102
title_pali = "",
103103
uid = uid,
104104
sutta_ref = "",
105+
nikaya = "",
105106
language = lang,
106107
content_html = content_html,
107108
content_plain = compact_rich_text(content_html),
@@ -136,7 +137,8 @@ def populate_from_sanskrit_to_appdata(sanskrit_db: Session, appdata_db: Session)
136137
for i in res:
137138
sanskrit_db.expunge(i)
138139
make_transient(i)
139-
i.id = None
140+
# Cannot assign member "id" for type "Sutta"
141+
# i.id = None
140142

141143
appdata_db.add(i)
142144
appdata_db.commit()

0 commit comments

Comments
 (0)