fix(yoga): astrologer 11-25 review items 4–8 — Raja structure formed with modifiers, exchange recall by houses, actual vs illustrated diagrams (BUG-2392)
Owner approved the yoga_engine.py change for items 4, 5, 6 and 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
This commit is contained in:
@@ -318,6 +318,18 @@ function ruleDiagram(id: string, bodies: Record<string, Body>, rules: Record<str
|
||||
return found.length ? { kind: "set", bodies: found.slice(0, 4), label: found.map(zh).join("、") } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2392 (占星师 11-25 第八项): the engine's matched participants draw this chart's actual configuration.
|
||||
* When the engine names none, the diagram is read from the rule's sentence (BUG-2387) and its caption says
|
||||
* it is an illustration of the rule, not the matched branch.
|
||||
*/
|
||||
function actualOrIllustration(row: Row, bound: string[], bodies: Record<string, Body>, rules: Record<string, number[]>): YogaDiagram {
|
||||
const diagram = rowDiagram(row, bound, bodies, rules);
|
||||
const wholeChart = diagram.kind === "spread" || diagram.kind === "chain" || diagram.kind === "none";
|
||||
if (bound.length || wholeChart) return diagram;
|
||||
return { ...diagram, label: `示意:${diagram.label}` };
|
||||
}
|
||||
|
||||
function rowDiagram(row: Row, bound: string[], bodies: Record<string, Body>, rules: Record<string, number[]> = {}): YogaDiagram {
|
||||
const category = String(row.category ?? "");
|
||||
const id = String(row.rule_id ?? "");
|
||||
@@ -436,8 +448,11 @@ export function buildYogaGroups(input: Readonly<{
|
||||
// A one-body yoga and a one-body structure on that body are the same fact (萨萨 and 7th lord in its own sign).
|
||||
if (planets.length === 1 && !formedPlanets.has(planets[0]!)) formedPlanets.set(planets[0]!, name);
|
||||
categories.set(id, String(row.category ?? ""));
|
||||
// BUG-2392 (占星师 11-25 第五项): a formed kendra–trikona Raja yoga keeps its modifier in plain words.
|
||||
const note = text(row.formation_note_zh);
|
||||
formed.push({
|
||||
id, group: "formed", name, alias, text: sentence, tags, same: false, planets, diagram: rowDiagram(row, planets, bodies, rules),
|
||||
id, group: "formed", name, alias, text: note ? `${sentence}。${note}`.replace(/。。/gu, "。") : sentence, tags, same: false, planets,
|
||||
diagram: actualOrIllustration(row, planets, bodies, rules),
|
||||
...(MINOR_CATEGORIES.has(String(row.category ?? "")) ? { minor: true } : {}),
|
||||
});
|
||||
}
|
||||
@@ -508,7 +523,7 @@ export function buildYogaGroups(input: Readonly<{
|
||||
id: `adverse:${key}`, group: "adverse", name, alias: null,
|
||||
text: `${conditionText(first)}${merged ? `。${merged}` : ""}`.replace(/。。/gu, "。"),
|
||||
tags: mitigations, same: false, planets,
|
||||
diagram: rowDiagram(first, planets, bodies, rules),
|
||||
diagram: actualOrIllustration(first, planets, bodies, rules),
|
||||
});
|
||||
}
|
||||
return { formed: [...formed.filter((card) => !card.minor), ...formed.filter((card) => card.minor)], support, adverse };
|
||||
|
||||
@@ -3370,7 +3370,9 @@ export const EVIDENCE_CARD_YOGA_SELECTION_RULE = (
|
||||
"selection_reasons keeps every recall reason. direct: route_packet, domain_named, packet_domain, rule_topic (topic map "
|
||||
+ "pending the astrologer's review). dependency: an exchange or debilitation cancellation sharing a planet with a direct "
|
||||
+ "row (dependency_of); unrelated ones do not enter. weak: category alone, or a planet ruling a recall house "
|
||||
+ "(domain_house_lord; not used on whole-chart cards). Rows without a mapped topic are unmapped_rule_ids, never dropped."
|
||||
+ "(domain_house_lord; not used on whole-chart cards). Rows without a mapped topic are unmapped_rule_ids, never dropped. "
|
||||
+ "exchange_houses: a sign exchange recalled by the two houses it exchanges (exchanged_houses) — a recall rule, not a "
|
||||
+ "conclusion; same_exchange_as marks another rule on the same exchange, which is one piece of evidence, not extra support."
|
||||
);
|
||||
|
||||
export const EVIDENCE_CARD_YOGA_FIELD_RULE = (
|
||||
@@ -3388,7 +3390,45 @@ export const EVIDENCE_CARD_YOGA_COUNTS_RULE = (
|
||||
+ "hit_count > 1 is the same rule matched again, not independent support."
|
||||
);
|
||||
|
||||
const YOGA_DIRECT_REASONS = ["route_packet", "domain_named", "packet_domain", "rule_topic"] as const;
|
||||
const YOGA_DIRECT_REASONS = ["route_packet", "domain_named", "packet_domain", "rule_topic", "exchange_houses"] as const;
|
||||
|
||||
/**
|
||||
* BUG-2392 (占星师 2026-11-25 复核第四项): a sign-exchange row is retrieved for a domain by the two houses
|
||||
* actually exchanged on this chart — a retrieval rule, not a conclusion. 事业 10 + 6/7/2/11;财富 2、11 + 8/12;
|
||||
* 婚恋 5、7(+2/8);健康 1/6/8/12;居住 4;学习远行 5/9;手足沟通 3. One exchange is one row of evidence:
|
||||
* other rows on the same two planets are marked `same_exchange_as`, never counted as extra support.
|
||||
*/
|
||||
export const EXCHANGE_DOMAIN_HOUSES: Readonly<Partial<Record<ConsultationDomain, Readonly<{ core: readonly number[]; extra: readonly number[] }>>>> = {
|
||||
career: { core: [10], extra: [6, 7, 2, 11] },
|
||||
wealth: { core: [2, 11], extra: [8, 12] },
|
||||
marriage: { core: [5, 7], extra: [2, 8] },
|
||||
health: { core: [1, 6, 8, 12], extra: [] },
|
||||
family: { core: [4, 3], extra: [] },
|
||||
parents: { core: [4], extra: [] },
|
||||
education: { core: [5, 9], extra: [] },
|
||||
migration: { core: [9, 12], extra: [] },
|
||||
};
|
||||
|
||||
/** A domain recalls an exchange when one exchanged house is its core house, or both are among its core and extra houses. */
|
||||
export function exchangeRecalledFor(domain: ConsultationDomain, houses: readonly number[]): boolean {
|
||||
const spec = EXCHANGE_DOMAIN_HOUSES[domain];
|
||||
if (!spec || houses.length !== 2) return false;
|
||||
const all = [...spec.core, ...spec.extra];
|
||||
return houses.some((house) => spec.core.includes(house)) || houses.every((house) => all.includes(house));
|
||||
}
|
||||
|
||||
/** The two houses a sign-exchange row exchanges: the engine's house_class check, else its `exchange` places. */
|
||||
export function exchangedHouses(row: Record<string, unknown>): number[] {
|
||||
for (const check of Array.isArray(row.formation_checks) ? row.formation_checks as Json[] : []) {
|
||||
const value = record(check);
|
||||
if (value.id === "house_class") {
|
||||
const houses = record(value.witness).houses;
|
||||
if (Array.isArray(houses)) return houses.filter((h): h is number => typeof h === "number");
|
||||
}
|
||||
}
|
||||
const places = Object.values(record(row.exchange)).map((place) => record(place).house).filter((h): h is number => typeof h === "number");
|
||||
return places.length === 2 ? places : [];
|
||||
}
|
||||
type YogaReason = typeof YOGA_DIRECT_REASONS[number] | "dependency" | "category" | "domain_house_lord";
|
||||
|
||||
function yogaCategory(row: Record<string, unknown>): string | undefined {
|
||||
@@ -3468,6 +3508,11 @@ export function selectEvidenceCardYogaDetail(
|
||||
if (typeof row.name === "string" && named.has(row.name)) out.push("domain_named");
|
||||
if (typeof row.packet_domain === "string" && tags.has(row.packet_domain)) out.push("packet_domain");
|
||||
if (stringList(row.rule_topics).some((topic) => topics.has(topic))) out.push("rule_topic");
|
||||
const exchanged = exchangedHouses(row);
|
||||
if (!whole && exchanged.length === 2
|
||||
&& scope.domains.some((domain) => exchangeRecalledFor(domain, exchanged))) {
|
||||
out.push("exchange_houses");
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const rows = [...unique.values()];
|
||||
@@ -3518,7 +3563,18 @@ export function selectEvidenceCardYogaDetail(
|
||||
chosen.sort((a, b) => rank[a.relevance] - rank[b.relevance] || String(a.row.rule_id).localeCompare(String(b.row.rule_id)));
|
||||
let detailCount = 0;
|
||||
let indexCount = 0;
|
||||
// BUG-2392: one exchange (two planets in each other's signs) is one piece of evidence however many rules name it.
|
||||
const exchangeFirst = new Map<string, string>();
|
||||
const exchangeKey = (row: Record<string, unknown>) => {
|
||||
const pair = Object.keys(record(row.exchange));
|
||||
const bound = pair.length === 2 ? pair : exchangedHouses(row).length === 2
|
||||
? (Array.isArray(row.planets) ? stringList(row.planets) : Object.keys(record(row.planets))) : [];
|
||||
return bound.length === 2 ? [...bound].sort().join(":") : "";
|
||||
};
|
||||
const outRows: Json[] = chosen.map(({ row, reasons, relevance, dependencyOf }) => {
|
||||
const exchangeOf = exchangeKey(row);
|
||||
const sameExchange = exchangeOf && exchangeFirst.has(exchangeOf) ? exchangeFirst.get(exchangeOf) : undefined;
|
||||
if (exchangeOf && !exchangeFirst.has(exchangeOf)) exchangeFirst.set(exchangeOf, String(row.rule_id));
|
||||
const common: JsonRecord = {
|
||||
// BUG-1976 / BUG-1978: rule id + layer; the method version is the snapshot's (yoga_id on the Python side).
|
||||
// BUG-1988: a per-planet rule (Neecha Bhanga main detector) keeps one row and one id per planet.
|
||||
@@ -3533,12 +3589,15 @@ export function selectEvidenceCardYogaDetail(
|
||||
...(dependencyOf ? { dependency_of: dependencyOf } : {}),
|
||||
...yogaTemporal(row),
|
||||
...(Number(row.hit_count ?? 1) > 1 ? { hit_count: Number(row.hit_count) } : {}),
|
||||
...(reasons.includes("exchange_houses") ? { exchanged_houses: exchangedHouses(row) as unknown as Json } : {}),
|
||||
...(sameExchange ? { same_exchange_as: sameExchange } : {}),
|
||||
};
|
||||
// Detail when the row bears on this question: a route packet, a domain section or the packet names it,
|
||||
// a dependency of such a row, or (single-domain cards) the rule's own topic. On a whole-chart card a
|
||||
// topic match alone is an index unless a participating planet runs a current period.
|
||||
const strong = reasons.some((r) => r === "route_packet" || r === "domain_named" || r === "packet_domain");
|
||||
const topicDetail = reasons.includes("rule_topic") && (!whole || stringList(row.running_dasha_levels).length > 0);
|
||||
const topicDetail = (reasons.includes("rule_topic") || reasons.includes("exchange_houses"))
|
||||
&& (!whole || stringList(row.running_dasha_levels).length > 0);
|
||||
const asIndex = relevance === "weak" || (relevance === "direct" && !strong && !topicDetail);
|
||||
if (asIndex) {
|
||||
indexCount += 1;
|
||||
|
||||
Reference in New Issue
Block a user