Files
999/scripts/stamp_native_scripts.py
T

183 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Fill original scripts: Hebrew, classical hanzi, Arabic geomantic names."""
from __future__ import annotations
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
CANON = ROOT / "oracle_enricher" / "data" / "traditions_canon.json"
ASSET = ROOT / "assets" / "data" / "traditions_canon.json"
HTML = ROOT / "lexicon_viewer.html"
SEPHIROTH_HEBREW = {
"kether": "כתר",
"chokmah": "חכמה",
"binah": "בינה",
"chesed": "חסד",
"geburah": "גבורה",
"tiphereth": "תפארת",
"netzach": "נצח",
"hod": "הוד",
"yesod": "יסוד",
"malkuth": "מלכות",
}
TRIGRAM_HANZI = {
"qian": "乾",
"kun": "坤",
"zhen": "震",
"kan": "坎",
"gen": "艮",
"xun": "巽",
"li": "離",
"dui": "兌",
}
# King Wen order, traditional characters (Zhou Yi)
GEOMANCY_ARABIC = {
"via": ("الطريق", "ат-Тарик", "Via", "Путь"),
"populus": ("الجماعة", "аль-Джама'а", "Populus", "Народ"),
"conjunctio": ("الاجتماع", "аль-Иджтима'", "Conjunctio", "Соединение"),
"carcer": ("الحبس", "аль-Хабс", "Carcer", "Тюрьма"),
"fortuna_major": ("النصرة الداخلة", "ан-Насра ад-Дахиля", "Fortuna Major", "Большая Удача"),
"fortuna_minor": ("النصرة الخارجة", "ан-Насра аль-Хариджа", "Fortuna Minor", "Малая Удача"),
"acquisitio": ("القبض الداخل", "аль-Кабд ад-Дахиль", "Acquisitio", "Приобретение"),
"amissio": ("القبض الخارج", "аль-Кабд аль-Харидж", "Amissio", "Потеря"),
"laetitia": ("الفرح", "аль-Фарах", "Laetitia", "Радость"),
"tristitia": ("الحزن", "аль-Хузн", "Tristitia", "Печаль"),
"puella": ("نقي الخد", "наки аль-хадд", "Puella", "Девушка"),
"puer": ("الانكيس", "аль-Анкийс", "Puer", "Юноша"),
"albus": ("البياض", "аль-Байяд", "Albus", "Белый"),
"rubeus": ("الحمرة", "аль-Хумра", "Rubeus", "Красный"),
"caput_draconis": ("رأس الجوزهر", "ра'с аль-джузхар", "Caput Draconis", "Голова Дракона"),
"cauda_draconis": ("ذنب الجوزهر", "занаб аль-джузхар", "Cauda Draconis", "Хвост Дракона"),
}
HEX_HANZI = {
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: "未濟",
}
def main() -> None:
canon = json.loads(CANON.read_text(encoding="utf-8"))
for st in canon["kabbalah"]["stations"]:
he = SEPHIROTH_HEBREW.get(st["id"])
if he:
st["hebrew"] = he
for st in canon["iching"]["stations"]:
sid = st["id"]
if sid in TRIGRAM_HANZI:
st["hanzi"] = TRIGRAM_HANZI[sid]
continue
if sid.startswith("hex_"):
n = int(sid.split("_")[1])
hz = HEX_HANZI.get(n)
if hz:
st["hanzi"] = hz
for i, st in enumerate(canon["geomancy"]["stations"], start=1):
rec = GEOMANCY_ARABIC.get(st["id"])
if not rec:
continue
script, latn, latin, ru = rec
st["arabic"] = script
st["name"] = f"{i} {latin} ({latn} / {ru})"
text = json.dumps(canon, ensure_ascii=False, indent=2) + "\n"
CANON.write_text(text, encoding="utf-8")
ASSET.write_text(text, encoding="utf-8")
html = HTML.read_text(encoding="utf-8")
start = html.find(" const TRADITIONS_CANON = ")
end = html.find(" const WORDS_DATA = ")
if start > 0 and end > start:
html = (
html[:start]
+ " const TRADITIONS_CANON = "
+ json.dumps(canon, ensure_ascii=False, indent=2)
+ ";\n\n"
+ html[end:]
)
HTML.write_text(html, encoding="utf-8")
kb = [(s["id"], s.get("hebrew"), s["name"]) for s in canon["kabbalah"]["stations"]]
print("sephiroth", kb)
ich = canon["iching"]["stations"]
print("trigrams", [(s["id"], s.get("hanzi"), s["name"]) for s in ich if not s["id"].startswith("hex_")])
print("hex sample", [(s["id"], s.get("hanzi"), s["name"]) for s in ich if s["id"].startswith("hex_")][:5])
print("hex 64", ich[-1]["id"], ich[-1].get("hanzi"), ich[-1]["name"])
missing = [s["id"] for s in ich if not s.get("hanzi")]
print("missing hanzi", missing)
geo = [(s["id"], s.get("arabic"), s["name"]) for s in canon["geomancy"]["stations"]]
print("geomancy", geo)
if __name__ == "__main__":
main()