Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
95 lines
4.7 KiB
Python
95 lines
4.7 KiB
Python
"""BUG-2300: one reading of the yoga engine's effect gates for every consumer.
|
|
|
|
The engine (`yoga_engine._apply_effect_and_method_gates`, upstream 58f37ee5b) moves a
|
|
gated rule's traditional effects to `traditional_effects` and empties `effects`. A
|
|
consumer that falls back to other prose (the rule's reader explanation, `interpretation`,
|
|
`summary`, an archived alias's effects) would put the traditional verdict back as a
|
|
personal conclusion. Every consumer asks here instead.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
# Her five effect statuses (upstream 58f37ee5b `detect` / `professional_parity_closure`).
|
|
GATED_EFFECT_STATUSES = frozenset({
|
|
"source_neutralized", "incomplete", "historical_medical_reference",
|
|
"historical_conduct_reference", "historical_injury_reference",
|
|
})
|
|
# Row states under which the engine withholds the traditional effects.
|
|
WITHHELD_FORMATION_STATUSES = frozenset({
|
|
"method_requires_review", "combustion_requires_review", "incomplete_conditions",
|
|
"not_implemented", "evaluation_error", "blocked",
|
|
})
|
|
|
|
# Her page sentences (upstream professional_parity_closure.build_yoga_interpretation_pack).
|
|
_RESULT_ZH = {
|
|
"historical_injury_reference": "保留传统条件与历史解释,不据此判断战争、伤害或死亡事件。",
|
|
"historical_conduct_reference": "保留传统结构与出处,不能据此认定本人或伴侣不忠。",
|
|
"historical_medical_reference": "保留传统条件与历史解释,不据此判断疾病、伤残或治疗结果。",
|
|
"source_neutralized": "原文所述作用已有缓解条件,不直接用于判断个人性格或结果。",
|
|
"incomplete": "结构已经核对,但影响其表现的条件资料不全,暂不据此判断个人性格或结果。",
|
|
}
|
|
_RESULT_EN = {
|
|
"historical_injury_reference": "The traditional condition and its historical reading are kept; no war, injury or death event is inferred.",
|
|
"historical_conduct_reference": "The traditional structure and its source are kept; no infidelity or personal conduct is established.",
|
|
"historical_medical_reference": "The traditional condition and its historical reading are kept; no illness, disability or treatment outcome is inferred.",
|
|
"source_neutralized": "The source's stated effect has a mitigating condition; it is not used to judge character or outcome.",
|
|
"incomplete": "The structure was checked, but inputs that shape its expression are missing; no character or outcome is judged from it.",
|
|
}
|
|
_METHOD_ZH = "取法尚待核定,保留候选结构,不据此写传统作用。"
|
|
_METHOD_EN = "The method is still under review; the candidate structure is kept without its traditional effect."
|
|
_OTHER_ZH = "条件没有全部核对,不据此写传统作用。"
|
|
_OTHER_EN = "Not every condition was checked; no traditional effect is stated from it."
|
|
|
|
|
|
def effect_status(row: Any) -> str | None:
|
|
"""The row's gated effect status (one of her five), or None."""
|
|
if not isinstance(row, dict):
|
|
return None
|
|
assessment = row.get("effect_assessment")
|
|
status = assessment.get("status") if isinstance(assessment, dict) else None
|
|
return status if status in GATED_EFFECT_STATUSES else None
|
|
|
|
|
|
def _formation_states(row: dict) -> set[str]:
|
|
states = {str(row.get(key) or "") for key in ("formation_status", "condition_status", "display_status")}
|
|
review = row.get("method_review")
|
|
if isinstance(review, dict) and review.get("status") == "pending":
|
|
states.add("method_requires_review")
|
|
return states
|
|
|
|
|
|
def effect_withheld(row: Any) -> bool:
|
|
"""True when the engine withheld this row's traditional effects."""
|
|
if not isinstance(row, dict):
|
|
return False
|
|
if effect_status(row) is not None:
|
|
return True
|
|
return bool(_formation_states(row) & WITHHELD_FORMATION_STATUSES)
|
|
|
|
|
|
def withheld_note(row: Any, language: str = "zh") -> str:
|
|
"""The sentence a reader sees instead of the traditional effect ('' when not withheld)."""
|
|
if not effect_withheld(row):
|
|
return ""
|
|
zh = language != "en"
|
|
status = effect_status(row)
|
|
if status is not None:
|
|
assessment = row.get("effect_assessment") or {}
|
|
summary = assessment.get("summary_zh" if zh else "summary_en")
|
|
if isinstance(summary, str) and summary.strip():
|
|
return summary.strip()
|
|
return (_RESULT_ZH if zh else _RESULT_EN)[status]
|
|
if "method_requires_review" in _formation_states(row):
|
|
return _METHOD_ZH if zh else _METHOD_EN
|
|
return _OTHER_ZH if zh else _OTHER_EN
|
|
|
|
|
|
def page_result_sentence(row: Any, language: str = "zh") -> str:
|
|
"""Her page `result` line for a gated effect status (not the summary), or ''."""
|
|
status = effect_status(row)
|
|
if status is None:
|
|
return ""
|
|
return (_RESULT_ZH if language != "en" else _RESULT_EN)[status]
|