Extract verbatim in ExtractClaims not in TypeClaim
This commit is contained in:
@@ -5,6 +5,11 @@ mode ingests the typed facts from Pass 2 exactly as the legacy path
|
||||
did — same _ingest_candidate, same containment checks, same merge; the
|
||||
single-pass path keeps working (control). No network: the expert's
|
||||
claims/typeclaim/extract modules are scripted.
|
||||
|
||||
The verbatim law (1/11): Pass 1 extracts the VERBATIM quote, Pass 2
|
||||
only types — code PINS the fact's quote to Pass 1's verbatim, so the
|
||||
STORED quotes (quotes.verbatim) must be Pass 1's spans (contained in
|
||||
the page text), never the TYPE model's paraphrases.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -16,7 +21,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
|
||||
|
||||
from knowledge.extract import Fact
|
||||
from knowledge.extract import Claim, Fact
|
||||
from knowledge.expert import KnowledgeConfig, KnowledgeExpert
|
||||
from knowledge.store import KnowledgeStore
|
||||
from knowledge.wiki import WikiPage
|
||||
@@ -36,14 +41,22 @@ def make_page() -> WikiPage:
|
||||
|
||||
|
||||
class ScriptedClaims:
|
||||
"""Pass 1 double: claims WITH their verbatim quotes — spans that ARE
|
||||
contained in PAGE_TEXT (the containment check runs for real)."""
|
||||
|
||||
def __call__(self, **kw):
|
||||
class Out:
|
||||
claims = ["Pedro Sanchez has been the prime minister of Spain since 2018",
|
||||
"Pedro Sanchez is Secretary-General of the PSOE since 2017"]
|
||||
claims = [Claim(claim="Pedro Sanchez has been the prime minister of Spain since 2018",
|
||||
verbatim="has been the prime minister of Spain since 2018"),
|
||||
Claim(claim="Pedro Sanchez is Secretary-General of the PSOE since 2017",
|
||||
verbatim="Secretary-General of the Spanish Socialist Workers' Party (PSOE) since 2017")]
|
||||
return Out()
|
||||
|
||||
|
||||
class ScriptedTypeClaim:
|
||||
"""Pass 2 double: typing only — its scripted quotes are PARAPHRASES;
|
||||
code must pin the fact's quote to Pass 1's verbatim instead."""
|
||||
|
||||
def __init__(self, facts):
|
||||
self.facts = facts
|
||||
self.i = 0
|
||||
@@ -66,12 +79,11 @@ def test_two_pass_ingests_typed_facts():
|
||||
e.typeclaim = ScriptedTypeClaim([
|
||||
Fact(subject="Pedro Sanchez", relation="prime minister of",
|
||||
object="Spain",
|
||||
quote="has been the prime minister of Spain since 2018",
|
||||
quote="a paraphrase Pass 2 invented (must be overwritten)",
|
||||
start="2018", end=None, point=None, granularity="year"),
|
||||
Fact(subject="Pedro Sanchez", relation="secretary-general of",
|
||||
object="PSOE",
|
||||
quote="Secretary-General of the Spanish Socialist Workers' "
|
||||
"Party (PSOE) since 2017",
|
||||
quote="another paraphrase (must be overwritten)",
|
||||
start="2017", end=None, point=None, granularity="year"),
|
||||
])
|
||||
# per-call state that answer_question initializes (the wiring test
|
||||
@@ -89,7 +101,14 @@ def test_two_pass_ingests_typed_facts():
|
||||
assert len(rows) == 2, rows
|
||||
assert rows[0][1] == "prime minister of" and rows[0][3] == "2018", rows[0]
|
||||
assert rows[1][1] == "secretary-general of" and rows[1][3] == "2017", rows[1]
|
||||
print("ok: two_pass ingests typed facts (windows kept, legacy checks)")
|
||||
# the verbatim law end-to-end: the STORED quotes are Pass 1's verbatims
|
||||
# (Pass 2's paraphrases never reach the store)
|
||||
quotes = {r[0] for r in store.db.execute(
|
||||
"SELECT verbatim FROM quotes").fetchall()}
|
||||
assert quotes == {"has been the prime minister of Spain since 2018",
|
||||
"Secretary-General of the Spanish Socialist Workers' "
|
||||
"Party (PSOE) since 2017"}, quotes
|
||||
print("ok: two_pass ingests typed facts (verbatim pinned, legacy checks)")
|
||||
|
||||
|
||||
def test_single_pass_still_works():
|
||||
|
||||
Reference in New Issue
Block a user