Owner 2026-11-21: after BUG-2115 the full-data report still printed source lines and book references (Goel 出处 line, the PVR 2014 article in the conditional-dasha note, PVR / Light on Life / BPHS verse in the calculation notes, Tithi lord table source, rashi-dasha 出处 lines, Narayana p.43 label and p.50 / Table 13 direction notes, functional profile source row, Ashtakavarga book calibration). Method names stay; the book, page, chapter and ruling round go. Engine labels for the consultation card are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
"""BUG-2129: book page / table / chapter references are not shown to the reader.
|
||
|
||
Owner 2026-11-21: the report shows the data and the method's name, never the book,
|
||
author's page, table number, chapter or internal ruling round it was taken from.
|
||
Engine packets keep those references for the backstage record; the report strips
|
||
a parenthetical that carries one.
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
|
||
_REF = (
|
||
r"(?:p\.\s?\d|pp\.\s?\d|Table\s?\d|Tables\s?\d|第\s?\d+\s?章|ch\.\s?\d|chapter\s\d|J\.S\.|§\s?\d"
|
||
r"|第[一二三四五六七八九十]+轮|round-\d|印页|印刷页|PDF\s?页)"
|
||
)
|
||
_NUMBER_IN_PARENS = re.compile(r"\((\d+)\)")
|
||
_ZH_GROUP = re.compile(r"([^()]*" + _REF + r"[^()]*)")
|
||
_EN_GROUP = re.compile(r"\s?\([^()]*" + _REF + r"[^()]*\)")
|
||
# A citation that opens the text itself: "J.S. 2.4.31–32 …", "p.50 规则 12 与注 2 …".
|
||
_LEADING = re.compile(
|
||
r"^(?:J\.S\.\s?[\d.\-–]+\s?|p\.\s?\d+\s?(?:规则|rule)\s?\d+,?\s?(?:与|and)?\s?(?:注|note)\s?\d+\s?)"
|
||
)
|
||
|
||
|
||
def strip_book_refs(text: str) -> str:
|
||
"""The text without any parenthetical holding a book page, table, chapter or ruling round."""
|
||
if not isinstance(text, str) or not text:
|
||
return text
|
||
flat = _NUMBER_IN_PARENS.sub(r"\1", text)
|
||
stripped = _LEADING.sub("", _EN_GROUP.sub("", _ZH_GROUP.sub("", flat)))
|
||
return stripped if stripped != flat else text
|