Stop a room number from being read as a room's reading
A quantity conflict compared labels, and a label can carry a number that
identifies the thing rather than measuring it. 「Room 3 holds 22 degrees」 and
「Room 4 holds 24 degrees」 shared the subject 「room」, so the store recorded a
conflict over the room numbers and dropped Room 3 from the answer page: asking
about degrees returned one room's reading and hid the other room entirely.
「The router 1/2 forwards 220/240 packets」 and 「2026 saw 3 / 2027 saw 5
releases」 failed the same way.
A bare number standing before any predicate is part of the subject's name, so it
joins the subject key and is never recorded as a value. A number that stands past
a word still measures: 「The rent is 2200 / 2400 dollars」 conflicts over rent,
and a number fused inside a CJK run stays a value, because 「恒温器调到」 states its
predicate inside the subject token and the motivating pair must keep conflicting.
The same year counting twice is now a conflict (「2026 saw 3 / 5 releases」), which
the old rule missed.
Only a number renames a subject: 「Room A」 and 「Room B」 still read as one room
whose reading moved, and an English qualifier does not split a subject the way a
Chinese one does. Both boundaries are disclosed and pinned by tests rather than
smoothed over.
Also collapses six two-line comment blocks back to one line each, which is the
rule this repo already enforces, and corrects the record where it claimed the
nearest label was 「书房」 (it is 「设定」) and that the subject rule only ever
missed conflicts.
Gates: pytest -q 379 passed (conflicts 17 -> 22, six p2-3 files 78, three tier
files 35); ruff clean; bench.filesize_check clean; mypy cold cache 24 errors in 9
files, byte-identical to the recorded 9cb46c1 baseline; pyright 0 errors on the
touched files; go build/vet/test and gofmt clean; npm run build unchanged at
index-CSDHCFNo.js; mcp_write_smoke.sh PASS; whole-line comment runs of length >=2:
0 across tracked Python files.
This commit is contained in:
1 parent
3daface332
commit
8bed319848
7 files changed
+104
-27
No files matched your search
@@ -322,8 +322,7 @@ class MemoryService:
|
||||
)
|
||||
self.db.upsert_atoms([rollup])
|
||||
self.vectors.sync_atoms([atom_id])
|
||||
# The watermark is the newest memory actually rolled up, not the clock of the pass: a
|
||||
# consolidation run with a clock behind the memories would otherwise count them twice.
|
||||
# The watermark is the newest memory actually rolled up, not the clock of the pass: a pass run behind the memories would count them twice.
|
||||
record = ConsolidationRecord(
|
||||
holder_id=holder_id,
|
||||
scenario=scenario,
|
||||
|
||||
@@ -315,8 +315,7 @@ def apply(connection: sqlite3.Connection) -> None:
|
||||
if name not in existing:
|
||||
connection.execute(f"ALTER TABLE atoms ADD COLUMN {name} {definition}")
|
||||
if version < 10:
|
||||
# CREATE VIEW IF NOT EXISTS keeps the old body, and the tenth version changed which rows
|
||||
# the current tier contains, so an upgraded database has to be told to look again.
|
||||
# CREATE VIEW IF NOT EXISTS keeps the old body, and v10 changed which rows are current, so an upgraded store must be told to look again.
|
||||
connection.execute("DROP VIEW IF EXISTS v_atoms_current")
|
||||
|
||||
connection.executescript(VIEWS)
|
||||
|
||||
@@ -223,26 +223,26 @@ def numeric_values(text: str) -> StatedNumbers:
|
||||
A number is attributed twice: to the subject the memory leads with, and to the content word
|
||||
standing beside it. 「恒温器放在书房,设定 22 度」 and 「恒温器调到 24 度」 phrase the setting
|
||||
differently but lead with the same thing, and it is that shared label which makes the pair one
|
||||
disagreement about one quantity rather than two unrelated counts.
|
||||
disagreement about one quantity rather than two unrelated counts. A number written onto the
|
||||
subject itself is part of the object's name, not a quantity — 「Room 3」 and 「Room 4」 are two
|
||||
rooms — so it joins the subject instead of being recorded as a value.
|
||||
"""
|
||||
try:
|
||||
tokens = fts_terms(text)
|
||||
except ValueError:
|
||||
return StatedNumbers(subject="", values={})
|
||||
subject = ""
|
||||
for token in tokens:
|
||||
# An English memory usually opens with an article, and a subject behind one is still the
|
||||
# subject: 「The router forwards 220 packets」 leads with its router, not with 「the」.
|
||||
subject = _label(token, first=True)
|
||||
if subject:
|
||||
break
|
||||
subject, named_at = _subject_and_rename_slot(tokens)
|
||||
values: dict[str, str] = {}
|
||||
beside = ""
|
||||
for token in tokens:
|
||||
for index, token in enumerate(tokens):
|
||||
stated = _NUMBER.findall(token)
|
||||
if not stated:
|
||||
beside = _label(token) or beside
|
||||
continue
|
||||
if index == named_at and not _LETTER.search(token):
|
||||
# A bare number written onto the subject names the object rather than measuring it: 「Room 3」 is not one reading.
|
||||
subject = f"{subject}{stated[0]}"
|
||||
continue
|
||||
for value in stated:
|
||||
if subject:
|
||||
values.setdefault(subject, value)
|
||||
@@ -251,6 +251,26 @@ def numeric_values(text: str) -> StatedNumbers:
|
||||
return StatedNumbers(subject=subject, values=values)
|
||||
|
||||
|
||||
def _subject_and_rename_slot(tokens: list[str]) -> tuple[str, int]:
|
||||
"""The thing a memory is about, and the slot where a number would rename rather than measure it.
|
||||
|
||||
A memory that opens with a number is about that number: 「2026 saw 3 releases」 counts releases
|
||||
for 2026, so 2026 names the thing and 3 measures it. An English memory usually opens with an
|
||||
article, and a subject behind one is still the subject: 「The router forwards 220 packets」 leads
|
||||
with its router, not with 「the」. Only a number written onto the subject renames it; one
|
||||
standing past a word is a value, which is why 「The rent is 2200 dollars」 can move. A CJK run can
|
||||
fuse the subject and what it reports into one token, and the number after that is a value too:
|
||||
「恒温器调到 24 度」 adjusts a thermostat, it does not name a thing called 「恒温器调到 24」.
|
||||
"""
|
||||
for index, token in enumerate(tokens):
|
||||
if _NUMBER.fullmatch(token.strip(_PUNCTUATION)):
|
||||
return token.strip(_PUNCTUATION), -1
|
||||
head = _label(token, first=True)
|
||||
if head:
|
||||
return head, -1 if _label(token) != head else index + 1
|
||||
return "", -1
|
||||
|
||||
|
||||
def quantity_conflict(older_text: str, newer_text: str) -> QuantityConflict | None:
|
||||
"""The quantity two memories state differently, but only while they lead with the same subject.
|
||||
|
||||
@@ -267,8 +287,7 @@ def quantity_conflict(older_text: str, newer_text: str) -> QuantityConflict | No
|
||||
return None
|
||||
subject = older.subject
|
||||
if subject in newer.values and _as_float(older.values[subject]) != _as_float(newer.values[subject]):
|
||||
# The subject carries the value here, so it is named rather than whichever shared label
|
||||
# sorts first: 「router」 is what the pair disagrees about, not the verb beside it.
|
||||
# The subject itself carries the two values, so it is named rather than the verb beside it.
|
||||
return QuantityConflict(term=subject, older_value=older.values[subject], newer_value=newer.values[subject])
|
||||
term = conflicting_number(older.values, newer.values)
|
||||
if term is None:
|
||||
@@ -316,3 +335,4 @@ def _label(token: str, *, first: bool = False) -> str:
|
||||
|
||||
_PUNCTUATION = " \t\n.,;:!?。,;:!?、"
|
||||
_NUMBER = re.compile(r"[-+]?\d+(?:\.\d+)?")
|
||||
_LETTER = re.compile(r"[^\W\d_]")
|
||||
@@ -201,7 +201,10 @@ def test_the_same_subject_measuring_two_things_still_reads_as_one_quantity(tmp_p
|
||||
def test_a_memory_that_leads_with_a_number_has_no_subject_to_conflict_on(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["22 度", "24 度"])
|
||||
|
||||
assert service.conflicts("wife") == [], "with no subject named the store cannot claim they are one thing"
|
||||
assert service.conflicts("wife") == [], (
|
||||
"the number is all the memory has to name itself with, so the store has no subject it could "
|
||||
"call the two one thing and records nothing"
|
||||
)
|
||||
|
||||
|
||||
def test_a_qualifier_on_the_subject_reads_as_a_different_thing(tmp_path) -> None:
|
||||
@@ -214,10 +217,65 @@ def test_a_qualifier_on_the_subject_reads_as_a_different_thing(tmp_path) -> None
|
||||
)
|
||||
|
||||
|
||||
def test_the_first_number_under_a_label_is_the_value_that_is_compared(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["2026 saw 3 releases", "2026 saw 5 releases"])
|
||||
def test_a_year_that_leads_a_memory_names_the_thing_it_counts(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["2026 saw 3 releases", "2027 saw 5 releases"])
|
||||
|
||||
assert service.conflicts("wife") == [], (
|
||||
"the year leads, so it is what the subject's value records; a count that moves behind it "
|
||||
"is not noticed — the store names one quantity per label, not every quantity in a sentence"
|
||||
"the year is what the count belongs to, not the quantity that moved: 2026 and 2027 are two "
|
||||
"records, and comparing their counts would call every timeline a disagreement"
|
||||
)
|
||||
|
||||
|
||||
def test_the_same_year_counting_differently_is_a_conflict(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["2026 saw 3 releases", "2026 saw 5 releases"])
|
||||
|
||||
found = service.conflicts("wife")
|
||||
assert [conflict.terms for conflict in found] == [["saw"]], (
|
||||
"one year, two counts: the year names the record and the count standing behind it is the "
|
||||
"quantity that moved, which is what the holder asked to be told about"
|
||||
)
|
||||
assert [(conflict.older_value, conflict.newer_value) for conflict in found] == [("3", "5")]
|
||||
|
||||
|
||||
def test_room_numbers_name_the_room_rather_than_measure_it(tmp_path) -> None:
|
||||
service, database = _lane(tmp_path, ["Room 3 holds 22 degrees", "Room 4 holds 24 degrees"])
|
||||
|
||||
assert service.conflicts("wife") == [], (
|
||||
"a number written onto the subject is part of its name: Room 3 and Room 4 are two rooms, "
|
||||
"each steady at its own temperature, and suppressing one would throw away a real fact"
|
||||
)
|
||||
assert sorted(_search(tmp_path, database, "Room")) == sorted(
|
||||
["Room 3 holds 22 degrees", "Room 4 holds 24 degrees"]
|
||||
), "both rooms stay findable"
|
||||
|
||||
|
||||
def test_two_routers_keep_their_own_counters(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["The router 1 forwards 220 packets", "The router 2 forwards 240 packets"])
|
||||
|
||||
assert service.conflicts("wife") == [], (
|
||||
"the counter that identifies the router is not the counter it reports, so each router keeps "
|
||||
"its own number the way each room keeps its own temperature"
|
||||
)
|
||||
|
||||
|
||||
def test_a_number_past_a_word_is_still_the_value_that_moved(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["The rent is 2200 dollars", "The rent is 2400 dollars"])
|
||||
|
||||
found = service.conflicts("wife")
|
||||
assert [conflict.terms for conflict in found] == [["rent"]], (
|
||||
"a number standing past a word measures the subject instead of naming it, which is what "
|
||||
"keeps the ordinary case — a rent that changed — reaching the holder"
|
||||
)
|
||||
assert [(conflict.older_value, conflict.newer_value) for conflict in found] == [
|
||||
("2200", "2400")
|
||||
]
|
||||
|
||||
|
||||
def test_a_letter_qualifier_does_not_rename_the_room(tmp_path) -> None:
|
||||
service, _ = _lane(tmp_path, ["Room A holds 22 degrees", "Room B holds 24 degrees"])
|
||||
|
||||
assert len(service.conflicts("wife")) == 1, (
|
||||
"only a number written onto the subject renames it, so Room A and Room B still read as one "
|
||||
"room whose reading moved — the pair is recorded for the holder to settle rather than "
|
||||
"silently resolved, and this is the boundary the rule does not cross"
|
||||
)
|
||||
@@ -284,8 +284,7 @@ def test_a_ninth_version_database_gains_the_tiers_in_place(tmp_path: Path) -> No
|
||||
_seed_source(database)
|
||||
database.upsert_atoms([_atom("key")])
|
||||
with database.connect() as connection:
|
||||
# The downgrade removes what a ninth build never had, including the view and indexes
|
||||
# that reference those columns, so the reopened store really is a ninth-version one.
|
||||
# The downgrade removes what a ninth build never had, view and indexes included, so the reopened store really is ninth-version.
|
||||
connection.executescript(
|
||||
"""
|
||||
DROP VIEW IF EXISTS v_atoms_current;
|
||||
|
||||
Reference in new issue
Block a user