Skip to content

Commit 7414f46

Browse files
derek73claude
andcommitted
Sweep the suggester's API docs for #1533: plain signals, rounded figures
From part A's report (#1534): - Parser.suggest's docstring gives the rounded figures docs/suggest.rst shows, with no dates; the dated tables stay in decisions/group-suggestion, which it names. - Signal's members say what each signal is and what it votes on, in a reader's words, without issue numbers or private table names. - NameEvidence's docstring says what a vote holds: the order voted for, the PatronymicRule, or True or False, as docs/suggest.rst does. And from the review of 093a07e: the two newly guarded article sites (attached on a reading, a phrase matching as a kind) each get a test over every kind that reaches them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 093a07e commit 7414f46

3 files changed

Lines changed: 74 additions & 64 deletions

File tree

‎nameparser/_parser.py‎

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -410,48 +410,29 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
410410
an empty group, or one with no votes, suggests no change. A
411411
bare str, bytes, a mapping or a non-str item raises TypeError.
412412
413-
Measured 2026-11-10, re-taken 2026-11-11, 2026-11-12,
414-
2026-11-14, 2026-11-15, 2026-11-16 and 2026-11-19, with
415-
tools/differential/suggest_measure.py on groups drawn from real
416-
names written in a known order, 300 groups a size
417-
(decisions/group-suggestion's 2026-11-19 #1364 and #1447
418-
entries hold the sizes): a group written in this parser's own order kept it
419-
in at least 97% of groups at every size from 2 to 2,000 names,
420-
under either base order, save three lists. ORCID holders who
421-
typed their given name in capitals (``ANNA Smith``), which the
422-
capitals signal reads as a family name, kept their given-first
423-
order in 52% of groups of two and 4% of five (why, in that
424-
file's 2026-11-12 CAPITALS entry). A list of
425-
nothing but bylines written two or three joined initials first
426-
(``AM Hoy``) kept it in at least 97% of groups at every size
427-
measured, to 500 names (it holds 644), but 50 and 100 names,
428-
where it kept it in 94.7% and 93.3%, the name tables voting on
429-
a few of its names. And a list of nothing but given names that
430-
ORCID's holders type as surnames (``Cooper``, ``Burke``) fell
431-
below 95% at every size and was read wrong in every group from
432-
5 names, the surname table voting on each of them (that file's
433-
2026-11-19 #1364 entry).
434-
Moving the base takes more names, and
435-
how many depends on what the names carry: groups of Chinese,
436-
Taiwanese, Korean, Czech, Polish or Italian names (the romanized
437-
surnames and the common given names) and of Russian ones (where
438-
their patronymics stand) were read right in 95% of groups from 5
439-
names; German, Dutch, Spanish, British, French,
440-
Romanian, Vietnamese and Japanese from 10; US, Turkish,
441-
Nigerian and Brazilian from 20; Indian from 50; and PSC's
442-
Bangladeshi filers from 200 (PatentsView's Philippine inventors
443-
from 20, through the Russian names among them). A group whose votes fall short of
444-
the thresholds keeps the base rather than guess, so a smaller
445-
group moves it in fewer of the draws. ``capitals_as_family``, measured 2026-11-12
446-
(decisions/group-suggestion's CAPITALS entry): ORCID holders who
447-
typed their family name in capitals were suggested it in at least
448-
95% of groups from 4 names, and from 10 where many of the
449-
surnames are two or three letters (holders in China, Korea,
450-
Vietnam and Taiwan). Of the lists measured that do not write their
451-
family names so, only ORCID holders who typed their given name in
452-
capitals (``ANNA Smith``) were suggested it, which nothing in a
453-
name tells apart; no other list was, ORCID's bylines (``AM Hoy``)
454-
included. A name wholly in one case carries no evidence.
413+
Measured on groups drawn from real names written in a known
414+
order (docs/suggest.rst's limits; the dated tables are in the
415+
source repository's docs/design/decisions/group-suggestion.md),
416+
these figures give a general idea and will differ for every
417+
dataset. A group written in this parser's own order kept it in
418+
at least 95% of groups from 2 to 2,000 names, and in 97% for
419+
nearly every kind, save three kinds of list: given names in
420+
capitals (``ANNA Smith``), whose capitals read as a family name;
421+
nothing but two or three joined initials (``AM Hoy``), which
422+
kept it in just under 95% of groups of 50 and 93% of 100; and
423+
nothing but given names that are common surnames elsewhere
424+
(``Cooper``, ``Burke``), read the wrong way round. A group
425+
written the other way round takes more names to move the base:
426+
from 5 for Chinese, Taiwanese, Korean, Czech, Polish, Italian
427+
and Russian names to 50 for Indian ones and 200 for Bangladeshi
428+
ones. A group whose votes fall short of the thresholds keeps the
429+
base rather than guess. ``capitals_as_family`` was suggested in
430+
at least 95% of groups from 4 names for holders who typed their
431+
family name in capitals, and from 10 where many of the surnames
432+
are two or three letters (China, Korea, Vietnam and Taiwan); of
433+
the lists that do not write their family names so, only the one
434+
writing its given names in capitals was suggested it. A name
435+
wholly in one case carries no evidence.
455436
"""
456437
from nameparser._suggest import suggest
457438
return suggest(self, names)

‎nameparser/_suggest.py‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,36 +135,35 @@ class Signal(StrEnum):
135135
patronymic rule or ``two_family_names``."""
136136

137137
#: A family name written in capitals at one end of a name in mixed
138-
#: case (``Mary SMITH``).
138+
#: case (``Mary SMITH``); votes on the order.
139139
CAPITALS = "capitals"
140-
#: A trailing initial (``Smith J.``), counted only where enough of
141-
#: the group's names end in initials.
140+
#: Initials ending the name (``Smith J.``), counted only where enough
141+
#: of the group's names end in them, as a bibliography's do; votes on
142+
#: the order.
142143
TRAILING_INITIAL = "trailing-initial"
143-
#: A lowercase particle first or before the last word.
144+
#: A lowercase particle first or before the last word; votes on the
145+
#: order.
144146
PARTICLE = "particle"
145147
#: A common surname as the first or last word: a romanized Chinese,
146-
#: Korean or Vietnamese one, or one ORCID's holders rarely type as a
147-
#: given name (``García``, #1364).
148+
#: Korean or Vietnamese one, or one researchers rarely write as a
149+
#: given name (``García``, ``Quispe``); votes on the order.
148150
SURNAME = "surname"
149151
#: A common given name that is rarely a surname (``Emily``, not
150-
#: ``Taylor``) as the first or last word.
152+
#: ``Taylor``) as the first or last word; votes on the order.
151153
GIVEN_NAME = "given-name"
152-
#: A patronymic one rule reads (Russian ``Petrovich``, Azerbaijani
153-
#: ``Huseyn oglu``), the evidence on ``patronymic_rules``.
154+
#: A patronymic a rule reads (Russian ``Petrovich``, Azerbaijani
155+
#: ``Huseyn oglu``); votes on ``patronymic_rules``.
154156
PATRONYMIC = "patronymic"
155-
#: Where an East Slavic patronymic of three name words stands, read
156-
#: where rules/O1 reads it, the evidence on ``name_order``: in the
157-
#: middle (``Ivan Petrovich Sidorov``) the family is written last,
158-
#: the middle word winning where the last ends as a patronymic too;
159-
#: last (``Sidorov Ivan Petrovich``) it is written first. Cast only
160-
#: beside an East Slavic ``PATRONYMIC`` vote.
157+
#: Where a Russian-style patronymic stands in a name of three words:
158+
#: last (``Sidorov Ivan Petrovich``), the family name is written
159+
#: first; in the middle (``Ivan Petrovich Sidorov``), last. Cast only
160+
#: beside a Russian-style ``PATRONYMIC`` vote; votes on the order.
161161
PATRONYMIC_POSITION = "patronymic-position"
162-
#: The word ``two_family_names`` would take into a name's family
163-
#: (rules/O6), voting the switch's value: True where it is a common
164-
#: surname of the ORCID table (``COMMON_SURNAMES``, #1364), ``García``
165-
#: in ``Gabriel García Márquez``, a first surname standing where a
166-
#: second given name would; False where it is a father's name the
167-
#: switch would read as a first surname (``Ivan Petrovich
162+
#: The word ``two_family_names`` would take into a name's family,
163+
#: voting the switch's value: True where it is a common surname
164+
#: (``García`` in ``Gabriel García Márquez``, a first surname where
165+
#: a second given name would stand), False where it is a father's
166+
#: name the switch would read as a first surname (``Ivan Petrovich
168167
#: Sidorov``). A listed given name there casts no vote.
169168
FIRST_SURNAME = "first-surname"
170169

@@ -732,7 +731,10 @@ class NameEvidence:
732731
Order votes are one per NAME: the end the name's order signals
733732
agree on. A name whose order signals point at both ends is
734733
contested, casts no order vote and never disagrees on order.
735-
``votes`` keeps every signal's vote all the same, save a
734+
``votes`` holds the votes keyed by signal: an order vote is the
735+
order it votes for (``GIVEN_FIRST`` or ``FAMILY_FIRST``), a
736+
patronymic vote the ``PatronymicRule``, and a first-surname vote
737+
``True`` or ``False``. It keeps every signal's vote all the same, save a
736738
trailing-initial vote the group did not cast: too few of its names
737739
ending in initials (``Parser.suggest``), or its runs of letters
738740
decided ``initials_as_family``, whose letters are its family.

‎tests/v2/test_lexicon.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,3 +2274,30 @@ def test_a_refused_property_names_the_kind_with_its_article(
22742274
with pytest.raises(ValueError,
22752275
match=f"^{article} {kind} reading takes "):
22762276
Lexicon.empty().add("zzq", kind=kind, zzprop=True) # type: ignore[call-arg]
2277+
2278+
2279+
def _attached_and_phrase_rows() -> tuple[list[tuple[str, str]],
2280+
list[tuple[str, str]]]:
2281+
from nameparser._reading_index import CATEGORY
2282+
rows = _article_rows()
2283+
attached = [(k, a) for k, a in rows
2284+
if CATEGORY[k] in ("title", "suffix")]
2285+
phrase = [(k, a) for k, a in rows if k != "birth_marker"
2286+
and CATEGORY[k] not in ("familiar", "spelling")]
2287+
assert attached and phrase
2288+
return attached, phrase
2289+
2290+
2291+
@pytest.mark.parametrize("kind, article", _attached_and_phrase_rows()[0])
2292+
def test_an_attached_side_names_the_kind_with_its_article(
2293+
kind: str, article: str) -> None:
2294+
with pytest.raises(ValueError,
2295+
match=f"^attached on {article} '{kind}' reading"):
2296+
Lexicon.empty().add("zzq", kind=kind, attached="sideways")
2297+
2298+
2299+
@pytest.mark.parametrize("kind, article", _attached_and_phrase_rows()[1])
2300+
def test_a_phrase_names_the_kind_with_its_article(
2301+
kind: str, article: str) -> None:
2302+
with pytest.raises(ValueError, match=f"match as {article} {kind}:"):
2303+
Lexicon.empty().add("zzq yyq", kind=kind)

0 commit comments

Comments
 (0)