Live, "Rashi on Devarim 6:5 indicates <a claim Rashi does not make>" came back tov: "Devarim 6:5" inside the citation was read as a Torah citation, which anchors the claim in Torah by reference (tablet 49's rule). The claim is about Rashi and must rest on Rashi — the mesorah passage is a given source — or on nothing. Mesorah citations are now blanked before the Torah readings (references and the Torah anchor); an output's own "Devarim 6:5" still anchors in Torah. korban 295/1 skipped. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
99 lines
5.0 KiB
Python
99 lines
5.0 KiB
Python
"""The second scroll, read (bishe'arecha §IV): citations found as written,
|
|
resolved against the snapshot, and given to the anchoring as sources."""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
os.environ.setdefault("MESORAH_MOUNT_POINT", str(REPO / "mesorah"))
|
|
|
|
from korban_processor import mesorah # noqa: E402
|
|
from korban_processor.bedikah import examine # noqa: E402
|
|
|
|
needs_scroll = pytest.mark.skipif(not mesorah.available(), reason="mesorah snapshot not built at MESORAH_MOUNT_POINT")
|
|
|
|
|
|
@needs_scroll
|
|
def test_citations_are_found_as_written_in_their_several_forms():
|
|
text = ("Rashi on Devarim 6:5 reads the verse one way; Ramban to Deut. 6:5 another. Onkelos Bereishit 1:1 renders it. "
|
|
"Mishnah Berakhot 1:1 opens with the evening Shema; Berakhot 2a asks why. Bereshit Rabbah 1:1 begins with wisdom. "
|
|
"Sifrei Devarim 32 comments. Bavli Shabbat 31a has Hillel.")
|
|
refs = {r.slug: r for r in mesorah.find_mesorah_references(text)}
|
|
assert refs["rashi_on_devarim"].address == (6, 5)
|
|
assert refs["ramban_on_devarim"].address == (6, 5)
|
|
assert refs["onkelos_bereishit"].address == (1, 1)
|
|
assert refs["mishnah_berakhot"].address == (1, 1)
|
|
assert refs["bavli_berakhot"].address == (3,) # 2a → daf index 3
|
|
assert refs["bavli_shabbat"].address == (61,) # 31a
|
|
assert refs["bereshit_rabbah"].address == (1, 1)
|
|
assert refs["sifrei_devarim"].address == (32,)
|
|
assert refs["rashi_on_devarim"].as_written == "Rashi on Devarim 6:5"
|
|
[t] = mesorah.find_mesorah_references("Midrash Tanchuma, Bereshit 1 opens the same way.")
|
|
assert t.slug == "midrash_tanchuma" and t.address == ("Bereshit", 1) and t.ref_id == "midrash_tanchuma_bereshit_1"
|
|
|
|
|
|
@needs_scroll
|
|
def test_complex_works_resolve_through_their_unnamed_node_and_tanchuma_through_its_parashah():
|
|
assert mesorah.resolve("ramban_on_bereishit", (1, 1))[0]
|
|
assert mesorah.resolve("ibn_ezra_on_bereishit", (1, 1))[0]
|
|
assert mesorah.resolve("sforno_on_bereishit", (1, 1))[0]
|
|
assert mesorah.resolve("midrash_tanchuma", ("Bereshit", 1))[0]
|
|
assert not mesorah.resolve("midrash_tanchuma", ("Nowhere", 1))[0]
|
|
|
|
|
|
@needs_scroll
|
|
def test_a_citation_the_scroll_has_resolves_to_text_and_one_it_lacks_does_not():
|
|
exists, texts = mesorah.resolve("rashi_on_devarim", (6, 5))
|
|
assert exists and "he" in texts and len(texts["he"]) > 20
|
|
assert "<" not in texts["he"] # tags stripped
|
|
exists, texts = mesorah.resolve("rashi_on_devarim", (99, 1))
|
|
assert not exists and texts == {}
|
|
exists, _ = mesorah.resolve("bavli_berakhot", (3,))
|
|
assert exists
|
|
|
|
|
|
@needs_scroll
|
|
def test_the_examination_lists_the_citations_and_anchors_a_claim_in_the_cited_passage():
|
|
he, _ = mesorah.resolve("rashi_on_bereishit", (1, 1))[1].get("he", ""), None
|
|
# Quote six consecutive words of Rashi on Bereishit 1:1 in the output: the claim must anchor in the passage.
|
|
words = he.split()
|
|
quote = " ".join(words[2:9])
|
|
out = f"Rashi on Bereishit 1:1 says: {quote}. This suggests the Torah opens with a question about where it should begin."
|
|
ex = examine(out, "claude", "")
|
|
refs = [r for r in ex.mesorah_references if r["work"] == "rashi_on_bereishit"]
|
|
assert refs and refs[0]["found"] and refs[0]["address"] == [1, 1] and "he" in refs[0]["languages"]
|
|
anchored = [a.source for c in ex.claims for a in c.anchors]
|
|
assert "mesorah:rashi_on_bereishit_1_1" in anchored
|
|
|
|
|
|
@needs_scroll
|
|
def test_a_citation_to_nothing_is_reported_not_invented():
|
|
ex = examine("Rashi on Devarim 99:1 explains this, which suggests the matter is settled.", "gpt", "")
|
|
assert ex.mesorah_references == [{"as_written": "Rashi on Devarim 99:1", "ref": "rashi_on_devarim_99_1", "work": "rashi_on_devarim", "address": [99, 1], "found": False, "languages": []}]
|
|
assert not any(a.source.startswith("mesorah:") for c in ex.claims for a in c.anchors)
|
|
|
|
|
|
def test_without_the_scroll_nothing_is_found_and_nothing_breaks(monkeypatch):
|
|
monkeypatch.setattr(mesorah, "MOUNT", "/nonexistent/mesorah")
|
|
mesorah._index.cache_clear()
|
|
mesorah._work.cache_clear()
|
|
try:
|
|
assert mesorah.find_mesorah_references("Rashi on Devarim 6:5 says so.") == []
|
|
assert mesorah.read("Berakhot 2a") == []
|
|
finally:
|
|
mesorah._index.cache_clear()
|
|
mesorah._work.cache_clear()
|
|
|
|
|
|
@needs_scroll
|
|
def test_a_claim_about_rashi_must_rest_on_rashi_not_on_the_verse_rashi_comments():
|
|
ex = examine("Rashi on Devarim 6:5 indicates that love means abandoning all commandments, which suggests the verse is optional.", "gpt", "")
|
|
assert ex.references == [] # "Devarim 6:5" here is Rashi's address
|
|
[claim] = [c for c in ex.claims if "abandoning" in c.sentence]
|
|
assert claim.anchors == [] # neither Torah by reference nor Rashi by text
|
|
assert [r["found"] for r in ex.mesorah_references] == [True]
|
|
# A Torah citation of the output's own still anchors in Torah.
|
|
ex2 = examine("Devarim 6:5 commands love, which suggests the whole heart.", "gpt", "")
|
|
assert ex2.references == ["Devarim 6:5"]
|