Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
105 lines
5.8 KiB
Python
105 lines
5.8 KiB
Python
"""Reader names for internal keys that reach the personal report's data chapters (BUG-2095).
|
||
|
||
The astrologer's layering rule (2026-11-19): readers never see internal codes. Several data
|
||
tables printed packet keys as they are stored (`bhrigu_bindu`, `day_lord`, `punya_saham`,
|
||
`goel_method_1_v1` ...). Technique names stay (owner 2026-11-20): a key becomes the technique's
|
||
proper name, never a lay paraphrase. Names are taken from the report's existing wording
|
||
(parity_chapters year-lord offices, tajika_mudda balance profiles, appendix_language reference
|
||
points, functional_layer_table profiles). A key with no known reader name is written in Title Case
|
||
without underscores, never translated by guess.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
from typing import Any
|
||
|
||
SNAKE_TOKEN = re.compile(r"\b[a-z]+(?:_[a-z0-9]+)+\b")
|
||
_VERSION_SUFFIX = re.compile(r"_v\d+$")
|
||
|
||
# key: (Chinese edition, English edition)
|
||
READER_KEY_NAMES: dict[str, tuple[str, str]] = {
|
||
# Sensitive points (technique names stay in both editions).
|
||
"bhrigu_bindu": ("Bhrigu Bindu", "Bhrigu Bindu"),
|
||
"sarpa_drekkana": ("Sarpa Drekkana", "Sarpa Drekkana"),
|
||
# Tajika year-lord offices: same words as parity_chapters._YEAR_LORD_OFFICES.
|
||
"new_year_lord": ("年首星座主", "Lord of the year's opening sign"),
|
||
"natal_lagna_lord": ("本命上升主", "Natal Lagna lord"),
|
||
"muntha_lord": ("Muntha 主星", "Muntha lord"),
|
||
"varsha_lagna_lord": ("年盘上升主", "Annual Lagna lord"),
|
||
"tri_rasi_lord": ("Tri-rasi 主", "Tri-rasi lord"),
|
||
# KP ruling planets.
|
||
"day_lord": ("日主", "Day lord"),
|
||
"moon_sign_lord": ("月亮星座主", "Moon sign lord"),
|
||
"moon_star_lord": ("月亮星宿主", "Moon star lord"),
|
||
"moon_sub_lord": ("月亮子主", "Moon sub lord"),
|
||
"ascendant_sign_lord": ("上升星座主", "Ascendant sign lord"),
|
||
"ascendant_star_lord": ("上升星宿主", "Ascendant star lord"),
|
||
"ascendant_sub_lord": ("上升子主", "Ascendant sub lord"),
|
||
# KP house basis.
|
||
"explicit_cusps": ("按实际宫头度数", "Explicit cusp degrees"),
|
||
"cusp_to_cusp": ("宫头到下一宫头", "Cusp to next cusp"),
|
||
# Annual table column (Chinese: appendix_language.FIELD_ZH).
|
||
"boundary_status": ("边界状态", "Boundary status"),
|
||
# Annual anchors.
|
||
"asc_sign": ("年盘上升", "Annual ascendant"),
|
||
# Mudda balance profiles: the words the Chinese edition already used (pl9_full_data_export).
|
||
"moon_at_birth_time": ("出生时月亮", "Moon at birth"),
|
||
"moon_in_varshaphala": ("年盘月亮", "Annual-chart Moon"),
|
||
"without_dasha_balance": ("不计余额", "No opening balance"),
|
||
# Sudarshana reference points (Chinese: appendix_language.REFERENCE_POINT_ZH).
|
||
"ascendant_lagna": ("出生上升参考点", "Birth Ascendant reference"),
|
||
"moon_lagna": ("月亮参考点", "Moon reference"),
|
||
"sun_lagna": ("太阳参考点", "Sun reference"),
|
||
# Yoga categories without an existing reader word.
|
||
"chandra_extended": ("月亮类(扩展)", "Chandra (extended)"),
|
||
"neecha_bhanga": ("Neecha Bhanga", "Neecha Bhanga"),
|
||
# Rashi dasha method profiles: the author or book stays named; the version code is not printed.
|
||
"goel_full_brahma_ch1_ch5_v1": ("Goel 完整 Brahma 法", "Goel's full Brahma method"),
|
||
"goel_rao_short_brahma_method_v1": ("K.N. Rao 简法 Brahma", "K.N. Rao short Brahma method"),
|
||
"goel_method_1_v1": ("Goel 第一法", "Goel method 1"),
|
||
"kn_rao": ("K.N. Rao 法", "K.N. Rao method"),
|
||
"drig_rath_aspect_sequence_v1": ("Drig 相位顺序(Rath)", "Drig aspect sequence (Rath)"),
|
||
"kendradi_narayana_duration_candidate_v1": ("Kendradi 顺序加 Narayana 年数", "Kendradi order with Narayana years"),
|
||
"pvr_niryaana_shoola_v1": ("PVR Niryaana Shoola", "PVR Niryaana Shoola"),
|
||
"shoola_forward_md_direct_ad_v1": ("Shoola 大运顺排、小运直排", "Shoola: Mahadasha forward, Antardasha direct"),
|
||
"jaimini_odd_footed_v1": ("Jaimini 奇数足排法", "Jaimini odd-footed method"),
|
||
# Functional profiles (functional_layer_table._PROFILE_SHORT).
|
||
"pvr_table30_v1": ("PVR 表 30", "PVR Table 30"),
|
||
"bphs_exception_profile": ("BPHS 例外表", "BPHS exception table"),
|
||
# Conditional-evidence words in the technique audit.
|
||
"parameter_sensitive": ("结果会随算法设置变化", "results change with the calculation settings"),
|
||
"profile_sensitive": ("结果会随所选口径变化", "results change with the chosen profile"),
|
||
"single_system_inference": ("只有一种方法给出", "given by one method only"),
|
||
"unclosed_divisional_chart": ("相关分盘还没有核定", "the divisional chart is not settled yet"),
|
||
"user_history_verification_required": ("需要对照本人经历核对", "needs checking against the person's own history"),
|
||
}
|
||
|
||
|
||
def title_case_key(raw: str) -> str:
|
||
"""`punya_saham` -> `Punya Saham`; a trailing version code (`_v1`) is dropped."""
|
||
|
||
words = _VERSION_SUFFIX.sub("", raw).split("_")
|
||
return " ".join(word[:1].upper() + word[1:] for word in words if word)
|
||
|
||
|
||
def reader_key(value: Any, language: str, title_case: bool = True) -> Any:
|
||
"""Reader name for an internal key; any other value is returned unchanged.
|
||
|
||
``title_case=False`` is for generic tables whose other keys the edition's later word pass
|
||
already translates (`dt_local` -> 本地时间): only keys named above are replaced there.
|
||
"""
|
||
|
||
if not isinstance(value, str):
|
||
return value
|
||
raw = value.strip()
|
||
names = READER_KEY_NAMES.get(raw)
|
||
if names:
|
||
return names[1] if language == "en" else names[0]
|
||
if title_case and SNAKE_TOKEN.fullmatch(raw):
|
||
fallback = raw[:-len("_fallback")] if raw.endswith("_fallback") else None
|
||
if fallback and fallback in READER_KEY_NAMES:
|
||
return reader_key(fallback, language)
|
||
return title_case_key(raw)
|
||
return value
|