feat(logic): setop engine + set gate — the Europe count computed end-to-end

A) SET GATE: enumerations are answered only from membership sets, never from mention rows (the probe early-exit that served 'Armenia, Cyprus, Georgia, Turkey' to 'what countries are in Europe' is dead). Sets carry origin_question; the gate matches stem-Jaccard>=0.5 so a set is served to its own question only. B) SETOP ENGINE: logic's first real engine — a count over list rows is computed (difference/intersection/count over norm_name'd items, table markers 'Austria*' == 'Austria'), before ROUTE, zero LLM calls, verified=True because the computation IS the check. C) Catalog honesty: knowledge 'lists are ONE fetch', logic 'how-many over lists in evidence', floop 'NOT mere size'. Plus four substrate bugs the live runs exposed: LM-proxy prompt cache (instant answers are cache hits, never trust zero latency), _context rendering list rows as scalars ('E1: 50' routed 'those countries' to user), <br> concatenation in multi-value name cells, multi-line refs leaking into values ('franceincludes the 101 departments' -> France dropped from EU -> 24 not 23). Cold E2E: Q1 50 states ingested, Q2 27 EU members ingested, Q3 difference computed = 23, cited over E1/E2. 22/22 tests.
This commit is contained in:
2026-10-18 19:49:24 +02:00
parent 6fcb3c0a86
commit e5482bd092
10 changed files with 390 additions and 34 deletions
+9 -3
View File
@@ -113,6 +113,11 @@ def parse_tables(wikitext: str, max_tables: int = 4) -> list[WikiTable]:
if line.startswith("|"):
raw_cells.extend(re.split(r"\|\|", line.lstrip("|")))
continue
# continuation line: multi-line refs/templates inside a cell do
# not start with a marker — they belong to the previous raw cell
if raw_cells:
raw_cells[-1] += " " + line
continue
if raw_cells:
flush_row(raw_cells, row_is_header)
if header_grid:
@@ -155,9 +160,10 @@ def _tpl_arg(content: str) -> str:
def _clean_cell(cell: str) -> str:
"""Resolve links/templates to display text; drop refs, File links, tags.
Order matters: refs with content first (else their text leaks into the
value — 'France<ref name=g/>' -> 'Franceg'), then File links (dropped
whole), then links (display text), then templates innermost-out."""
Order matters: <br> variants become ' / ' separators FIRST (multi-value
name cells like 'Albania<br>Republic of Albania<br>ALB' must not
concatenate), then refs, File links, links, templates."""
cell = re.sub(r"<br\s*/?>", " / ", cell, flags=re.I)
cell = re.sub(r"<ref[^>]*>.*?</ref>", "", cell, flags=re.S | re.I)
cell = re.sub(r"<ref[^>]*/?>", "", cell, flags=re.I)
cell = re.sub(r"<sup[^>]*>.*?</sup>", "", cell, flags=re.S | re.I)