From a31f8d66747d5def318104a301ec2da506887ed8 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Fri, 20 Nov 2026 14:35:26 -0800 Subject: [PATCH 1/4] Count a listed title typed into the given-names box apart from the score (#1501) Where the filer typed a listed title into the given-names box and the parse reads it as the title and the rest of the box as the box's names, every other field agreeing and no title box filed, local_agreement.read marks the record titled: counted in neither the agreeing records nor the misses, the agreement figure taken over the records outside it, the report printing the class's size, its titles and its records per group, and --base reporting a record entering or leaving it as `titled in` and `titled out` with the titles read. This replaces #1477's choice that `Dr.Ahmed` read title `Dr.` stays a miss. config_diff's gaps and score drop a record any configuration reads into the class from every column. Co-Authored-By: Claude Opus 5.5 --- tests/v2/test_config_diff.py | 23 ++++++ tests/v2/test_local_agreement.py | 115 ++++++++++++++++++++++++-- tools/differential/config_diff.py | 28 ++++--- tools/differential/local_agreement.py | 110 ++++++++++++++++++++---- 4 files changed, 247 insertions(+), 29 deletions(-) diff --git a/tests/v2/test_config_diff.py b/tests/v2/test_config_diff.py index b73e3e235..989cbb0b8 100644 --- a/tests/v2/test_config_diff.py +++ b/tests/v2/test_config_diff.py @@ -531,6 +531,29 @@ def test_score_rows_counts_agreement_and_fixes_and_breaks_against_the_first() -> assert lines[-1].split()[5:] == ["[0]", "+0.00", "0/0"] +def test_score_rows_drops_a_record_any_configuration_reads_with_a_typed_title() -> None: + # #1501: `Dr` typed into the given box is a class of its own, so a + # configuration that reads it as the title neither breaks the record + # nor is credited with it; every column drops it alike. + no_dr = 'expr:Parser(lexicon=Lexicon.default().remove("dr", kind="title"))' + rows = [_orcid("Dr Ana Souza", "Dr Ana", "Souza"), _orcid("Ana López", "Ana", "López")] + specs = (no_dr, "default") + readings = cd._read_chunk([(r["name"], None, specs) for r in rows])[1] + listed = cd.local_agreement._title_words(Lexicon.default()) + scored, per = cd.score_rows(rows, cd.local_agreement.FIELDED[cd.ORCID], readings, listed) + assert scored == 1 + assert [(s.agree, s.fixed, s.broken) for s in per] == [(1, 0, 0), (1, 0, 0)] + # The control: with the class off, the default breaks it. + with pytest.MonkeyPatch.context() as patch: + patch.setattr(cd.local_agreement, "titled", lambda *args: False) + scored, per = cd.score_rows(rows, cd.local_agreement.FIELDED[cd.ORCID], readings, + listed) + assert scored == 2 and [(s.agree, s.broken) for s in per] == [(2, 0), (1, 1)] + # gaps drops it from both columns the same way. + result = _score([(cd.ORCID, "XX", r) for r in rows], specs) + assert result["groups"][f"{cd.ORCID} XX"]["scored"] == 1 + + def test_score_selects_a_named_group_or_a_languages_countries( monkeypatch: pytest.MonkeyPatch) -> None: _psc(monkeypatch, [("Ana Souza", "Brazilian"), ("Bo Lima", "French"), diff --git a/tests/v2/test_local_agreement.py b/tests/v2/test_local_agreement.py index 19e652036..6861efcb6 100644 --- a/tests/v2/test_local_agreement.py +++ b/tests/v2/test_local_agreement.py @@ -531,9 +531,11 @@ def test_a_given_box_holding_the_middle_names_is_compared_with_both() -> None: "given": "Ann"} -def test_a_source_with_no_title_box_scores_a_read_title_as_a_miss_not_filer_error() -> None: +def test_a_source_with_no_title_box_counts_a_title_typed_as_a_given_name_apart() -> None: + # #1501: neither a miss nor filer error set aside, but a class of its own. reading = agreement.read(_held("Dr Ann", "Lee"), _ORCID_FIELDS, Parser(), _LISTED) - assert (reading.got, reading.set_aside) == ({"given+middle": "Ann"}, False) + assert (reading.got, reading.set_aside, reading.titled) == ( + {"given+middle": "Ann"}, False, "Dr") def test_a_peeled_suffix_is_compared_inside_the_family_box_of_a_joined_source() -> None: @@ -567,16 +569,119 @@ def test_a_box_the_parse_cuts_after_its_full_stops_agrees(given: str) -> None: ("AB", "Lee", {"given+middle": ""}), # A word of the family box read into the given box's field. ("K.S", "Perera Silva", {"given+middle": "K. S Perera", "family": "Silva"}), - # A title glued before the box's initials, peeled to a field ORCID has no box for. + # A title glued before the box's letters, peeled to a field ORCID + # has no box for: since #1501 a class of its own (titled), not an + # agreement, which the cut alone would not make it. ("Dr.A.B.", "Perera", {"given+middle": "A. B."}), - # A word peeled out of the field at the full stop it is glued by. ("Dr.Ahmed", "Hassan", {"given+middle": "Ahmed"}), ]) -def test_a_misreading_beside_a_cut_at_a_full_stop_stays_a_miss( +def test_a_misreading_beside_a_cut_at_a_full_stop_never_agrees( given: str, family: str, got: dict[str, str]) -> None: assert agreement.read(_held(given, family), _ORCID_FIELDS, Parser(), _LISTED).got == got +# -- a listed title typed into the given-names box (#1501) --------------------- + +_PV_FIELDS = agreement.FIELDED[corpora.PV] + + +@pytest.mark.parametrize(("given", "family", "title", "got"), [ + ("Dr. Anna", "Berg", "Dr.", "Anna"), + ("Dr/ Anna", "Berg", "Dr", "Anna"), # a slash for the full stop (#1149) + ("د. منى", "حسن", "د.", "منى"), + ("Dr.Ahmed", "Hassan", "Dr.", "Ahmed"), # glued, cut at its full stop (#1477) + ("Prof. Dr. Anna", "Berg", "Prof. Dr.", "Anna"), + ("Dr. Anna Maria", "Berg", "Dr.", "Anna Maria"), +]) +@pytest.mark.parametrize("fielded", [_ORCID_FIELDS, _PV_FIELDS], ids=["orcid", "patentsview"]) +def test_a_listed_title_typed_into_the_given_box_is_counted_apart( + given: str, family: str, title: str, got: str, fielded: object) -> None: + reading = agreement.read(_held(given, family), fielded, Parser(), _LISTED) + assert (reading.got, reading.titled, reading.set_aside) == ( + {"given+middle": got}, title, False) + + +def test_a_title_typed_into_the_forename_box_beside_an_empty_title_box_is_counted_apart( + ) -> None: + reading = agreement.read(_filed("", "Dr Anna", "Maria", "Berg"), _PSC_FIELDS, + Parser(), _LISTED) + assert (reading.got, reading.titled) == ({"title": "Dr", "given": "Anna"}, "Dr") + + +@pytest.mark.parametrize(("record", "fielded", "got"), [ + # A title the vocabulary does not list, read by its shape alone: the + # mistake a source with no title box exists to catch. + (_held("Xyz. Anna", "Berg"), _ORCID_FIELDS, {"given+middle": "Anna"}), + # A box holding only a title: no names in it to agree. + (_held("Dr", "Berg"), _ORCID_FIELDS, {"given+middle": ""}), + # A title typed into the family box, read as the title after it. + (_held("Anna", "Berg Dr."), _ORCID_FIELDS, {"family": "Berg"}), + # Another field disagrees too. + (_held("Dr Anna", "Berg Silva"), _ORCID_FIELDS, {"given+middle": "Anna Berg", + "family": "Silva"}), + # A title box filed: the title is scored against it. + (_filed("Mrs", "Dr Anna", surname="Berg"), _PSC_FIELDS, {"title": "Mrs Dr", + "given": "Anna"}), + # A box holding only a title, the names in the next box. + (_filed("", "Dr", "Anna", "Berg"), _PSC_FIELDS, {"title": "Dr", "given": "Anna", + "middle": ""}), +]) +def test_a_title_outside_the_class_stays_a_miss( + record: dict[str, str], fielded: object, got: dict[str, str]) -> None: + reading = agreement.read(record, fielded, Parser(), _LISTED) + assert (reading.got, reading.titled) == (got, "") + + +def test_a_title_word_the_parse_reads_as_a_given_name_agrees() -> None: + # `Dean` is a title only inside a title phrase (rules/H9), so the + # parse reads the box's words as its names. + reading = agreement.read(_held("Dean Anna", "Berg"), _ORCID_FIELDS, Parser(), _LISTED) + assert (reading.got, reading.titled) == ({}, "") + + +#: How many of the class's rows (the parametrized rows above, in both +#: sources) the scorer read as misses before #1501: the guard's negative +#: control, re-taken whenever its rows or the parse move. +_TITLED_ROWS = (("Dr. Anna", "Berg"), ("Dr/ Anna", "Berg"), ("د. منى", "حسن"), + ("Dr.Ahmed", "Hassan"), ("Prof. Dr. Anna", "Berg"), ("Dr. Anna Maria", "Berg")) +_UNTITLED_EFFECT = 6 + + +def test_the_titled_class_is_counted_apart_from_the_agreement_figure( + monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(agreement, "GROUP_FLOOR", 1) + rows = [_held(g, f) for g, f in _TITLED_ROWS] + [_held("Ann", "Lee"), + _held("Xyz. Anna", "Berg")] + result = agreement.score(rows, _ORCID_FIELDS, Parser()) + assert result.scored == {"NZ": 2} and result.agreed == {"NZ": 1} + assert result.titled == {"Dr.": 3, "Dr": 1, "د.": 1, "Prof. Dr.": 1} + assert all(result.entries[agreement.key(r)].get("titled") for r in rows[:6]) + lines = "\n".join(agreement.report(result, _ORCID_FIELDS, 5)) + assert "every field agrees: 1 of 2 (50.0%)" in lines + assert result.titled_groups == {"NZ": 6} + assert " NZ 2 50.0% 1 0 6" in lines + assert "read as the title: 6 (counted apart" in lines + assert "titles most often read in the given-names box:\n 3 Dr." in lines + # The negative control: with the class off, each of its rows is a miss. + monkeypatch.setattr(agreement, "titled", lambda *args: False) + off = agreement.score(rows, _ORCID_FIELDS, Parser()) + assert sum(off.scored.values()) - sum(off.agreed.values()) - 1 == _UNTITLED_EFFECT + assert not off.titled + + +def test_a_record_entering_or_leaving_the_titled_class_is_reported_apart() -> None: + miss = {"got": {"given+middle": "Anna"}} + titled = {"got": {"given+middle": "Anna"}, "titled": "Dr."} + old = {"a": miss, "c": titled, "d": titled, "e": miss} + new = {"a": titled, "b": titled, "c": miss, "e": {"got": {"family": "Lee"}}} + found = agreement.moves(old, new) + assert found == {"regression": [], "progress": [], "changed": ["e"], + "titled in": ["a", "b"], "titled out": ["c", "d"]} + lines = agreement.summarize(found, old, new) + assert "titled in: 2 records, a title typed into the given-names box (Dr. 2)" in lines + assert "titled out: 2 records, a title typed into the given-names box (Dr. 2)" in lines + + def test_a_cut_across_two_boxes_stays_a_miss() -> None: # psc-individuals compares each box alone: `Md.Karim` typed in the # forename box and read given `Md.`, middle `Karim` puts a word in diff --git a/tools/differential/config_diff.py b/tools/differential/config_diff.py index 9046ac93b..ec86a6ec1 100644 --- a/tools/differential/config_diff.py +++ b/tools/differential/config_diff.py @@ -89,15 +89,20 @@ name is evidence of nothing; the 2026-10-30 entry of decisions/vocabulary-model filtered so); PSC's are set aside by local_agreement.read with the default's title words, the same records -in every column. Each group is its first --cap records in raw.jsonl's +in every column, and a record either column reads with a listed title +typed into the given-names box (local_agreement.titled, #1501; in PSC a +title in the forename box with the title box empty) is dropped from +both. Each group is its first --cap records in raw.jsonl's order. **score**: configurations scored against the filed boxes, a row a group. For each group of the same three fielded corpora (`--group` as the corpus writes it, `--languages` the groups whose country writes one of those tags, or every group), its first --cap records, less the given -boxes opening with a title word and, in ORCID and PatentsView, the -records with an empty box, each configuration's share of records +boxes opening with a title word, the records any configuration reads +with a title typed into the given-names box (local_agreement.titled) +and, in ORCID and PatentsView, the records with an empty box, each +configuration's share of records agreeing in every box (local_agreement.read), and for the best one the records it fixes and breaks against the first. `--switches` names bool `Policy` fields and reads every configuration under every combination @@ -922,6 +927,8 @@ def word(w: str) -> WordCount: if rp.set_aside: continue rs = local_agreement.read(record, fielded, _Parsed(s), listed) # type: ignore[arg-type] + if rp.titled or rs.titled: # a title typed into the given box (#1501) + continue count.scored += 1 count.plain += not rp.got count.strict += not rs.got @@ -1056,19 +1063,20 @@ def score_rows(rows: Sequence[dict[str, str]], fielded: local_agreement.Fielded, ) -> tuple[int, list[SpecScore]]: """`rows` scored under each configuration's reading: the records scored (local_agreement.read's set-aside, judged under the first - configuration, dropped from every column) and each one's score.""" + configuration, and its title typed into the given-names box, under + any, each dropped from every column) and each one's score.""" n_specs = len(readings[0]) if readings else 0 out = [SpecScore() for _ in range(n_specs)] scored = 0 for record, rs in zip(rows, readings): - first = local_agreement.read(record, fielded, _Parsed(rs[0]), listed) # type: ignore[arg-type] - if first.set_aside: + mine = [local_agreement.read(record, fielded, _Parsed(r), listed) # type: ignore[arg-type] + for r in rs] + if mine[0].set_aside or any(m.titled for m in mine): continue scored += 1 - ok0 = not first.got - for i, r in enumerate(rs): - ok = ok0 if i == 0 else not local_agreement.read( - record, fielded, _Parsed(r), listed).got # type: ignore[arg-type] + ok0 = not mine[0].got + for i, m in enumerate(mine): + ok = not m.got out[i].agree += ok out[i].fixed += ok and not ok0 out[i].broken += ok0 and not ok diff --git a/tools/differential/local_agreement.py b/tools/differential/local_agreement.py index bb569d90f..423e504fb 100644 --- a/tools/differential/local_agreement.py +++ b/tools/differential/local_agreement.py @@ -75,6 +75,18 @@ counts where at least TITLE_FLOOR records share one (the --top commonest), as leads for the vocabulary (a title nobody listed lands there as well). +- Where the filer typed a listed title into the given-names box (`Dr. + Anna`, `Dr/ Anna`, `Dr.Ahmed`) and the parse reads it as the title and + the rest of the box as the box's names, every other field agreeing and + no title box filed, the record is a class of its own (titled, #1501): + the parse is right and the box is what differs, so it is counted in + neither the agreeing records nor the misses, the agreement figure is + taken over the records outside it, and the report prints the titles + read there, so a reader checks the words (a given name wrongly peeled + as a title, a leading `Dean`, lands there too) rather than the + records. A title the vocabulary does not list (`Xyz. Anna`, read by + its shape), a box holding only a title, and a title typed into the + family box stay misses. The record is keyed to the corpus's records and to the scorer's own code (scorer_fingerprint), so a refetch, or a change to how a field is @@ -236,14 +248,18 @@ def unlisted(title: str, listed: frozenset[str]) -> bool: @dataclass(frozen=True) class Reading: """One record's reading: each field as parsed where it disagrees - with the box, whether the record was set aside, and whether the - family agreed only with the parser's suffix appended.""" + with the box, whether the record was set aside, whether the family + agreed only with the parser's suffix appended, and the title the + parse read where the filer typed it into the given-names box + (titled).""" got: dict[str, str] set_aside: bool = False by_suffix: bool = False + titled: str = "" def entry(self) -> dict[str, Any]: - return {"got": self.got, **({"set_aside": True} if self.set_aside else {})} + return {"got": self.got, **({"set_aside": True} if self.set_aside else {}), + **({"titled": self.titled} if self.titled else {})} def read(record: dict[str, str], fielded: Fielded, parser: Parser, @@ -263,9 +279,34 @@ def read(record: dict[str, str], fielded: Fielded, parser: Parser, title = record.get(_box(fielded, "title"), "") if fielded.sets_aside and title and "title" in wrong and unlisted(title, listed): return Reading(wrong, set_aside=True) + if titled(record, fielded, name.title, got, wrong, listed): + return Reading(wrong, titled=name.title) return Reading(wrong, by_suffix=by_suffix and not wrong) +def titled(record: dict[str, str], fielded: Fielded, title: str, got: dict[str, str], + wrong: dict[str, str], listed: frozenset[str]) -> bool: + """Whether the filer typed a listed title into the given-names box + (#1501): the parse read a `title` whose every word the vocabulary + lists, no title box was filed, the given-names box is that title + followed by the box's names as read (agrees; a slash typed for the + title's full stop, `Dr/ Anna`, read as one), and nothing else + disagrees but that box and, where the source has one, the empty + title box. A box holding the title alone has no names to agree.""" + box = _box(fielded, "given") + role = fielded.fields.get(box, "") + title_role = fielded.fields.get(_box(fielded, "title"), "") + if not (title and role and got[role]) or unlisted(title, listed) \ + or record.get(_box(fielded, "title"), "").strip(): + return False + if set(wrong) != {role, *filter(None, [title_role])}: + return False + words = record.get(box, "").split() + typed = [w[:-1] + "." if i < len(title.split()) and w.endswith("/") else w + for i, w in enumerate(words)] + return agrees(" ".join(typed), f"{title} {got[role]}") + + def _box(fielded: Fielded, role: str) -> str: """The box `role` is compared with, or "" where none holds it.""" return next((box for box, r in fielded.fields.items() if role in r.split("+")), "") @@ -306,6 +347,11 @@ class Score: shapes: Counter[str] by_suffix: int entries: dict[str, dict[str, Any]] + #: The titles the parse read in the given-names box (titled), with + #: how many records each, and those records per group: counted apart + #: from the scored records. + titled: Counter[str] = field(default_factory=Counter) + titled_groups: Counter[str] = field(default_factory=Counter) def score(rows: Iterator[dict[str, str]] | list[dict[str, str]], fielded: Fielded, @@ -335,6 +381,10 @@ def score(rows: Iterator[dict[str, str]] | list[dict[str, str]], fielded: Fielde result.set_aside[record.get(_box(fielded, "title"), "")] += 1 continue group = group_of(record, fielded) + if reading.titled: + result.titled[reading.titled] += 1 + result.titled_groups[group] += 1 + continue result.scored[group] += 1 if not reading.got: result.agreed[group] += 1 @@ -380,18 +430,26 @@ def report(result: Score, fielded: Fielded, top: int) -> list[str]: f"every field agrees: {agreed:,} of {total:,} ({_pct(agreed, total).strip()})" + ("" if _box(fielded, "suffix") else f"; {result.by_suffix:,} of them with the parser's suffix in the surname box"), + f"a title typed into the given-names box, read as the title: " + f"{sum(result.titled.values()):,} (counted apart, neither agreeing nor missing)", "misses per field: " + ", ".join(f"{r} {misses[r]:,}" for r in roles), "", - f"by {fielded.group} (at least {floor:,} records), misses per field:", + f"by {fielded.group} (at least {floor:,} records), misses per field" + + (", and the titles typed into the given-names box:" if result.titled else ":"), f" {fielded.group:<24} {'records':>10} {'agree':>7} " - + " ".join(f"{r:>8}" for r in roles)] + + " ".join(f"{r:>8}" for r in roles) + + (f" {'titled':>8}" if result.titled else "")] for group, n in result.scored.most_common(): if n < floor: break row = result.misses.get(group, Counter()) out.append(f" {group[:24]:<24} {n:>10,} {_pct(result.agreed[group], n)} " - + " ".join(f"{row[r]:>8,}" for r in roles)) + + " ".join(f"{row[r]:>8,}" for r in roles) + + (f" {result.titled_groups[group]:>8,}" if result.titled else "")) out += ["", f"the {top} commonest disagreement shapes (field: words filed->parsed):"] out += [f" {n:>9,} {s}" for s, n in result.shapes.most_common(top)] + if result.titled: + out += ["", f"the {top} titles most often read in the given-names box:"] + out += [f" {n:>9,} {t}" for t, n in result.titled.most_common(top)] if fielded.sets_aside: out += ["", f"set-aside title boxes written by at least {TITLE_FLOOR} records:"] out += [f" {n:>9,} {t}" for t, n in result.set_aside.most_common() @@ -460,7 +518,7 @@ def read_record(path: Path, local: local_corpora.Local, locale: str = "" #: What decides a record's reading, besides the parser: scorer_fingerprint #: hashes them, as local_corpora.fold_fingerprint hashes the word fold. -_SCORER_CODE = ("fold", "agrees", "_words", "_joined", "_title_words", "unlisted", "read", "_box", "Reading", +_SCORER_CODE = ("fold", "agrees", "_words", "_joined", "_title_words", "unlisted", "read", "titled", "_box", "Reading", "key", "score", "_read_chunk", "parser_of") @@ -561,27 +619,51 @@ def moves(old: dict[str, dict[str, Any]], new: dict[str, dict[str, Any]], ) -> dict[str, list[str]]: """Each record whose reading moved, by kind: `regression` (it agreed and now does not), `progress` (it disagreed and now agrees), - `changed` (it disagrees, or is set aside, differently). Both sides - read the same fetch, so no record is gained or lost.""" - found: dict[str, list[str]] = {"regression": [], "progress": [], "changed": []} + `changed` (it disagrees, or is set aside, differently), and apart + from those `titled in` and `titled out`, a record entering or + leaving the class of a title typed into the given-names box + (titled), which is neither agreeing nor missing. Both sides read the + same fetch, so no record is gained or lost.""" + found: dict[str, list[str]] = {"regression": [], "progress": [], "changed": [], + "titled in": [], "titled out": []} for k in sorted(set(old) | set(new)): - if k not in old: + was, now = old.get(k), new.get(k) + if was == now: + continue + if _titled_entry(now) and not _titled_entry(was): + found["titled in"].append(k) + elif _titled_entry(was) and not _titled_entry(now): + found["titled out"].append(k) + elif was is None: found["regression"].append(k) - elif k not in new: + elif now is None: found["progress"].append(k) - elif old[k] != new[k]: + else: found["changed"].append(k) return found +def _titled_entry(entry: dict[str, Any] | None) -> bool: + return bool(entry and entry.get("titled")) + + def summarize(found: dict[str, list[str]], old: dict[str, dict[str, Any]], new: dict[str, dict[str, Any]]) -> list[str]: """One line per kind of move, with the fields it moved: a field - counts where the record disagrees on it on either side.""" + counts where the record disagrees on it on either side. A move into + or out of the titled class names the titles read there instead, so + a reader checks the words rather than the records.""" out = [] for kind, keys in found.items(): if not keys: continue + if kind.startswith("titled"): + side = new if kind == "titled in" else old + titles = Counter(side[k]["titled"] for k in keys) + out.append(f"{kind}: {len(keys):,} records, a title typed into the given-names " + f"box (" + ", ".join(f"{t} {n:,}" for t, n in titles.most_common(10)) + + ")") + continue fields: Counter[str] = Counter() for k in keys: fields.update(set(old.get(k, {}).get("got", {})) | set(new.get(k, {}).get("got", {}))) From 54e88d8a6038c732a33e6e7634fb52e5b1a9cf69 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Fri, 20 Nov 2026 14:41:13 -0800 Subject: [PATCH 2/4] Pin each clause of the titled class and describe it where the score is (#1501) A row for each clause no other refuses (another field disagreeing, a box holding more than the title and names), cz-candidates' rows, the filed-title clause pinned directly, gaps read both ways round, three configurations in score_rows, a record titled on both sides, glued `Dr/Anna` recorded as outside the class, and `titled` in the fingerprint test. The report's groups run by the records they hold, the class among them, and the module docstring's example is `Hon`, which the measurement found, not `Dean`, which the parse reads as a given name. tools/differential/README.md and AGENTS.md describe the class and its size on 2026-11-20. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- tests/v2/test_config_diff.py | 14 +++++-- tests/v2/test_local_agreement.py | 55 +++++++++++++++++++++++---- tools/differential/README.md | 2 +- tools/differential/local_agreement.py | 14 ++++--- 5 files changed, 69 insertions(+), 18 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f9296d456..b17af6cd0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -329,7 +329,7 @@ The 2.0 rewrite landed as underscore-private modules beside the v1 code, which 2 **Measuring a change to the group suggester: use `tools/differential/suggest_measure.py`.** Run it after any change to `nameparser/_suggest.py`, to `nameparser/config/_order_names.py` (or `tools/vocab/order_names.py`, which writes it) or to a predicate a signal reads (the capitals, particle and patronymic tests, and the title, suffix and numeral tests a name is read past), or to rules/O9 or rules/O6, whose readings the `capitals_as_family` and `two_family_names` votes ask of the parse itself: `suggest` moves no parse, so the snapshot and every corpus check report nothing. It draws groups of known order, 2, 3, 4, 5, 10, 20, 50 and 200 names by default (a change to a threshold adds `--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000`: a share counted among the names that vote holds at 200 names and fails past it, which no default size shows, and #1442's two stray votes decided lists of 500 and more for that reason), from the local corpora and reports the share of groups read right by size, the same-order rows being the anti-goal (at least 95% at every size, save `pv-listed-given`'s two same-order rows, a list of nothing but given names that are surnames the ORCID surname table lists (`Cooper`, `Burke`, `Clarke`), which that table reads the wrong way round, a cost left open (decisions/group-suggestion, 2026-11-19 #1364), save `orcid-givcaps`' two same-order rows, a list writing its given names in capitals (`ANNA Smith`), which the capitals signal reads the wrong way round by design (decisions/group-suggestion, 2026-11-12 CAPITALS), and `orcid-byline-joined`'s given-first row at 50 and 100 names, and at 200 until #1357, a list of nothing but `AM Hoy` bylines that the few names the name tables vote on decide (decisions/group-suggestion, 2026-11-14 #1355, which took `orcid-byline`'s own row off this list, as #1397 took `orcid-famcaps-short`'s); groups of 2 to 4 are where #1308's final review found a patronymic rule forcing given-first on a family-first base); `--set NAME=VALUE` overrides a threshold, and `--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 --set _MIN_TWO_FAMILY_VOTES=1000000` decides nothing and is the harness proof (the order count alone leaves the patronymic rule free to decide its own given-first order, the two vote counts leave the letters setting free to decide, and the last holds `two_family_names`; `_MIN_VOTES` also holds `capitals_as_family`, whose table `--set _MIN_CAPITALS_LETTERS=1000000` empties alone). A change to the `two_family_names` vote reads the `orcid-span-CC` populations (ORCID holders of a country, the boxes saying which words are the family) by country: the groups deciding the switch, which the countries the switch costs (Bangladesh, Ghana, Kenya, Pakistan, Vietnam, Angola, Mozambique, Turkey) must not reach, and whole names right under the suggestion against the base (decisions/group-suggestion, 2026-11-19 #1452). A table change also moves the `print(suggestion)` evidence docs/getting-started.rst and docs/suggest.rst show as doctests, which `uv run pytest` does not run: run `uv run sphinx-build -b doctest docs ` too (#1374's ORCID table made `Wang Xiaoming` a given-name vote and failed every build job). Its figures are quoted in `Parser.suggest`'s docstring, docs/suggest.rst and docs/design/decisions/group-suggestion.md; re-take all three when they move (decisions/group-suggestion's THRESHOLDS entry names the command, and its latest dated entries carrying re-taken sizes, 2026-11-19 #1364's, #1447's and #1452's, hold the figures the other two round; the 2026-11-12 CAPITALS entry holds the `capitals_as_family` table, which the docstring's and docs/suggest.rst's capitals sentences round). A signal that reads one of the pipeline's predicates must read it exactly where the pipeline's rule does, no wider and no narrower, and its tests need a row at each edge: #1310's patronymic signal first voted an `-ovich` ending on any word (wider: two-word `Abramovich Roman` decided East Slavic and forced given-first), then its fix refused one on the first word, which rules/O1 never asks about (narrower: `Abramovich Roman Arkadyevich`, which the rule reads right, cast nothing). Only the second review caught the narrowing. A signal that votes where exactly ONE end of a name is listed votes by the other end alone once one end is no longer read: #1355's first sketch stopped looking up a short capitals word opening a name, and `WU Zhi` then cast a given-first surname vote by `Zhi`, so the shipped rule silences the signal on the whole name; when a rule stops reading a word, put a name whose other word is listed too in its grid. And a rule keyed to a word's shape needs a population of nothing but that shape: the default populations mix short capitals surnames with long ones, so the ending word's twin of that defect (`Zhi LI`) went unseen from #1308 until #1355 cut `orcid-famcaps-short`, and #1397 fixed it (decisions/group-suggestion, 2026-11-14 #1355 and #1397). A setting has more than one effect, and a suggestion that leaves something out leaves it out on every base: #1356 was first decided on "the East Slavic rule stands down under a family-first order", true of its reordering and false of its `patronymic` view, and PR #1399 as first pushed then kept every family-first base's order. Five names written `Zzyvan Petrovich Qqsidorov` under `FAMILY_FIRST` were read family `Zzyvan` where master moved the base and read them right; and `SIDOROV Ivan Petrovich` five times under `FAMILY_FIRST_GIVEN_LAST` lost the rule, though `capitals_as_family`, suggested in the same patch, makes the rule name the patronymic there. Review found both; the tool's table was identical with and without them, its populations then holding neither shape and no `FAMILY_FIRST_GIVEN_LAST` base anywhere in it (it has read the parliament lists under one since, which catches the second kind on a real list; its draws still run under two bases). Before deciding what a suggestion leaves out, sweep every base order × every switch the same patch can turn on × both written positions of the word the rule reads, and compare whole names read right (given and family), not the family alone: `FAMILY_FIRST_GIVEN_LAST` reads the family of `Sidorov Ivan Petrovich` right and its given name wrong, which a family count scored as nothing to fix. One signal is wider on purpose, and says so where it is decided: the letters signal (#1254) counts a run joined with full stops (`B.K.`), which rules/O8 never moves, beside the spaced runs it does, since three quarters of Nepal's runs are written joined (decisions/group-suggestion, 2026-11-11 LETTER RUNS); a test holds every other run to the rule exactly. -**Validating a new parsing rule** — before implementing, simulate it in a throwaway script against `TEST_NAMES` (plus a few target-language examples) to catch regressions/false-positives early. E.g. this surfaced the `last_base` `do`/`st`/`mc` empties and the patronymic `"David Michael Abramovich"` false-reorder. After the change, `tests/v2/test_snapshot.py` lists every corpus name it moved, grouped by changed field -- read them, and re-record with `uv run python tools/differential/snapshot.py --record` once every move is intended, so the PR diff of `snapshot.jsonl` shows the reviewer the same list. `uv run python tools/differential/cldr_agreement.py` reports how the tree's agreement with CLDR's stated name fields moved; `tests/v2/test_cldr_agreement.py` fails on any move, and `tools/differential/cldr_agreement.json` doubles as a measured list of names the parser and CLDR read differently. The same command and test score the GND corpus's real names (`gnd_fields.jsonl`, record `gnd_agreement.json`) by the same rules, and `--record` rewrites every record, printing per source what it accepts. A locale-pack change reads the second view the same command prints, per pack (`cldr_agreement_locales.json`, #672, and `wikidata_native_agreement_locales.json` for real Han and kana names); its `JA` rows run only with the `ja` extra installed. A change to Han, Hangul or kana order or to Korean segmentation reads `wikidata_native_agreement.json` too: the only real names in those scripts the corpora hold. It holds no honorific, so a change to the honorific peel moves nothing there. A change to comma or credential handling also reads the local corpus of hand-typed names (`snapshot.py --local ctgov-officials --base `, which reads the base from a baseline kept for its package's files and never the shared snapshot beside the corpus (a base read once from the same fetch is copied rather than parsed again; `--sample N` reads a fixed sample while iterating; the shared snapshot beside the corpus is one file per source for every worktree, and #752's phase 2f found ctgov reporting a sibling branch's 1,334 joined-credential readings as its own moves against it); tools/differential/README.md's "Local corpora"): the one population of names nobody chose for a test or a catalog, so it shows how often each shape is typed, and the one no CI run sees. A change to title handling reads `ukec-individuals` the same way: UK donors' names in spoken order and mixed case, in 8,219 of whose 15,214 `parse()` read a title on 2026-10-22. A change to English titles, honorifics or post-nominals also reads `snapshot.py --local govuk-people` the same way: GOV.UK's display names of ministers, officials and officers, the title run and the post-nominals as an office writes them (`The Rt Hon`, `Sir`, `Baroness`, ranks; `KC`, `CBE`, `KCB`), in 2,093 of whose 6,021 `parse()` read one or both on 2026-10-30. A change to Spanish titles, to the `es` pack, or to how a title marks where a name starts after an office reads `snapshot.py --local dof-signatures` the same way: the names in the signature blocks of Mexico's Diario Oficial for 2025, cut from the clause that names the signatory's office, 65.4% of its 33,565 signatures opening with a title (`Lic.`, `Dr.`, `Mtro.`, `C.`, `Licenciada`, `C.P.`), whose first word `parse()` read as a title in 82.1% and `parser_for(locales.ES)` in 86.8% on 2026-10-31. A change to particles or generational words reads `snapshot.py --local tse-donors` the same way, Brazilian names in spoken order dense with both. A change to initials, to a title word outside English, or to how a script's combining marks are read reads `snapshot.py --local nepal-candidates` the same way: Nepal's local election candidates, each a romanized name (surnames written as initials, `B.K.`, `K.C.`; honorific titles such as `Guru` in front, `Shekh`, a title there until #752's phase 2j made it one only inside a title phrase, and `Md.`, a title by its period's shape until #1383 made it Muhammad written short, the given name) beside the same name in Devanagari, written with vowel signs and the virama, combining marks the letter-shape tests do not count as letters (decisions/nfd-shapes), and with the joiners ZWJ and ZWNJ. It is the only large population of South Asian names the corpora hold, and its corpus reads both scripts. A change to non-Latin scripts or to Arabic-script names reads `snapshot.py --local jrc-names` the same way, and `local_corpora.py groups jrc-names`: the spellings of one person across scripts and transliterations, harvested from news text, with 17,074 Arabic-script spellings where the committed corpora hold 315 distinct names with an Arabic letter, 96 of them CLDR's fictional renderings (2026-10-24), and under a licence that keeps even a reading of one of its names in the cache. A change to patronymics, to Turkic or East Slavic names, to Indic titles and initials, or to Slavic or Portuguese double surnames reads `snapshot.py --local opensanctions-parliaments --base ` the same way, and `local_corpora.py groups opensanctions-parliaments`: the members of twenty-eight national chambers as each parliament writes them (Azerbaijan, the Central Asian chambers, Turkey, Croatia, Slovenia, Slovakia, Portugal, India, Ukraine, Belarus, Russia, Indonesia, Ethiopia, South Korea, Israel, Mongolia, and since 2026-11-19 Malaysia, Pakistan's two chambers, Egypt and Somalia, #1465) and Indonesia's 2018 regional heads, read through OpenSanctions, 26,515 spellings of 20,856 members on 2026-11-19 (24,302 of 19,283 on 2026-11-12, before the five chambers and some other lists' newer exports; 24,084 of 19,216 on 2026-11-08, before the Khural and other lists' newer exports), some members' aliases in another script (Kazakh beside Russian Cyrillic, Uzbek Cyrillic beside Latin, Devanagari beside Latin, Hangul and Hanja or Hebrew beside Latin) or with a title (`Shri`, `Smt.`), the population issues #1186 to #1192 were read from, and the one that measures Indonesia's `H.` and `Imam` (#1205, #1206) Ethiopia's father's name (#1203), Korea's Hangul and Hanja (#1213, #1215, #1216) Israel's Hebrew (#1209 to #1211) and Mongolia's Cyrillic, the father's name first (#1237, `mn_parliament`, 126 members, added 2026-11-12), and Egypt's Arabic-script names, each written short and with the full chain of names (#1072, #1464); `config_diff.py --group ` keeps one parliament. A change to Malay, Indian-Malaysian or Chinese-Malaysian names (`bin`, `binti`, `B.`, `bt`, `a/l`, `a/p`, `anak`, the `@` alias, `MD`, honorifics such as `Ustaz` and `Cikgu` opening a name, a Chinese name written family first) or to names written wholly in capitals reads `snapshot.py --local my-candidates --base ` the same way: Malaysia's election candidates of 2008 to 2023 as their ballots name them, in capitals, 3,077 distinct names on 2026-11-19, grouped by the ethnicity each file states (`config_diff.py --group chinese`), the population issues #1467, #1468, #1164, #1183 and #1179 were read from. A change that cuts one written word across two fields, or joins two written words, first reads how `local_agreement.py` compares a box (`agrees`, tools/differential/README.md): 3.1's #1296 cut `B.A.S.D.` into given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records scored a miss though read right until #1470 (measured 2026-11-19). A change to which field a word lands in also reads `local_agreement.py psc-individuals --base ` the same way: real names with the four boxes their filers typed them into (UK companies' people with significant control), scored field by field and by nationality; and `local_agreement.py orcid-researchers --base `, ORCID holders' own two boxes (given names, family name) from every country, scored by the country they work or live in -- a population each person split for themselves, academic but worldwide, the one to read for a change a language pack makes. Its `name` is COMPOSED from those boxes, given first, so it cannot show which word a writer put first: a count of where a word falls in it is fixed by construction, and #1163's 538 records with the trailing letters in the family box against 0 with the word before them (`Lakshmi R S`, never `R S Lakshmi`) reproduced from that field. Order is measured on the free-text `credit` name (125,960 of the 2026-10-27 fetch's 1,831,533 records, which lean towards bibliographic bylines), against the boxes (decisions/O8); and `local_agreement.py patentsview-inventors --base `, US patents' inventors in the two boxes their filings give, split by a professional filer, with how many people filed under each name in each country, the one to read for how common a name's word is among a country's US-patent inventors. A change to titles or post-nominals, or to the `cs` pack, reads `local_agreement.py cz-candidates --base `, and with `--locale cs` too: Czech election candidates' four boxes (the title before the name, given names, surname, the title after it), scored by election, the only population whose titles are stated apart from the name, 36% of its 170,181 records titled (2026-10-30), nearly all academic degrees; its names are composed from the boxes (`Ing. Jan Novák, Ph.D.`), so it says nothing about how a writer spaces or punctuates them. A change to family-first order, to Vietnamese names or to their titles reads `local_agreement.py uit-vinames --base ` and `local_agreement.py vn-assembly --base `, and with `--locale vi`, `locales.VI` being that pack (#1108): 21,090 distinct names and 499 National Assembly deputies written family name first with their diacritics, whose parts no one filed but the convention derives (first word the family, last the given, the words between the middle name), so they score middle names, which ORCID's two boxes cannot, and `vn-assembly` the `GS.`/`PGS.`/`TS.`/`ThS.` titles composed from the education each deputy states. These are the only real fielded populations outside the committed fields files, and no CI run sees them either. +**Validating a new parsing rule** — before implementing, simulate it in a throwaway script against `TEST_NAMES` (plus a few target-language examples) to catch regressions/false-positives early. E.g. this surfaced the `last_base` `do`/`st`/`mc` empties and the patronymic `"David Michael Abramovich"` false-reorder. After the change, `tests/v2/test_snapshot.py` lists every corpus name it moved, grouped by changed field -- read them, and re-record with `uv run python tools/differential/snapshot.py --record` once every move is intended, so the PR diff of `snapshot.jsonl` shows the reviewer the same list. `uv run python tools/differential/cldr_agreement.py` reports how the tree's agreement with CLDR's stated name fields moved; `tests/v2/test_cldr_agreement.py` fails on any move, and `tools/differential/cldr_agreement.json` doubles as a measured list of names the parser and CLDR read differently. The same command and test score the GND corpus's real names (`gnd_fields.jsonl`, record `gnd_agreement.json`) by the same rules, and `--record` rewrites every record, printing per source what it accepts. A locale-pack change reads the second view the same command prints, per pack (`cldr_agreement_locales.json`, #672, and `wikidata_native_agreement_locales.json` for real Han and kana names); its `JA` rows run only with the `ja` extra installed. A change to Han, Hangul or kana order or to Korean segmentation reads `wikidata_native_agreement.json` too: the only real names in those scripts the corpora hold. It holds no honorific, so a change to the honorific peel moves nothing there. A change to comma or credential handling also reads the local corpus of hand-typed names (`snapshot.py --local ctgov-officials --base `, which reads the base from a baseline kept for its package's files and never the shared snapshot beside the corpus (a base read once from the same fetch is copied rather than parsed again; `--sample N` reads a fixed sample while iterating; the shared snapshot beside the corpus is one file per source for every worktree, and #752's phase 2f found ctgov reporting a sibling branch's 1,334 joined-credential readings as its own moves against it); tools/differential/README.md's "Local corpora"): the one population of names nobody chose for a test or a catalog, so it shows how often each shape is typed, and the one no CI run sees. A change to title handling reads `ukec-individuals` the same way: UK donors' names in spoken order and mixed case, in 8,219 of whose 15,214 `parse()` read a title on 2026-10-22. A change to English titles, honorifics or post-nominals also reads `snapshot.py --local govuk-people` the same way: GOV.UK's display names of ministers, officials and officers, the title run and the post-nominals as an office writes them (`The Rt Hon`, `Sir`, `Baroness`, ranks; `KC`, `CBE`, `KCB`), in 2,093 of whose 6,021 `parse()` read one or both on 2026-10-30. A change to Spanish titles, to the `es` pack, or to how a title marks where a name starts after an office reads `snapshot.py --local dof-signatures` the same way: the names in the signature blocks of Mexico's Diario Oficial for 2025, cut from the clause that names the signatory's office, 65.4% of its 33,565 signatures opening with a title (`Lic.`, `Dr.`, `Mtro.`, `C.`, `Licenciada`, `C.P.`), whose first word `parse()` read as a title in 82.1% and `parser_for(locales.ES)` in 86.8% on 2026-10-31. A change to particles or generational words reads `snapshot.py --local tse-donors` the same way, Brazilian names in spoken order dense with both. A change to initials, to a title word outside English, or to how a script's combining marks are read reads `snapshot.py --local nepal-candidates` the same way: Nepal's local election candidates, each a romanized name (surnames written as initials, `B.K.`, `K.C.`; honorific titles such as `Guru` in front, `Shekh`, a title there until #752's phase 2j made it one only inside a title phrase, and `Md.`, a title by its period's shape until #1383 made it Muhammad written short, the given name) beside the same name in Devanagari, written with vowel signs and the virama, combining marks the letter-shape tests do not count as letters (decisions/nfd-shapes), and with the joiners ZWJ and ZWNJ. It is the only large population of South Asian names the corpora hold, and its corpus reads both scripts. A change to non-Latin scripts or to Arabic-script names reads `snapshot.py --local jrc-names` the same way, and `local_corpora.py groups jrc-names`: the spellings of one person across scripts and transliterations, harvested from news text, with 17,074 Arabic-script spellings where the committed corpora hold 315 distinct names with an Arabic letter, 96 of them CLDR's fictional renderings (2026-10-24), and under a licence that keeps even a reading of one of its names in the cache. A change to patronymics, to Turkic or East Slavic names, to Indic titles and initials, or to Slavic or Portuguese double surnames reads `snapshot.py --local opensanctions-parliaments --base ` the same way, and `local_corpora.py groups opensanctions-parliaments`: the members of twenty-eight national chambers as each parliament writes them (Azerbaijan, the Central Asian chambers, Turkey, Croatia, Slovenia, Slovakia, Portugal, India, Ukraine, Belarus, Russia, Indonesia, Ethiopia, South Korea, Israel, Mongolia, and since 2026-11-19 Malaysia, Pakistan's two chambers, Egypt and Somalia, #1465) and Indonesia's 2018 regional heads, read through OpenSanctions, 26,515 spellings of 20,856 members on 2026-11-19 (24,302 of 19,283 on 2026-11-12, before the five chambers and some other lists' newer exports; 24,084 of 19,216 on 2026-11-08, before the Khural and other lists' newer exports), some members' aliases in another script (Kazakh beside Russian Cyrillic, Uzbek Cyrillic beside Latin, Devanagari beside Latin, Hangul and Hanja or Hebrew beside Latin) or with a title (`Shri`, `Smt.`), the population issues #1186 to #1192 were read from, and the one that measures Indonesia's `H.` and `Imam` (#1205, #1206) Ethiopia's father's name (#1203), Korea's Hangul and Hanja (#1213, #1215, #1216) Israel's Hebrew (#1209 to #1211) and Mongolia's Cyrillic, the father's name first (#1237, `mn_parliament`, 126 members, added 2026-11-12), and Egypt's Arabic-script names, each written short and with the full chain of names (#1072, #1464); `config_diff.py --group ` keeps one parliament. A change to Malay, Indian-Malaysian or Chinese-Malaysian names (`bin`, `binti`, `B.`, `bt`, `a/l`, `a/p`, `anak`, the `@` alias, `MD`, honorifics such as `Ustaz` and `Cikgu` opening a name, a Chinese name written family first) or to names written wholly in capitals reads `snapshot.py --local my-candidates --base ` the same way: Malaysia's election candidates of 2008 to 2023 as their ballots name them, in capitals, 3,077 distinct names on 2026-11-19, grouped by the ethnicity each file states (`config_diff.py --group chinese`), the population issues #1467, #1468, #1164, #1183 and #1179 were read from. A change that cuts one written word across two fields, or joins two written words, first reads how `local_agreement.py` compares a box (`agrees`, tools/differential/README.md): 3.1's #1296 cut `B.A.S.D.` into given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records scored a miss though read right until #1470 (measured 2026-11-19). A change to title vocabulary reads its `titled in` and `titled out` lines, not its regressions: a listed title the filer typed into the given-names box and the parse reads as the title is counted apart from the agreement figure since #1501, 9,145 `orcid-researchers` records on 2026-11-20, so a word that starts or stops being read as a title moves records into or out of that class, listed by the titles read. A change to which field a word lands in also reads `local_agreement.py psc-individuals --base ` the same way: real names with the four boxes their filers typed them into (UK companies' people with significant control), scored field by field and by nationality; and `local_agreement.py orcid-researchers --base `, ORCID holders' own two boxes (given names, family name) from every country, scored by the country they work or live in -- a population each person split for themselves, academic but worldwide, the one to read for a change a language pack makes. Its `name` is COMPOSED from those boxes, given first, so it cannot show which word a writer put first: a count of where a word falls in it is fixed by construction, and #1163's 538 records with the trailing letters in the family box against 0 with the word before them (`Lakshmi R S`, never `R S Lakshmi`) reproduced from that field. Order is measured on the free-text `credit` name (125,960 of the 2026-10-27 fetch's 1,831,533 records, which lean towards bibliographic bylines), against the boxes (decisions/O8); and `local_agreement.py patentsview-inventors --base `, US patents' inventors in the two boxes their filings give, split by a professional filer, with how many people filed under each name in each country, the one to read for how common a name's word is among a country's US-patent inventors. A change to titles or post-nominals, or to the `cs` pack, reads `local_agreement.py cz-candidates --base `, and with `--locale cs` too: Czech election candidates' four boxes (the title before the name, given names, surname, the title after it), scored by election, the only population whose titles are stated apart from the name, 36% of its 170,181 records titled (2026-10-30), nearly all academic degrees; its names are composed from the boxes (`Ing. Jan Novák, Ph.D.`), so it says nothing about how a writer spaces or punctuates them. A change to family-first order, to Vietnamese names or to their titles reads `local_agreement.py uit-vinames --base ` and `local_agreement.py vn-assembly --base `, and with `--locale vi`, `locales.VI` being that pack (#1108): 21,090 distinct names and 499 National Assembly deputies written family name first with their diacritics, whose parts no one filed but the convention derives (first word the family, last the given, the words between the middle name), so they score middle names, which ORCID's two boxes cannot, and `vn-assembly` the `GS.`/`PGS.`/`TS.`/`ThS.` titles composed from the education each deputy states. These are the only real fielded populations outside the committed fields files, and no CI run sees them either. ## Gotchas diff --git a/tests/v2/test_config_diff.py b/tests/v2/test_config_diff.py index 989cbb0b8..717cf5029 100644 --- a/tests/v2/test_config_diff.py +++ b/tests/v2/test_config_diff.py @@ -549,9 +549,17 @@ def test_score_rows_drops_a_record_any_configuration_reads_with_a_typed_title() scored, per = cd.score_rows(rows, cd.local_agreement.FIELDED[cd.ORCID], readings, listed) assert scored == 2 and [(s.agree, s.broken) for s in per] == [(2, 0), (1, 1)] - # gaps drops it from both columns the same way. - result = _score([(cd.ORCID, "XX", r) for r in rows], specs) - assert result["groups"][f"{cd.ORCID} XX"]["scored"] == 1 + # gaps drops it from both columns the same way, whichever reads the + # title: the plain choice listing it and the strict one not is the + # direction a strict gap meets. + for pair in (specs, specs[::-1]): + result = _score([(cd.ORCID, "XX", r) for r in rows], pair) + assert result["groups"][f"{cd.ORCID} XX"]["scored"] == 1, pair + # Any configuration, not the first or the last alone. + three = (no_dr, "default", no_dr) + readings = cd._read_chunk([(r["name"], None, three) for r in rows])[1] + scored, per = cd.score_rows(rows, cd.local_agreement.FIELDED[cd.ORCID], readings, listed) + assert scored == 1 def test_score_selects_a_named_group_or_a_languages_countries( diff --git a/tests/v2/test_local_agreement.py b/tests/v2/test_local_agreement.py index 6861efcb6..8c438b66d 100644 --- a/tests/v2/test_local_agreement.py +++ b/tests/v2/test_local_agreement.py @@ -291,6 +291,7 @@ def test_a_record_written_by_another_scorer_is_refused( assert agreement.scorer_fingerprint(_PSC) != before, "its own boxes" for name, changed in (("fold", lambda text: text.casefold()), ("score", lambda rows, fielded, parser: None), + ("titled", lambda *args: False), ("key", lambda record: str(record))): with monkeypatch.context() as patch: patch.setattr(agreement, name, changed) @@ -616,9 +617,18 @@ def test_a_title_typed_into_the_forename_box_beside_an_empty_title_box_is_counte (_held("Dr", "Berg"), _ORCID_FIELDS, {"given+middle": ""}), # A title typed into the family box, read as the title after it. (_held("Anna", "Berg Dr."), _ORCID_FIELDS, {"family": "Berg"}), - # Another field disagrees too. + # Another field disagrees too, the given box agreeing (the family + # box's nickname is no family; the set check alone refuses it). + (_held("Dr Anna", "Berg (Lee)"), _ORCID_FIELDS, {"family": "Berg"} | { + "given+middle": "Anna"}), (_held("Dr Anna", "Berg Silva"), _ORCID_FIELDS, {"given+middle": "Anna Berg", "family": "Silva"}), + # The box holds more than the title and the names read (a nickname), + # nothing else disagreeing: the comparison alone refuses it. + (_held("Dr (Ann) Anna", "Berg"), _ORCID_FIELDS, {"given+middle": "Anna"}), + # A slash glued inside a word is not read as the title's full stop; + # only a title word ending in it is (`Dr/ Anna`). + (_held("Dr/Anna", "Berg"), _ORCID_FIELDS, {"given+middle": "Anna"}), # A title box filed: the title is scored against it. (_filed("Mrs", "Dr Anna", surname="Berg"), _PSC_FIELDS, {"title": "Mrs Dr", "given": "Anna"}), @@ -639,9 +649,9 @@ def test_a_title_word_the_parse_reads_as_a_given_name_agrees() -> None: assert (reading.got, reading.titled) == ({}, "") -#: How many of the class's rows (the parametrized rows above, in both -#: sources) the scorer read as misses before #1501: the guard's negative -#: control, re-taken whenever its rows or the parse move. +#: How many of the class's rows (the parametrized rows above, read as +#: ORCID records) the scorer read as misses before #1501: the guard's +#: negative control, re-taken whenever its rows or the parse move. _TITLED_ROWS = (("Dr. Anna", "Berg"), ("Dr/ Anna", "Berg"), ("د. منى", "حسن"), ("Dr.Ahmed", "Hassan"), ("Prof. Dr. Anna", "Berg"), ("Dr. Anna Maria", "Berg")) _UNTITLED_EFFECT = 6 @@ -665,17 +675,20 @@ def test_the_titled_class_is_counted_apart_from_the_agreement_figure( # The negative control: with the class off, each of its rows is a miss. monkeypatch.setattr(agreement, "titled", lambda *args: False) off = agreement.score(rows, _ORCID_FIELDS, Parser()) - assert sum(off.scored.values()) - sum(off.agreed.values()) - 1 == _UNTITLED_EFFECT assert not off.titled + assert sum(bool(agreement.read(r, _ORCID_FIELDS, Parser(), _LISTED).got) + for r in rows[:6]) == _UNTITLED_EFFECT def test_a_record_entering_or_leaving_the_titled_class_is_reported_apart() -> None: miss = {"got": {"given+middle": "Anna"}} titled = {"got": {"given+middle": "Anna"}, "titled": "Dr."} - old = {"a": miss, "c": titled, "d": titled, "e": miss} - new = {"a": titled, "b": titled, "c": miss, "e": {"got": {"family": "Lee"}}} + other = {"got": {"given+middle": "Anna"}, "titled": "Prof. Dr."} + old = {"a": miss, "c": titled, "d": titled, "e": miss, "f": titled} + new = {"a": titled, "b": titled, "c": miss, "e": {"got": {"family": "Lee"}}, "f": other} found = agreement.moves(old, new) - assert found == {"regression": [], "progress": [], "changed": ["e"], + # A record in the class on both sides, read with another title, changed. + assert found == {"regression": [], "progress": [], "changed": ["e", "f"], "titled in": ["a", "b"], "titled out": ["c", "d"]} lines = agreement.summarize(found, old, new) assert "titled in: 2 records, a title typed into the given-names box (Dr. 2)" in lines @@ -841,6 +854,32 @@ def _volby_read(record: dict[str, str], fielded: object = _VOLBY_FIELDS return reading.got, reading.set_aside, reading.by_suffix +@pytest.mark.parametrize(("record", "titled"), [ + # A listed title typed into the given-names box, the title box empty, + # whatever stands after the name. + (_candidate("", "Dr. Jan", "Novák"), "Dr."), + (_candidate("", "Mgr. Jan", "Novák", "Ph.D."), "Mgr."), + # The title box filed: the title is scored against it. + (_candidate("Ing.", "Dr. Jan", "Novák"), ""), + # A title the default vocabulary does not list. + (_candidate("", "Ing. Jan", "Novák"), ""), +]) +def test_a_source_with_a_title_box_counts_a_title_in_the_given_box_only_where_it_is_empty( + record: dict[str, str], titled: str) -> None: + assert agreement.read(record, _VOLBY_FIELDS, Parser(), _LISTED).titled == titled + + +def test_a_filed_title_box_keeps_a_record_out_of_the_titled_class() -> None: + # A filed title box puts its words in the parse's title, so the + # comparison refuses such a record too; this pins the clause itself. + got, wrong = {"title": "Dr", "given": "Anna", "middle": "", "family": "Berg"}, { + "title": "Dr", "given": "Anna"} + record = {"forename": "Dr Anna", "surname": "Berg"} + assert agreement.titled(record, _PSC_FIELDS, "Dr", got, wrong, _LISTED) + assert not agreement.titled({**record, "title": "Dr"}, _PSC_FIELDS, "Dr", got, wrong, + _LISTED) + + def test_a_suffix_is_compared_with_the_box_after_the_name_not_the_surname() -> None: assert _volby_read(_candidate("Ing.", "Jan", "Novák", "Ph.D.")) == ({}, False, False) # The control: read as a source with no suffix box, the parser's diff --git a/tools/differential/README.md b/tools/differential/README.md index f08bc237a..b184ba0c5 100644 --- a/tools/differential/README.md +++ b/tools/differential/README.md @@ -361,7 +361,7 @@ Its score reads the title before the name against `TITULPRED`, the given and mid `my-candidates` downloads the five pinned files and refuses one whose sha256 is not the pinned one (retried first, as a body cut short), then, in this order, one of another header than the file's pinned one, one whose body does not end with a line break or whose last row is short (as `opensanctions-parliaments` does), one holding another number of rows than pinned, and past their shares rows of another width (`MY_MAX_BAD`) and rows with an empty name in a column read (`MY_MAX_NAMELESS`), a row counted once however many of its columns are empty. Its data date is the pinned commit's, and a corpus read at another `MY_COMMIT` or by another `MY_READ_VERSION` is refused on load. It holds no fields, so it is a `snapshot.py --local` population, not a `local_agreement.py` one. The fetch took under a second on 2026-11-19. -`local_agreement.py` does the SCORE job for a local corpus. It parses each filed display name and compares the parser's roles with the boxes the source states (title, given, middle and family for `psc-individuals`; given and middle joined against the given-names box, then family, for `orcid-researchers` and `patentsview-inventors`; title, given and middle joined, family and suffix for `cz-candidates`; family, middle and given, the parts derived, for `uit-vinames`; and title, family, middle and given for `vn-assembly`), folding case, periods, commas and spacing. Where the source has no box after the name, a suffix the parser peels is compared inside the surname box: the display name joins the surname last, so a trailing suffix was typed into it whenever it is filled, with or without a comma (`Smith, Jr.`); the fold read the comma as a miss until 2026-10-28, which moved 83 `psc-individuals` records and 561 `orcid-researchers` records to agreeing and none away. Joining two fields to compare them with one box puts a space between them, which the fold cannot tell from one the filer typed, and a reading that cuts one written word across the two makes it false: 3.1's run of initials (#1296, rules/T7) reads the box `B.A.S.D.` as given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records (403 of them Sri Lanka's) and 35 `patentsview-inventors` records scored a miss with the box's letters in the box's field (measured 2026-11-19), until #1470 had a word agree with the reading that cuts it after one or more of its initials, and #1477 after any full stop the filer typed, whatever stands before it (`Md.Karim` read `Md.`, `Karim`: 168 `orcid-researchers` records and 1 `patentsview-inventors` record moved on 2026-11-19, 146 of them Bangladesh's). `agrees` holds the rule, guarded by `test_a_reading_cut_only_after_a_full_stop_is_never_scored_a_miss` with a recorded negative control; a run with no full stop, a full stop the reading lost, a word left over or peeled to another field (`Dr.Ahmed` read title `Dr.`), other letters, and a cut across two boxes a source states apart (`psc-individuals`' forename and middle name) still score a miss. A parser change that cuts one written word across two fields, or joins two written words, reads `agrees` before trusting the score it moves. Where a source has a title box, and save `cz-candidates` (above), a title the parser reads otherwise, holding a word the vocabulary lists as neither a title nor a connective (a job typed as a title), is set aside as filer error rather than scored, and the report lists the commonest such titles as leads for the vocabulary. The report gives agreement overall and by the group the source states (nationality, country), misses per field, and the commonest disagreement shapes, as counts, word counts and the commonest set-aside titles; `--list N` prints moved records, names and all, for reading locally. Its record, `agreement.jsonl` beside the corpus, holds every record that did not wholly agree, so a re-run reports what moved. As with the local snapshot, check it from the branch against a base you name (`--base `, whose record is kept under `agreements/` beside the corpus, keyed by the fetch, the base's `nameparser/` files, the interpreter's minor version and the scorer, the ten most recent kept; the scorer's fingerprint reads only its own source's `FIELDED` entry, so adding a source leaves the others' records standing, which the whole table, hashed until `patentsview-inventors` was added on 2026-10-28, did not), or, alone, record the shared one from the base checkout (`--record --tree `) and run it from the branch; it refuses a record from another fetch, or one written by another version of the scorer, whose own change would otherwise read as the parser's moves. `--locale cs` scores the parser of a locale pack, `parser_for(locales.CS)`, against a record of its own (`agreement.cs.jsonl`, and kept records keyed by the locale too), so a pack's score and the default's never stand for each other; `measure.py` runs the default's alone. No CI run sees it. +`local_agreement.py` does the SCORE job for a local corpus. It parses each filed display name and compares the parser's roles with the boxes the source states (title, given, middle and family for `psc-individuals`; given and middle joined against the given-names box, then family, for `orcid-researchers` and `patentsview-inventors`; title, given and middle joined, family and suffix for `cz-candidates`; family, middle and given, the parts derived, for `uit-vinames`; and title, family, middle and given for `vn-assembly`), folding case, periods, commas and spacing. Where the source has no box after the name, a suffix the parser peels is compared inside the surname box: the display name joins the surname last, so a trailing suffix was typed into it whenever it is filled, with or without a comma (`Smith, Jr.`); the fold read the comma as a miss until 2026-10-28, which moved 83 `psc-individuals` records and 561 `orcid-researchers` records to agreeing and none away. Joining two fields to compare them with one box puts a space between them, which the fold cannot tell from one the filer typed, and a reading that cuts one written word across the two makes it false: 3.1's run of initials (#1296, rules/T7) reads the box `B.A.S.D.` as given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records (403 of them Sri Lanka's) and 35 `patentsview-inventors` records scored a miss with the box's letters in the box's field (measured 2026-11-19), until #1470 had a word agree with the reading that cuts it after one or more of its initials, and #1477 after any full stop the filer typed, whatever stands before it (`Md.Karim` read `Md.`, `Karim`: 168 `orcid-researchers` records and 1 `patentsview-inventors` record moved on 2026-11-19, 146 of them Bangladesh's). `agrees` holds the rule, guarded by `test_a_reading_cut_only_after_a_full_stop_is_never_scored_a_miss` with a recorded negative control; a run with no full stop, a full stop the reading lost, a word left over, other letters, and a cut across two boxes a source states apart (`psc-individuals`' forename and middle name) still score a miss. A parser change that cuts one written word across two fields, or joins two written words, reads `agrees` before trusting the score it moves. A listed title the filer typed into the given-names box and the parse reads as the title, the rest of the box read as the box's names (`Dr. Anna`, `Dr/ Anna`, `د. منى`, and `Dr.Ahmed`, which #1477 left a miss), every other field agreeing and no title box filed, is a class of its own (`titled`, #1501): the parse is right and the box is what differs, so it counts as neither agreeing nor missing, the agreement figure is taken over the records outside it, and the report gives its size, its records per group and the titles read there, so a reader checks the words, a given name wrongly peeled among them (`Hon`, a Cantonese given name the default reads as the style, #999), rather than the records. On 2026-11-20 it held 9,145 `orcid-researchers` records (Pakistan 835, Bangladesh 595, Iraq 572; `Dr.` 5,311, `Dr` 1,807), 90 `patentsview-inventors` records (`Hon` 39) and 6 `psc-individuals` records, every one a miss before, raising ORCID's figure from 81.1% to 81.5%. A title the vocabulary does not list (`Xyz. Anna`, read by its shape), a box holding only a title, a title typed into the family box and a title box filed stay out of it. `--base` reports a record entering or leaving the class as `titled in` or `titled out`, with the titles read, apart from the regressions and progress, so a change to the title vocabulary reads those lines for its ORCID and PatentsView moves; `config_diff.py`'s `gaps` and `score` drop a record any configuration reads into the class from every column. Where a source has a title box, and save `cz-candidates` (above), a title the parser reads otherwise, holding a word the vocabulary lists as neither a title nor a connective (a job typed as a title), is set aside as filer error rather than scored, and the report lists the commonest such titles as leads for the vocabulary. The report gives agreement overall and by the group the source states (nationality, country), misses per field, and the commonest disagreement shapes, as counts, word counts and the commonest set-aside titles; `--list N` prints moved records, names and all, for reading locally. Its record, `agreement.jsonl` beside the corpus, holds every record that did not wholly agree, so a re-run reports what moved. As with the local snapshot, check it from the branch against a base you name (`--base `, whose record is kept under `agreements/` beside the corpus, keyed by the fetch, the base's `nameparser/` files, the interpreter's minor version and the scorer, the ten most recent kept; the scorer's fingerprint reads only its own source's `FIELDED` entry, so adding a source leaves the others' records standing, which the whole table, hashed until `patentsview-inventors` was added on 2026-10-28, did not), or, alone, record the shared one from the base checkout (`--record --tree `) and run it from the branch; it refuses a record from another fetch, or one written by another version of the scorer, whose own change would otherwise read as the parser's moves. `--locale cs` scores the parser of a locale pack, `parser_for(locales.CS)`, against a record of its own (`agreement.cs.jsonl`, and kept records keyed by the locale too), so a pack's score and the default's never stand for each other; `measure.py` runs the default's alone. No CI run sees it. `pairs` reads a paired source (`tse-donors`, whose records carry the registry's name beside the filed one) as two spellings of one person, and sorts each pair by how the filed name departs from the reference: the first of its shapes that fits, from case, accents (case unchanged) and case and accents together, through words left out, shortened or misspelled, to few words in common. A word left out or added counts once per pair, and is listed only when ten pairs share it. `--agreement` also parses both spellings of every pair with a reference name that differs, and counts the pairs whose two readings end the family name in the same word (two readings with no family name share none). It lists the accents-only pairs read with two surnames by the two spellings' last words, the same ten-pair floor applied. diff --git a/tools/differential/local_agreement.py b/tools/differential/local_agreement.py index 423e504fb..6983983b6 100644 --- a/tools/differential/local_agreement.py +++ b/tools/differential/local_agreement.py @@ -82,8 +82,9 @@ the parse is right and the box is what differs, so it is counted in neither the agreeing records nor the misses, the agreement figure is taken over the records outside it, and the report prints the titles - read there, so a reader checks the words (a given name wrongly peeled - as a title, a leading `Dean`, lands there too) rather than the + read there, so a reader checks the words (a given name the parse + wrongly peels as a title lands there too: `Hon`, a Cantonese given + name, in `Hon Kit` read title `Hon`, given `Kit`) rather than the records. A title the vocabulary does not list (`Xyz. Anna`, read by its shape), a box holding only a title, and a title typed into the family box stay misses. @@ -438,9 +439,12 @@ def report(result: Score, fielded: Fielded, top: int) -> list[str]: f" {fielded.group:<24} {'records':>10} {'agree':>7} " + " ".join(f"{r:>8}" for r in roles) + (f" {'titled':>8}" if result.titled else "")] - for group, n in result.scored.most_common(): - if n < floor: - break + # By the records a group holds, the class among them, so the class + # does not reorder groups of one size (a country at ORCID's cap). + sizes = result.scored + result.titled_groups + for group, _size in sizes.most_common(): + if (n := result.scored[group]) < floor: + continue row = result.misses.get(group, Counter()) out.append(f" {group[:24]:<24} {n:>10,} {_pct(result.agreed[group], n)} " + " ".join(f"{row[r]:>8,}" for r in roles) From a06f0e459856f962e713ad65bb93936dd5a1f28c Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Fri, 20 Nov 2026 14:47:12 -0800 Subject: [PATCH 3/4] Make the titled class's control fail with the class on, and fix its prose (#1501) The negative control counted read()'s misses, which a record in the class has too, so it held with the class on; it now scores the class's rows with the class off. The class's rows are one tuple, both the glued-title rows check `titled`, each refusal row has its own comment, and the Arabic row has an invented surname. The moves docstring says a record that agreed and is now titled is `titled in`, never a regression, and AGENTS.md now says to read those lines beside the regressions rather than instead of them. The report's descriptions, config_diff's docstrings and the README's countries (India first) are brought in line. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- tests/v2/test_local_agreement.py | 41 ++++++++++++++++----------- tools/differential/README.md | 2 +- tools/differential/config_diff.py | 15 ++++++---- tools/differential/local_agreement.py | 25 +++++++++------- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b17af6cd0..35b0b98ea 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -329,7 +329,7 @@ The 2.0 rewrite landed as underscore-private modules beside the v1 code, which 2 **Measuring a change to the group suggester: use `tools/differential/suggest_measure.py`.** Run it after any change to `nameparser/_suggest.py`, to `nameparser/config/_order_names.py` (or `tools/vocab/order_names.py`, which writes it) or to a predicate a signal reads (the capitals, particle and patronymic tests, and the title, suffix and numeral tests a name is read past), or to rules/O9 or rules/O6, whose readings the `capitals_as_family` and `two_family_names` votes ask of the parse itself: `suggest` moves no parse, so the snapshot and every corpus check report nothing. It draws groups of known order, 2, 3, 4, 5, 10, 20, 50 and 200 names by default (a change to a threshold adds `--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000`: a share counted among the names that vote holds at 200 names and fails past it, which no default size shows, and #1442's two stray votes decided lists of 500 and more for that reason), from the local corpora and reports the share of groups read right by size, the same-order rows being the anti-goal (at least 95% at every size, save `pv-listed-given`'s two same-order rows, a list of nothing but given names that are surnames the ORCID surname table lists (`Cooper`, `Burke`, `Clarke`), which that table reads the wrong way round, a cost left open (decisions/group-suggestion, 2026-11-19 #1364), save `orcid-givcaps`' two same-order rows, a list writing its given names in capitals (`ANNA Smith`), which the capitals signal reads the wrong way round by design (decisions/group-suggestion, 2026-11-12 CAPITALS), and `orcid-byline-joined`'s given-first row at 50 and 100 names, and at 200 until #1357, a list of nothing but `AM Hoy` bylines that the few names the name tables vote on decide (decisions/group-suggestion, 2026-11-14 #1355, which took `orcid-byline`'s own row off this list, as #1397 took `orcid-famcaps-short`'s); groups of 2 to 4 are where #1308's final review found a patronymic rule forcing given-first on a family-first base); `--set NAME=VALUE` overrides a threshold, and `--set _MIN_VOTES=1000000 --set _MIN_PATRONYMIC_VOTES=1000000 --set _MIN_RUN_NAMES=1000000 --set _MIN_TWO_FAMILY_VOTES=1000000` decides nothing and is the harness proof (the order count alone leaves the patronymic rule free to decide its own given-first order, the two vote counts leave the letters setting free to decide, and the last holds `two_family_names`; `_MIN_VOTES` also holds `capitals_as_family`, whose table `--set _MIN_CAPITALS_LETTERS=1000000` empties alone). A change to the `two_family_names` vote reads the `orcid-span-CC` populations (ORCID holders of a country, the boxes saying which words are the family) by country: the groups deciding the switch, which the countries the switch costs (Bangladesh, Ghana, Kenya, Pakistan, Vietnam, Angola, Mozambique, Turkey) must not reach, and whole names right under the suggestion against the base (decisions/group-suggestion, 2026-11-19 #1452). A table change also moves the `print(suggestion)` evidence docs/getting-started.rst and docs/suggest.rst show as doctests, which `uv run pytest` does not run: run `uv run sphinx-build -b doctest docs ` too (#1374's ORCID table made `Wang Xiaoming` a given-name vote and failed every build job). Its figures are quoted in `Parser.suggest`'s docstring, docs/suggest.rst and docs/design/decisions/group-suggestion.md; re-take all three when they move (decisions/group-suggestion's THRESHOLDS entry names the command, and its latest dated entries carrying re-taken sizes, 2026-11-19 #1364's, #1447's and #1452's, hold the figures the other two round; the 2026-11-12 CAPITALS entry holds the `capitals_as_family` table, which the docstring's and docs/suggest.rst's capitals sentences round). A signal that reads one of the pipeline's predicates must read it exactly where the pipeline's rule does, no wider and no narrower, and its tests need a row at each edge: #1310's patronymic signal first voted an `-ovich` ending on any word (wider: two-word `Abramovich Roman` decided East Slavic and forced given-first), then its fix refused one on the first word, which rules/O1 never asks about (narrower: `Abramovich Roman Arkadyevich`, which the rule reads right, cast nothing). Only the second review caught the narrowing. A signal that votes where exactly ONE end of a name is listed votes by the other end alone once one end is no longer read: #1355's first sketch stopped looking up a short capitals word opening a name, and `WU Zhi` then cast a given-first surname vote by `Zhi`, so the shipped rule silences the signal on the whole name; when a rule stops reading a word, put a name whose other word is listed too in its grid. And a rule keyed to a word's shape needs a population of nothing but that shape: the default populations mix short capitals surnames with long ones, so the ending word's twin of that defect (`Zhi LI`) went unseen from #1308 until #1355 cut `orcid-famcaps-short`, and #1397 fixed it (decisions/group-suggestion, 2026-11-14 #1355 and #1397). A setting has more than one effect, and a suggestion that leaves something out leaves it out on every base: #1356 was first decided on "the East Slavic rule stands down under a family-first order", true of its reordering and false of its `patronymic` view, and PR #1399 as first pushed then kept every family-first base's order. Five names written `Zzyvan Petrovich Qqsidorov` under `FAMILY_FIRST` were read family `Zzyvan` where master moved the base and read them right; and `SIDOROV Ivan Petrovich` five times under `FAMILY_FIRST_GIVEN_LAST` lost the rule, though `capitals_as_family`, suggested in the same patch, makes the rule name the patronymic there. Review found both; the tool's table was identical with and without them, its populations then holding neither shape and no `FAMILY_FIRST_GIVEN_LAST` base anywhere in it (it has read the parliament lists under one since, which catches the second kind on a real list; its draws still run under two bases). Before deciding what a suggestion leaves out, sweep every base order × every switch the same patch can turn on × both written positions of the word the rule reads, and compare whole names read right (given and family), not the family alone: `FAMILY_FIRST_GIVEN_LAST` reads the family of `Sidorov Ivan Petrovich` right and its given name wrong, which a family count scored as nothing to fix. One signal is wider on purpose, and says so where it is decided: the letters signal (#1254) counts a run joined with full stops (`B.K.`), which rules/O8 never moves, beside the spaced runs it does, since three quarters of Nepal's runs are written joined (decisions/group-suggestion, 2026-11-11 LETTER RUNS); a test holds every other run to the rule exactly. -**Validating a new parsing rule** — before implementing, simulate it in a throwaway script against `TEST_NAMES` (plus a few target-language examples) to catch regressions/false-positives early. E.g. this surfaced the `last_base` `do`/`st`/`mc` empties and the patronymic `"David Michael Abramovich"` false-reorder. After the change, `tests/v2/test_snapshot.py` lists every corpus name it moved, grouped by changed field -- read them, and re-record with `uv run python tools/differential/snapshot.py --record` once every move is intended, so the PR diff of `snapshot.jsonl` shows the reviewer the same list. `uv run python tools/differential/cldr_agreement.py` reports how the tree's agreement with CLDR's stated name fields moved; `tests/v2/test_cldr_agreement.py` fails on any move, and `tools/differential/cldr_agreement.json` doubles as a measured list of names the parser and CLDR read differently. The same command and test score the GND corpus's real names (`gnd_fields.jsonl`, record `gnd_agreement.json`) by the same rules, and `--record` rewrites every record, printing per source what it accepts. A locale-pack change reads the second view the same command prints, per pack (`cldr_agreement_locales.json`, #672, and `wikidata_native_agreement_locales.json` for real Han and kana names); its `JA` rows run only with the `ja` extra installed. A change to Han, Hangul or kana order or to Korean segmentation reads `wikidata_native_agreement.json` too: the only real names in those scripts the corpora hold. It holds no honorific, so a change to the honorific peel moves nothing there. A change to comma or credential handling also reads the local corpus of hand-typed names (`snapshot.py --local ctgov-officials --base `, which reads the base from a baseline kept for its package's files and never the shared snapshot beside the corpus (a base read once from the same fetch is copied rather than parsed again; `--sample N` reads a fixed sample while iterating; the shared snapshot beside the corpus is one file per source for every worktree, and #752's phase 2f found ctgov reporting a sibling branch's 1,334 joined-credential readings as its own moves against it); tools/differential/README.md's "Local corpora"): the one population of names nobody chose for a test or a catalog, so it shows how often each shape is typed, and the one no CI run sees. A change to title handling reads `ukec-individuals` the same way: UK donors' names in spoken order and mixed case, in 8,219 of whose 15,214 `parse()` read a title on 2026-10-22. A change to English titles, honorifics or post-nominals also reads `snapshot.py --local govuk-people` the same way: GOV.UK's display names of ministers, officials and officers, the title run and the post-nominals as an office writes them (`The Rt Hon`, `Sir`, `Baroness`, ranks; `KC`, `CBE`, `KCB`), in 2,093 of whose 6,021 `parse()` read one or both on 2026-10-30. A change to Spanish titles, to the `es` pack, or to how a title marks where a name starts after an office reads `snapshot.py --local dof-signatures` the same way: the names in the signature blocks of Mexico's Diario Oficial for 2025, cut from the clause that names the signatory's office, 65.4% of its 33,565 signatures opening with a title (`Lic.`, `Dr.`, `Mtro.`, `C.`, `Licenciada`, `C.P.`), whose first word `parse()` read as a title in 82.1% and `parser_for(locales.ES)` in 86.8% on 2026-10-31. A change to particles or generational words reads `snapshot.py --local tse-donors` the same way, Brazilian names in spoken order dense with both. A change to initials, to a title word outside English, or to how a script's combining marks are read reads `snapshot.py --local nepal-candidates` the same way: Nepal's local election candidates, each a romanized name (surnames written as initials, `B.K.`, `K.C.`; honorific titles such as `Guru` in front, `Shekh`, a title there until #752's phase 2j made it one only inside a title phrase, and `Md.`, a title by its period's shape until #1383 made it Muhammad written short, the given name) beside the same name in Devanagari, written with vowel signs and the virama, combining marks the letter-shape tests do not count as letters (decisions/nfd-shapes), and with the joiners ZWJ and ZWNJ. It is the only large population of South Asian names the corpora hold, and its corpus reads both scripts. A change to non-Latin scripts or to Arabic-script names reads `snapshot.py --local jrc-names` the same way, and `local_corpora.py groups jrc-names`: the spellings of one person across scripts and transliterations, harvested from news text, with 17,074 Arabic-script spellings where the committed corpora hold 315 distinct names with an Arabic letter, 96 of them CLDR's fictional renderings (2026-10-24), and under a licence that keeps even a reading of one of its names in the cache. A change to patronymics, to Turkic or East Slavic names, to Indic titles and initials, or to Slavic or Portuguese double surnames reads `snapshot.py --local opensanctions-parliaments --base ` the same way, and `local_corpora.py groups opensanctions-parliaments`: the members of twenty-eight national chambers as each parliament writes them (Azerbaijan, the Central Asian chambers, Turkey, Croatia, Slovenia, Slovakia, Portugal, India, Ukraine, Belarus, Russia, Indonesia, Ethiopia, South Korea, Israel, Mongolia, and since 2026-11-19 Malaysia, Pakistan's two chambers, Egypt and Somalia, #1465) and Indonesia's 2018 regional heads, read through OpenSanctions, 26,515 spellings of 20,856 members on 2026-11-19 (24,302 of 19,283 on 2026-11-12, before the five chambers and some other lists' newer exports; 24,084 of 19,216 on 2026-11-08, before the Khural and other lists' newer exports), some members' aliases in another script (Kazakh beside Russian Cyrillic, Uzbek Cyrillic beside Latin, Devanagari beside Latin, Hangul and Hanja or Hebrew beside Latin) or with a title (`Shri`, `Smt.`), the population issues #1186 to #1192 were read from, and the one that measures Indonesia's `H.` and `Imam` (#1205, #1206) Ethiopia's father's name (#1203), Korea's Hangul and Hanja (#1213, #1215, #1216) Israel's Hebrew (#1209 to #1211) and Mongolia's Cyrillic, the father's name first (#1237, `mn_parliament`, 126 members, added 2026-11-12), and Egypt's Arabic-script names, each written short and with the full chain of names (#1072, #1464); `config_diff.py --group ` keeps one parliament. A change to Malay, Indian-Malaysian or Chinese-Malaysian names (`bin`, `binti`, `B.`, `bt`, `a/l`, `a/p`, `anak`, the `@` alias, `MD`, honorifics such as `Ustaz` and `Cikgu` opening a name, a Chinese name written family first) or to names written wholly in capitals reads `snapshot.py --local my-candidates --base ` the same way: Malaysia's election candidates of 2008 to 2023 as their ballots name them, in capitals, 3,077 distinct names on 2026-11-19, grouped by the ethnicity each file states (`config_diff.py --group chinese`), the population issues #1467, #1468, #1164, #1183 and #1179 were read from. A change that cuts one written word across two fields, or joins two written words, first reads how `local_agreement.py` compares a box (`agrees`, tools/differential/README.md): 3.1's #1296 cut `B.A.S.D.` into given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records scored a miss though read right until #1470 (measured 2026-11-19). A change to title vocabulary reads its `titled in` and `titled out` lines, not its regressions: a listed title the filer typed into the given-names box and the parse reads as the title is counted apart from the agreement figure since #1501, 9,145 `orcid-researchers` records on 2026-11-20, so a word that starts or stops being read as a title moves records into or out of that class, listed by the titles read. A change to which field a word lands in also reads `local_agreement.py psc-individuals --base ` the same way: real names with the four boxes their filers typed them into (UK companies' people with significant control), scored field by field and by nationality; and `local_agreement.py orcid-researchers --base `, ORCID holders' own two boxes (given names, family name) from every country, scored by the country they work or live in -- a population each person split for themselves, academic but worldwide, the one to read for a change a language pack makes. Its `name` is COMPOSED from those boxes, given first, so it cannot show which word a writer put first: a count of where a word falls in it is fixed by construction, and #1163's 538 records with the trailing letters in the family box against 0 with the word before them (`Lakshmi R S`, never `R S Lakshmi`) reproduced from that field. Order is measured on the free-text `credit` name (125,960 of the 2026-10-27 fetch's 1,831,533 records, which lean towards bibliographic bylines), against the boxes (decisions/O8); and `local_agreement.py patentsview-inventors --base `, US patents' inventors in the two boxes their filings give, split by a professional filer, with how many people filed under each name in each country, the one to read for how common a name's word is among a country's US-patent inventors. A change to titles or post-nominals, or to the `cs` pack, reads `local_agreement.py cz-candidates --base `, and with `--locale cs` too: Czech election candidates' four boxes (the title before the name, given names, surname, the title after it), scored by election, the only population whose titles are stated apart from the name, 36% of its 170,181 records titled (2026-10-30), nearly all academic degrees; its names are composed from the boxes (`Ing. Jan Novák, Ph.D.`), so it says nothing about how a writer spaces or punctuates them. A change to family-first order, to Vietnamese names or to their titles reads `local_agreement.py uit-vinames --base ` and `local_agreement.py vn-assembly --base `, and with `--locale vi`, `locales.VI` being that pack (#1108): 21,090 distinct names and 499 National Assembly deputies written family name first with their diacritics, whose parts no one filed but the convention derives (first word the family, last the given, the words between the middle name), so they score middle names, which ORCID's two boxes cannot, and `vn-assembly` the `GS.`/`PGS.`/`TS.`/`ThS.` titles composed from the education each deputy states. These are the only real fielded populations outside the committed fields files, and no CI run sees them either. +**Validating a new parsing rule** — before implementing, simulate it in a throwaway script against `TEST_NAMES` (plus a few target-language examples) to catch regressions/false-positives early. E.g. this surfaced the `last_base` `do`/`st`/`mc` empties and the patronymic `"David Michael Abramovich"` false-reorder. After the change, `tests/v2/test_snapshot.py` lists every corpus name it moved, grouped by changed field -- read them, and re-record with `uv run python tools/differential/snapshot.py --record` once every move is intended, so the PR diff of `snapshot.jsonl` shows the reviewer the same list. `uv run python tools/differential/cldr_agreement.py` reports how the tree's agreement with CLDR's stated name fields moved; `tests/v2/test_cldr_agreement.py` fails on any move, and `tools/differential/cldr_agreement.json` doubles as a measured list of names the parser and CLDR read differently. The same command and test score the GND corpus's real names (`gnd_fields.jsonl`, record `gnd_agreement.json`) by the same rules, and `--record` rewrites every record, printing per source what it accepts. A locale-pack change reads the second view the same command prints, per pack (`cldr_agreement_locales.json`, #672, and `wikidata_native_agreement_locales.json` for real Han and kana names); its `JA` rows run only with the `ja` extra installed. A change to Han, Hangul or kana order or to Korean segmentation reads `wikidata_native_agreement.json` too: the only real names in those scripts the corpora hold. It holds no honorific, so a change to the honorific peel moves nothing there. A change to comma or credential handling also reads the local corpus of hand-typed names (`snapshot.py --local ctgov-officials --base `, which reads the base from a baseline kept for its package's files and never the shared snapshot beside the corpus (a base read once from the same fetch is copied rather than parsed again; `--sample N` reads a fixed sample while iterating; the shared snapshot beside the corpus is one file per source for every worktree, and #752's phase 2f found ctgov reporting a sibling branch's 1,334 joined-credential readings as its own moves against it); tools/differential/README.md's "Local corpora"): the one population of names nobody chose for a test or a catalog, so it shows how often each shape is typed, and the one no CI run sees. A change to title handling reads `ukec-individuals` the same way: UK donors' names in spoken order and mixed case, in 8,219 of whose 15,214 `parse()` read a title on 2026-10-22. A change to English titles, honorifics or post-nominals also reads `snapshot.py --local govuk-people` the same way: GOV.UK's display names of ministers, officials and officers, the title run and the post-nominals as an office writes them (`The Rt Hon`, `Sir`, `Baroness`, ranks; `KC`, `CBE`, `KCB`), in 2,093 of whose 6,021 `parse()` read one or both on 2026-10-30. A change to Spanish titles, to the `es` pack, or to how a title marks where a name starts after an office reads `snapshot.py --local dof-signatures` the same way: the names in the signature blocks of Mexico's Diario Oficial for 2025, cut from the clause that names the signatory's office, 65.4% of its 33,565 signatures opening with a title (`Lic.`, `Dr.`, `Mtro.`, `C.`, `Licenciada`, `C.P.`), whose first word `parse()` read as a title in 82.1% and `parser_for(locales.ES)` in 86.8% on 2026-10-31. A change to particles or generational words reads `snapshot.py --local tse-donors` the same way, Brazilian names in spoken order dense with both. A change to initials, to a title word outside English, or to how a script's combining marks are read reads `snapshot.py --local nepal-candidates` the same way: Nepal's local election candidates, each a romanized name (surnames written as initials, `B.K.`, `K.C.`; honorific titles such as `Guru` in front, `Shekh`, a title there until #752's phase 2j made it one only inside a title phrase, and `Md.`, a title by its period's shape until #1383 made it Muhammad written short, the given name) beside the same name in Devanagari, written with vowel signs and the virama, combining marks the letter-shape tests do not count as letters (decisions/nfd-shapes), and with the joiners ZWJ and ZWNJ. It is the only large population of South Asian names the corpora hold, and its corpus reads both scripts. A change to non-Latin scripts or to Arabic-script names reads `snapshot.py --local jrc-names` the same way, and `local_corpora.py groups jrc-names`: the spellings of one person across scripts and transliterations, harvested from news text, with 17,074 Arabic-script spellings where the committed corpora hold 315 distinct names with an Arabic letter, 96 of them CLDR's fictional renderings (2026-10-24), and under a licence that keeps even a reading of one of its names in the cache. A change to patronymics, to Turkic or East Slavic names, to Indic titles and initials, or to Slavic or Portuguese double surnames reads `snapshot.py --local opensanctions-parliaments --base ` the same way, and `local_corpora.py groups opensanctions-parliaments`: the members of twenty-eight national chambers as each parliament writes them (Azerbaijan, the Central Asian chambers, Turkey, Croatia, Slovenia, Slovakia, Portugal, India, Ukraine, Belarus, Russia, Indonesia, Ethiopia, South Korea, Israel, Mongolia, and since 2026-11-19 Malaysia, Pakistan's two chambers, Egypt and Somalia, #1465) and Indonesia's 2018 regional heads, read through OpenSanctions, 26,515 spellings of 20,856 members on 2026-11-19 (24,302 of 19,283 on 2026-11-12, before the five chambers and some other lists' newer exports; 24,084 of 19,216 on 2026-11-08, before the Khural and other lists' newer exports), some members' aliases in another script (Kazakh beside Russian Cyrillic, Uzbek Cyrillic beside Latin, Devanagari beside Latin, Hangul and Hanja or Hebrew beside Latin) or with a title (`Shri`, `Smt.`), the population issues #1186 to #1192 were read from, and the one that measures Indonesia's `H.` and `Imam` (#1205, #1206) Ethiopia's father's name (#1203), Korea's Hangul and Hanja (#1213, #1215, #1216) Israel's Hebrew (#1209 to #1211) and Mongolia's Cyrillic, the father's name first (#1237, `mn_parliament`, 126 members, added 2026-11-12), and Egypt's Arabic-script names, each written short and with the full chain of names (#1072, #1464); `config_diff.py --group ` keeps one parliament. A change to Malay, Indian-Malaysian or Chinese-Malaysian names (`bin`, `binti`, `B.`, `bt`, `a/l`, `a/p`, `anak`, the `@` alias, `MD`, honorifics such as `Ustaz` and `Cikgu` opening a name, a Chinese name written family first) or to names written wholly in capitals reads `snapshot.py --local my-candidates --base ` the same way: Malaysia's election candidates of 2008 to 2023 as their ballots name them, in capitals, 3,077 distinct names on 2026-11-19, grouped by the ethnicity each file states (`config_diff.py --group chinese`), the population issues #1467, #1468, #1164, #1183 and #1179 were read from. A change that cuts one written word across two fields, or joins two written words, first reads how `local_agreement.py` compares a box (`agrees`, tools/differential/README.md): 3.1's #1296 cut `B.A.S.D.` into given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records scored a miss though read right until #1470 (measured 2026-11-19). A change to title vocabulary reads `local_agreement.py --base`'s `titled in` and `titled out` lines beside its regressions: a listed title the filer typed into the given-names box and the parse reads as the title is counted apart from the agreement figure since #1501, 9,145 `orcid-researchers` records on 2026-11-20, so a word newly read as a title moves records that agreed into `titled in` (a given name wrongly peeled, as `Hon` is in Hong Kong), not into the regressions; read the titles listed there. A change to which field a word lands in also reads `local_agreement.py psc-individuals --base ` the same way: real names with the four boxes their filers typed them into (UK companies' people with significant control), scored field by field and by nationality; and `local_agreement.py orcid-researchers --base `, ORCID holders' own two boxes (given names, family name) from every country, scored by the country they work or live in -- a population each person split for themselves, academic but worldwide, the one to read for a change a language pack makes. Its `name` is COMPOSED from those boxes, given first, so it cannot show which word a writer put first: a count of where a word falls in it is fixed by construction, and #1163's 538 records with the trailing letters in the family box against 0 with the word before them (`Lakshmi R S`, never `R S Lakshmi`) reproduced from that field. Order is measured on the free-text `credit` name (125,960 of the 2026-10-27 fetch's 1,831,533 records, which lean towards bibliographic bylines), against the boxes (decisions/O8); and `local_agreement.py patentsview-inventors --base `, US patents' inventors in the two boxes their filings give, split by a professional filer, with how many people filed under each name in each country, the one to read for how common a name's word is among a country's US-patent inventors. A change to titles or post-nominals, or to the `cs` pack, reads `local_agreement.py cz-candidates --base `, and with `--locale cs` too: Czech election candidates' four boxes (the title before the name, given names, surname, the title after it), scored by election, the only population whose titles are stated apart from the name, 36% of its 170,181 records titled (2026-10-30), nearly all academic degrees; its names are composed from the boxes (`Ing. Jan Novák, Ph.D.`), so it says nothing about how a writer spaces or punctuates them. A change to family-first order, to Vietnamese names or to their titles reads `local_agreement.py uit-vinames --base ` and `local_agreement.py vn-assembly --base `, and with `--locale vi`, `locales.VI` being that pack (#1108): 21,090 distinct names and 499 National Assembly deputies written family name first with their diacritics, whose parts no one filed but the convention derives (first word the family, last the given, the words between the middle name), so they score middle names, which ORCID's two boxes cannot, and `vn-assembly` the `GS.`/`PGS.`/`TS.`/`ThS.` titles composed from the education each deputy states. These are the only real fielded populations outside the committed fields files, and no CI run sees them either. ## Gotchas diff --git a/tests/v2/test_local_agreement.py b/tests/v2/test_local_agreement.py index 8c438b66d..4e8018cd9 100644 --- a/tests/v2/test_local_agreement.py +++ b/tests/v2/test_local_agreement.py @@ -570,15 +570,17 @@ def test_a_box_the_parse_cuts_after_its_full_stops_agrees(given: str) -> None: ("AB", "Lee", {"given+middle": ""}), # A word of the family box read into the given box's field. ("K.S", "Perera Silva", {"given+middle": "K. S Perera", "family": "Silva"}), - # A title glued before the box's letters, peeled to a field ORCID - # has no box for: since #1501 a class of its own (titled), not an - # agreement, which the cut alone would not make it. + # A title glued before the box's letters or name, peeled to a field + # ORCID has no box for: since #1501 a class of its own (titled), the + # cut rule alone never making it agree. ("Dr.A.B.", "Perera", {"given+middle": "A. B."}), ("Dr.Ahmed", "Hassan", {"given+middle": "Ahmed"}), ]) def test_a_misreading_beside_a_cut_at_a_full_stop_never_agrees( given: str, family: str, got: dict[str, str]) -> None: - assert agreement.read(_held(given, family), _ORCID_FIELDS, Parser(), _LISTED).got == got + reading = agreement.read(_held(given, family), _ORCID_FIELDS, Parser(), _LISTED) + assert reading.got == got + assert reading.titled == ("Dr." if given.startswith("Dr.") else "") # -- a listed title typed into the given-names box (#1501) --------------------- @@ -586,14 +588,19 @@ def test_a_misreading_beside_a_cut_at_a_full_stop_never_agrees( _PV_FIELDS = agreement.FIELDED[corpora.PV] -@pytest.mark.parametrize(("given", "family", "title", "got"), [ +#: The class's rows: the given-names box, the family box, the title the +#: parse reads, and the given and middle names it reads. +_TITLED_ROWS = ( ("Dr. Anna", "Berg", "Dr.", "Anna"), ("Dr/ Anna", "Berg", "Dr", "Anna"), # a slash for the full stop (#1149) - ("د. منى", "حسن", "د.", "منى"), + ("د. منى", "قاسمي", "د.", "منى"), ("Dr.Ahmed", "Hassan", "Dr.", "Ahmed"), # glued, cut at its full stop (#1477) ("Prof. Dr. Anna", "Berg", "Prof. Dr.", "Anna"), ("Dr. Anna Maria", "Berg", "Dr.", "Anna Maria"), -]) +) + + +@pytest.mark.parametrize(("given", "family", "title", "got"), _TITLED_ROWS) @pytest.mark.parametrize("fielded", [_ORCID_FIELDS, _PV_FIELDS], ids=["orcid", "patentsview"]) def test_a_listed_title_typed_into_the_given_box_is_counted_apart( given: str, family: str, title: str, got: str, fielded: object) -> None: @@ -617,10 +624,12 @@ def test_a_title_typed_into_the_forename_box_beside_an_empty_title_box_is_counte (_held("Dr", "Berg"), _ORCID_FIELDS, {"given+middle": ""}), # A title typed into the family box, read as the title after it. (_held("Anna", "Berg Dr."), _ORCID_FIELDS, {"family": "Berg"}), - # Another field disagrees too, the given box agreeing (the family - # box's nickname is no family; the set check alone refuses it). + # Another field disagrees too, the given box agreeing with the title + # and names (the family box's bracketed word read as a nickname): + # the check of the other fields alone refuses it. (_held("Dr Anna", "Berg (Lee)"), _ORCID_FIELDS, {"family": "Berg"} | { "given+middle": "Anna"}), + # A word of the family box read into the given field. (_held("Dr Anna", "Berg Silva"), _ORCID_FIELDS, {"given+middle": "Anna Berg", "family": "Silva"}), # The box holds more than the title and the names read (a nickname), @@ -649,18 +658,16 @@ def test_a_title_word_the_parse_reads_as_a_given_name_agrees() -> None: assert (reading.got, reading.titled) == ({}, "") -#: How many of the class's rows (the parametrized rows above, read as -#: ORCID records) the scorer read as misses before #1501: the guard's -#: negative control, re-taken whenever its rows or the parse move. -_TITLED_ROWS = (("Dr. Anna", "Berg"), ("Dr/ Anna", "Berg"), ("د. منى", "حسن"), - ("Dr.Ahmed", "Hassan"), ("Prof. Dr. Anna", "Berg"), ("Dr. Anna Maria", "Berg")) +#: How many of the class's rows (_TITLED_ROWS, read as ORCID records) +#: the scorer read as misses before #1501: the guard's negative control, +#: re-taken whenever its rows or the parse move. _UNTITLED_EFFECT = 6 def test_the_titled_class_is_counted_apart_from_the_agreement_figure( monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(agreement, "GROUP_FLOOR", 1) - rows = [_held(g, f) for g, f in _TITLED_ROWS] + [_held("Ann", "Lee"), + rows = [_held(g, f) for g, f, _t, _n in _TITLED_ROWS] + [_held("Ann", "Lee"), _held("Xyz. Anna", "Berg")] result = agreement.score(rows, _ORCID_FIELDS, Parser()) assert result.scored == {"NZ": 2} and result.agreed == {"NZ": 1} @@ -676,8 +683,8 @@ def test_the_titled_class_is_counted_apart_from_the_agreement_figure( monkeypatch.setattr(agreement, "titled", lambda *args: False) off = agreement.score(rows, _ORCID_FIELDS, Parser()) assert not off.titled - assert sum(bool(agreement.read(r, _ORCID_FIELDS, Parser(), _LISTED).got) - for r in rows[:6]) == _UNTITLED_EFFECT + off = agreement.score(rows[:6], _ORCID_FIELDS, Parser()) + assert sum(off.scored.values()) - sum(off.agreed.values()) == _UNTITLED_EFFECT def test_a_record_entering_or_leaving_the_titled_class_is_reported_apart() -> None: diff --git a/tools/differential/README.md b/tools/differential/README.md index b184ba0c5..af9f006a0 100644 --- a/tools/differential/README.md +++ b/tools/differential/README.md @@ -361,7 +361,7 @@ Its score reads the title before the name against `TITULPRED`, the given and mid `my-candidates` downloads the five pinned files and refuses one whose sha256 is not the pinned one (retried first, as a body cut short), then, in this order, one of another header than the file's pinned one, one whose body does not end with a line break or whose last row is short (as `opensanctions-parliaments` does), one holding another number of rows than pinned, and past their shares rows of another width (`MY_MAX_BAD`) and rows with an empty name in a column read (`MY_MAX_NAMELESS`), a row counted once however many of its columns are empty. Its data date is the pinned commit's, and a corpus read at another `MY_COMMIT` or by another `MY_READ_VERSION` is refused on load. It holds no fields, so it is a `snapshot.py --local` population, not a `local_agreement.py` one. The fetch took under a second on 2026-11-19. -`local_agreement.py` does the SCORE job for a local corpus. It parses each filed display name and compares the parser's roles with the boxes the source states (title, given, middle and family for `psc-individuals`; given and middle joined against the given-names box, then family, for `orcid-researchers` and `patentsview-inventors`; title, given and middle joined, family and suffix for `cz-candidates`; family, middle and given, the parts derived, for `uit-vinames`; and title, family, middle and given for `vn-assembly`), folding case, periods, commas and spacing. Where the source has no box after the name, a suffix the parser peels is compared inside the surname box: the display name joins the surname last, so a trailing suffix was typed into it whenever it is filled, with or without a comma (`Smith, Jr.`); the fold read the comma as a miss until 2026-10-28, which moved 83 `psc-individuals` records and 561 `orcid-researchers` records to agreeing and none away. Joining two fields to compare them with one box puts a space between them, which the fold cannot tell from one the filer typed, and a reading that cuts one written word across the two makes it false: 3.1's run of initials (#1296, rules/T7) reads the box `B.A.S.D.` as given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records (403 of them Sri Lanka's) and 35 `patentsview-inventors` records scored a miss with the box's letters in the box's field (measured 2026-11-19), until #1470 had a word agree with the reading that cuts it after one or more of its initials, and #1477 after any full stop the filer typed, whatever stands before it (`Md.Karim` read `Md.`, `Karim`: 168 `orcid-researchers` records and 1 `patentsview-inventors` record moved on 2026-11-19, 146 of them Bangladesh's). `agrees` holds the rule, guarded by `test_a_reading_cut_only_after_a_full_stop_is_never_scored_a_miss` with a recorded negative control; a run with no full stop, a full stop the reading lost, a word left over, other letters, and a cut across two boxes a source states apart (`psc-individuals`' forename and middle name) still score a miss. A parser change that cuts one written word across two fields, or joins two written words, reads `agrees` before trusting the score it moves. A listed title the filer typed into the given-names box and the parse reads as the title, the rest of the box read as the box's names (`Dr. Anna`, `Dr/ Anna`, `د. منى`, and `Dr.Ahmed`, which #1477 left a miss), every other field agreeing and no title box filed, is a class of its own (`titled`, #1501): the parse is right and the box is what differs, so it counts as neither agreeing nor missing, the agreement figure is taken over the records outside it, and the report gives its size, its records per group and the titles read there, so a reader checks the words, a given name wrongly peeled among them (`Hon`, a Cantonese given name the default reads as the style, #999), rather than the records. On 2026-11-20 it held 9,145 `orcid-researchers` records (Pakistan 835, Bangladesh 595, Iraq 572; `Dr.` 5,311, `Dr` 1,807), 90 `patentsview-inventors` records (`Hon` 39) and 6 `psc-individuals` records, every one a miss before, raising ORCID's figure from 81.1% to 81.5%. A title the vocabulary does not list (`Xyz. Anna`, read by its shape), a box holding only a title, a title typed into the family box and a title box filed stay out of it. `--base` reports a record entering or leaving the class as `titled in` or `titled out`, with the titles read, apart from the regressions and progress, so a change to the title vocabulary reads those lines for its ORCID and PatentsView moves; `config_diff.py`'s `gaps` and `score` drop a record any configuration reads into the class from every column. Where a source has a title box, and save `cz-candidates` (above), a title the parser reads otherwise, holding a word the vocabulary lists as neither a title nor a connective (a job typed as a title), is set aside as filer error rather than scored, and the report lists the commonest such titles as leads for the vocabulary. The report gives agreement overall and by the group the source states (nationality, country), misses per field, and the commonest disagreement shapes, as counts, word counts and the commonest set-aside titles; `--list N` prints moved records, names and all, for reading locally. Its record, `agreement.jsonl` beside the corpus, holds every record that did not wholly agree, so a re-run reports what moved. As with the local snapshot, check it from the branch against a base you name (`--base `, whose record is kept under `agreements/` beside the corpus, keyed by the fetch, the base's `nameparser/` files, the interpreter's minor version and the scorer, the ten most recent kept; the scorer's fingerprint reads only its own source's `FIELDED` entry, so adding a source leaves the others' records standing, which the whole table, hashed until `patentsview-inventors` was added on 2026-10-28, did not), or, alone, record the shared one from the base checkout (`--record --tree `) and run it from the branch; it refuses a record from another fetch, or one written by another version of the scorer, whose own change would otherwise read as the parser's moves. `--locale cs` scores the parser of a locale pack, `parser_for(locales.CS)`, against a record of its own (`agreement.cs.jsonl`, and kept records keyed by the locale too), so a pack's score and the default's never stand for each other; `measure.py` runs the default's alone. No CI run sees it. +`local_agreement.py` does the SCORE job for a local corpus. It parses each filed display name and compares the parser's roles with the boxes the source states (title, given, middle and family for `psc-individuals`; given and middle joined against the given-names box, then family, for `orcid-researchers` and `patentsview-inventors`; title, given and middle joined, family and suffix for `cz-candidates`; family, middle and given, the parts derived, for `uit-vinames`; and title, family, middle and given for `vn-assembly`), folding case, periods, commas and spacing. Where the source has no box after the name, a suffix the parser peels is compared inside the surname box: the display name joins the surname last, so a trailing suffix was typed into it whenever it is filled, with or without a comma (`Smith, Jr.`); the fold read the comma as a miss until 2026-10-28, which moved 83 `psc-individuals` records and 561 `orcid-researchers` records to agreeing and none away. Joining two fields to compare them with one box puts a space between them, which the fold cannot tell from one the filer typed, and a reading that cuts one written word across the two makes it false: 3.1's run of initials (#1296, rules/T7) reads the box `B.A.S.D.` as given `B.`, middle `A.S.D.`, and 1,140 `orcid-researchers` records (403 of them Sri Lanka's) and 35 `patentsview-inventors` records scored a miss with the box's letters in the box's field (measured 2026-11-19), until #1470 had a word agree with the reading that cuts it after one or more of its initials, and #1477 after any full stop the filer typed, whatever stands before it (`Md.Karim` read `Md.`, `Karim`: 168 `orcid-researchers` records and 1 `patentsview-inventors` record moved on 2026-11-19, 146 of them Bangladesh's). `agrees` holds the rule, guarded by `test_a_reading_cut_only_after_a_full_stop_is_never_scored_a_miss` with a recorded negative control; a run with no full stop, a full stop the reading lost, a word left over, other letters, and a cut across two boxes a source states apart (`psc-individuals`' forename and middle name) still score a miss. A parser change that cuts one written word across two fields, or joins two written words, reads `agrees` before trusting the score it moves. A listed title the filer typed into the given-names box and the parse reads as the title, the rest of the box read as the box's names (`Dr. Anna`, `Dr/ Anna`, `د. منى`, and `Dr.Ahmed`, which #1477 left a miss), every other field agreeing and no title box filed, is a class of its own (`titled`, #1501): the parse is right and the box is what differs, so it counts as neither agreeing nor missing, the agreement figure is taken over the records outside it, and the report gives its size, its records per group and the titles read there, so a reader checks the words, a given name wrongly peeled among them (`Hon`, a Cantonese given name the default reads as the style, #999), rather than the records. On 2026-11-20 it held 9,145 `orcid-researchers` records (the most in India, 1,190, Pakistan, 835, and Bangladesh, 595; `Dr.` 5,311, `Dr` 1,807), 90 `patentsview-inventors` records (`Hon` 39) and 6 `psc-individuals` records, every one a miss before, raising ORCID's figure from 81.1% to 81.5%. A title the vocabulary does not list (`Xyz. Anna`, read by its shape), a box holding only a title, a title typed into the family box and a title box filed stay out of it. `--base` reports a record entering or leaving the class as `titled in` or `titled out`, with the titles read, apart from the regressions and progress: a record that agreed and is now read with a title (a given name newly peeled) is `titled in`, never a regression, so a change to the title vocabulary reads those lines beside its regressions; `config_diff.py`'s `gaps` and `score` drop a record any configuration reads into the class from every column. Where a source has a title box, and save `cz-candidates` (above), a title the parser reads otherwise, holding a word the vocabulary lists as neither a title nor a connective (a job typed as a title), is set aside as filer error rather than scored, and the report lists the commonest such titles as leads for the vocabulary. The report gives agreement overall and by the group the source states (nationality, country), misses per field, the commonest disagreement shapes and the titled class, as counts, word counts, the commonest set-aside titles and the titles read in the given-names box; `--list N` prints moved records, names and all, for reading locally. Its record, `agreement.jsonl` beside the corpus, holds every record that did not wholly agree, so a re-run reports what moved. As with the local snapshot, check it from the branch against a base you name (`--base `, whose record is kept under `agreements/` beside the corpus, keyed by the fetch, the base's `nameparser/` files, the interpreter's minor version and the scorer, the ten most recent kept; the scorer's fingerprint reads only its own source's `FIELDED` entry, so adding a source leaves the others' records standing, which the whole table, hashed until `patentsview-inventors` was added on 2026-10-28, did not), or, alone, record the shared one from the base checkout (`--record --tree `) and run it from the branch; it refuses a record from another fetch, or one written by another version of the scorer, whose own change would otherwise read as the parser's moves. `--locale cs` scores the parser of a locale pack, `parser_for(locales.CS)`, against a record of its own (`agreement.cs.jsonl`, and kept records keyed by the locale too), so a pack's score and the default's never stand for each other; `measure.py` runs the default's alone. No CI run sees it. `pairs` reads a paired source (`tse-donors`, whose records carry the registry's name beside the filed one) as two spellings of one person, and sorts each pair by how the filed name departs from the reference: the first of its shapes that fits, from case, accents (case unchanged) and case and accents together, through words left out, shortened or misspelled, to few words in common. A word left out or added counts once per pair, and is listed only when ten pairs share it. `--agreement` also parses both spellings of every pair with a reference name that differs, and counts the pairs whose two readings end the family name in the same word (two readings with no family name share none). It lists the accents-only pairs read with two surnames by the two spellings' last words, the same ten-pair floor applied. diff --git a/tools/differential/config_diff.py b/tools/differential/config_diff.py index ec86a6ec1..940e708ab 100644 --- a/tools/differential/config_diff.py +++ b/tools/differential/config_diff.py @@ -90,9 +90,11 @@ decisions/vocabulary-model filtered so); PSC's are set aside by local_agreement.read with the default's title words, the same records in every column, and a record either column reads with a listed title -typed into the given-names box (local_agreement.titled, #1501; in PSC a -title in the forename box with the title box empty) is dropped from -both. Each group is its first --cap records in raw.jsonl's +typed into the given-names box (local_agreement.titled, #1501) is +dropped from both: in PSC a title in the forename box with the title +box empty, and in ORCID and PatentsView the few the title-word filter +above does not drop (`Dr/ Anna`, a title the default does not list). +Each group is its first --cap records in raw.jsonl's order. **score**: configurations scored against the filed boxes, a row a group. @@ -1062,9 +1064,10 @@ def score_rows(rows: Sequence[dict[str, str]], fielded: local_agreement.Fielded, readings: Sequence[tuple[Reading, ...]], listed: frozenset[str] ) -> tuple[int, list[SpecScore]]: """`rows` scored under each configuration's reading: the records - scored (local_agreement.read's set-aside, judged under the first - configuration, and its title typed into the given-names box, under - any, each dropped from every column) and each one's score.""" + scored, less those local_agreement.read sets aside under the first + configuration and those any configuration reads into the titled + class (local_agreement.titled), each dropped from every column, and + each configuration's score.""" n_specs = len(readings[0]) if readings else 0 out = [SpecScore() for _ in range(n_specs)] scored = 0 diff --git a/tools/differential/local_agreement.py b/tools/differential/local_agreement.py index 6983983b6..fe91e9bae 100644 --- a/tools/differential/local_agreement.py +++ b/tools/differential/local_agreement.py @@ -43,7 +43,9 @@ field's word count as filed and as parsed (`middle 0->1, family 2->1` is a two-word surname whose first word was read as a middle name), and the set-aside title boxes at least TITLE_FLOOR records share (a word that -many filers typed is no one person's name, though it may be a name). +many filers typed is no one person's name, though it may be a name), +and the class of a title typed into the given-names box (titled): its +size, its records per group and the titles read there. `--list N` prints up to N moved records of each kind, names and all, for reading at one's own terminal. @@ -439,8 +441,9 @@ def report(result: Score, fielded: Fielded, top: int) -> list[str]: f" {fielded.group:<24} {'records':>10} {'agree':>7} " + " ".join(f"{r:>8}" for r in roles) + (f" {'titled':>8}" if result.titled else "")] - # By the records a group holds, the class among them, so the class - # does not reorder groups of one size (a country at ORCID's cap). + # By the records a group holds, the class among them, so a group's + # place does not fall with its class (every country at ORCID's cap + # holds as many); groups of one size keep the order they were met. sizes = result.scored + result.titled_groups for group, _size in sizes.most_common(): if (n := result.scored[group]) < floor: @@ -621,13 +624,15 @@ def _record_command(source: str) -> str: def moves(old: dict[str, dict[str, Any]], new: dict[str, dict[str, Any]], ) -> dict[str, list[str]]: - """Each record whose reading moved, by kind: `regression` (it agreed - and now does not), `progress` (it disagreed and now agrees), - `changed` (it disagrees, or is set aside, differently), and apart - from those `titled in` and `titled out`, a record entering or - leaving the class of a title typed into the given-names box - (titled), which is neither agreeing nor missing. Both sides read the - same fetch, so no record is gained or lost.""" + """Each record whose reading moved, by kind: `titled in` and + `titled out`, a record entering or leaving the class of a title + typed into the given-names box (titled), which is neither agreeing + nor missing, whichever side it came from or went to (a record that + agreed and is now titled is `titled in`, never a regression); then, + outside the class, `regression` (it agreed and now disagrees), + `progress` (it disagreed and now agrees) and `changed` (it + disagrees, is set aside, or is titled, differently). Both sides read + the same fetch, so no record is gained or lost.""" found: dict[str, list[str]] = {"regression": [], "progress": [], "changed": [], "titled in": [], "titled out": []} for k in sorted(set(old) | set(new)): From d203de7b3fd67f214f981dfbe77c4c4fd2b5c397 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Fri, 20 Nov 2026 14:50:23 -0800 Subject: [PATCH 4/4] Say which records the title-word filter lets through to the titled class (#1501) Co-Authored-By: Claude Opus 5.5 --- tools/differential/config_diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/differential/config_diff.py b/tools/differential/config_diff.py index 940e708ab..b8c6ad4e5 100644 --- a/tools/differential/config_diff.py +++ b/tools/differential/config_diff.py @@ -93,7 +93,7 @@ typed into the given-names box (local_agreement.titled, #1501) is dropped from both: in PSC a title in the forename box with the title box empty, and in ORCID and PatentsView the few the title-word filter -above does not drop (`Dr/ Anna`, a title the default does not list). +above does not drop (`Dr/ Anna`, whose `Dr/` its split does not match). Each group is its first --cap records in raw.jsonl's order.