Files
Jyotisha/scripts/reader_appendix_language.py
T
jesse-uxandClaude Code f968cb2166
Independent Staging Quality Gate / validate (push) Failing after 17m57s
Independent Staging Quality Gate / publish (push) Skipped
feat(report): add dense personal report appendix
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-23 10:42:17 +08:00

46 lines
2.3 KiB
Python

"""Reader-only vocabulary projection; calculation packets and CLI stay untouched."""
from __future__ import annotations
import re
STATUS_LABELS = {
"parameter_sensitive": "参数敏感",
"pyjhora_behavior_only": "仅单一外部参照,未做多引擎核对",
"not_multiengine_parity": "仅单一外部参照,未做多引擎核对",
"unresolved_external_tuple_boundary": "外部边界未对齐",
"partial_verified": "部分核验",
"raw_appendix_only": "仅原始附录可见",
"missing_in_local": "本地暂无",
"internal_reference_omitted": "内部参照已省略",
}
CELL_LABELS = {"blocked": "暂不可用", "executed": "已执行", "available": "可用", "computed": "已计算"}
_TOKEN = re.compile(r"\b(" + "|".join(STATUS_LABELS) + r")\b")
_PRODUCT = re.compile(
r"\bPL9(?:\.pdf)?(?:[ \t]*(?:第[ \t]*\d+(?:[ \t]*[–—/-][ \t]*\d+)*[ \t]*页|"
r"(?:pages?|p)[ \t-]*\d+(?:[ \t]*[–—/-][ \t]*\d+)*))?\b|"
r"\bPL9[ \t]*第[ \t]*\d+(?:[ \t]*[–—/-][ \t]*\d+)*[ \t]*页",
re.IGNORECASE,
)
_FUNCTION = re.compile(r"\b(?:jyotish_engine\.)?(?:cmd_[a-z0-9_]+|render_pl9_markdown|build_professional_report_reference_packet)\b")
_CELL = re.compile(r"(?<=\|)([ \t]*)(`?)(blocked|executed|available|computed)\2([ \t]*)(?=\|)")
def clean_reader_appendix_markdown(markdown: str) -> str:
"""Translate copy without dropping lines, field names, or numeric cells.
Ambiguous English words are changed only as complete pipe-table cells.
Chart fences are immutable: their JSON is a separate renderer contract.
"""
parts = re.split(r"(^[ \t]*```jyotish-chart[^\n]*\n[\s\S]*?^[ \t]*```[^\n]*(?:\n|$))", markdown, flags=re.MULTILINE)
for index in range(0, len(parts), 2):
value = _TOKEN.sub(lambda match: STATUS_LABELS[match[0]], parts[index])
value = _FUNCTION.sub("本地计算", value)
value = re.sub(r"\b(?:[a-z0-9_]+pl9[a-z0-9_]*|pl9_[a-z0-9_]+)(?:\.v\d+)?\b", "外部参照资料", value, flags=re.IGNORECASE)
value = _PRODUCT.sub("外部参照资料", value)
value = re.sub(r"\b(?:PyJHora|JHora)\b", "外部参照引擎", value, flags=re.IGNORECASE)
value = _CELL.sub(lambda match: f"{match[1]}{match[2]}{CELL_LABELS[match[3]]}{match[2]}{match[4]}", value)
parts[index] = value
return "".join(parts)