Skip to content

Gate blank-typed link inference with a structural-home check - #79

Merged
kdroidFilter merged 1 commit into
masterfrom
fix/blank-link-cross-ref-commentary
Jun 8, 2026
Merged

Gate blank-typed link inference with a structural-home check#79
kdroidFilter merged 1 commit into
masterfrom
fix/blank-link-cross-ref-commentary

Conversation

@kdroidFilter

Copy link
Copy Markdown
Owner

Problem

In the reader's commentator (מפרשים) panel, opening a commentary on a verse showed extra, unrelated segments. Example: Shulchan Arukh OC 323:6 → Magen Avraham listed 5 comments, but only ס"ק ח/ט (323:8, 323:9) actually comment on that se'if — the others (302:6, 321:7, 331:5) are in different simanim.

Root cause

Genuine commentary links are explicitly typed commentary in Sefaria; lateral cross-references have a blank Conection Type. The generator's blank-type inference (inferConnectionTypeFromSchema) promoted any blank-typed link to COMMENTARY whenever a base→dependant relationship existed, so cross-references (a commentary citing another siman) were mislabeled as commentary.

Fix

inferBlankConnectionType wraps the schema inference with a structural-home gate: keep the oriented promotion only when the dependant segment's top-level structural index (siman / perek) matches the base it points at; otherwise classify as REFERENCE. Daf-style / whole-book refs are left untouched (never demoted).

  • Explicitly-typed commentary links are unaffected.
  • Blank-but-home commentaries (e.g. Abarbanel → the verse it expounds) stay COMMENTARY.

Validation

Regenerated the DB seeded from the v1 build state:

  • 323:6 → Magen Avraham: 5 COMMENTARY → 2 COMMENTARY (the genuine ס"ק ח/ט), 3 → REFERENCE.
  • Corpus-wide COMMENTARY −1.35% (concentrated in halakhic cross-refs); Genesis 1:1 kept 70/72 commentators, the 2 dropped being real cross-refs to other parashot; Rashi intact.
  • Unit tests added in SefariaLinksImporterTest.

Blank 'Conection Type' links between a base text and its commentary were
promoted to COMMENTARY whenever a base->dependant relationship existed.
That mislabeled lateral cross-references (e.g. Magen Avraham 302:6 ->
Shulchan Arukh 323:6, which only cites siman 323) as commentary, so they
surfaced as spurious segments in the reader's מפרשים panel.

Keep the oriented promotion only when the dependant segment's top-level
structural index (siman / perek) matches the base it points at; otherwise
classify the link as REFERENCE. Explicitly-typed commentary links never
hit this path and are unaffected, and blank-but-home commentaries
(e.g. Abarbanel -> the verse it expounds) stay COMMENTARY.
@kdroidFilter
kdroidFilter merged commit 3fe24c5 into master Jun 8, 2026
1 check passed
@kdroidFilter
kdroidFilter deleted the fix/blank-link-cross-ref-commentary branch June 8, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant