daodejing-runze 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- daodejing_runze/__init__.py +44 -0
- daodejing_runze/data/daodejing-81.jsonl +81 -0
- daodejing_runze-1.0.0.dist-info/METADATA +63 -0
- daodejing_runze-1.0.0.dist-info/RECORD +7 -0
- daodejing_runze-1.0.0.dist-info/WHEEL +5 -0
- daodejing_runze-1.0.0.dist-info/licenses/LICENSE +438 -0
- daodejing_runze-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""道可道 · 润泽解读道德经 —— 八十一章结构化数据。
|
|
2
|
+
|
|
3
|
+
>>> import daodejing_runze as dj
|
|
4
|
+
>>> dj.chapter(1)["title"]
|
|
5
|
+
'道可道,非常道'
|
|
6
|
+
>>> [c["volume"] for c in dj.chapters()][:5]
|
|
7
|
+
['根', '根', '根', '根', '根']
|
|
8
|
+
|
|
9
|
+
作者:润泽博士(#润泽博士)。许可:CC BY-NC-SA 4.0。
|
|
10
|
+
"""
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
|
|
14
|
+
__version__ = "1.0.0"
|
|
15
|
+
_DATA = os.path.join(os.path.dirname(__file__), "data", "daodejing-81.jsonl")
|
|
16
|
+
_cache = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def chapters():
|
|
20
|
+
"""返回全部 81 章(list[dict])。字段:id/no/title/volume/scripture/notes/text。"""
|
|
21
|
+
global _cache
|
|
22
|
+
if _cache is None:
|
|
23
|
+
with open(_DATA, encoding="utf-8") as f:
|
|
24
|
+
_cache = [json.loads(line) for line in f if line.strip()]
|
|
25
|
+
return _cache
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def chapter(n):
|
|
29
|
+
"""取第 n 章(1–81)。"""
|
|
30
|
+
if not 1 <= n <= 81:
|
|
31
|
+
raise ValueError("chapter number must be 1..81")
|
|
32
|
+
return chapters()[n - 1]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def scripture(n):
|
|
36
|
+
"""取第 n 章经文(纯文本)。"""
|
|
37
|
+
return chapter(n)["scripture"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def by_volume(name):
|
|
41
|
+
"""按卷取章:根 / 动 / 生 / 落 / 还。"""
|
|
42
|
+
if name not in ("根", "动", "生", "落", "还"):
|
|
43
|
+
raise ValueError("volume must be one of 根 动 生 落 还")
|
|
44
|
+
return [c for c in chapters() if c["volume"] == name]
|