Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md

Large diffs are not rendered by default.

60 changes: 56 additions & 4 deletions docs/design/decisions/group-suggestion.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/release_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Release Log
- **Add the order report, on a name of one word followed by initials.** ``parse("Kavitha S").ambiguities`` holds an ``order`` ambiguity, which names no ``alternative`` (the other reading lays out the whole name: ``name_order=FAMILY_FIRST`` reads it), where 2.0.0 through 3.0.1 report nothing; the reading itself does not change. Capitals written as one word with no full stops (``Armitage JO``) are not reported, being written as a short surname is (``Zhi LI``). :issue:`1137`, :issue:`1254`
- **Add Policy.capitals_as_family, to read the words a name writes in capitals as its family name.** ``Parser(policy=Policy(capitals_as_family=True)).parse("DUPONT Marie")`` gives given ``Marie``, family ``DUPONT``, where 1.4.0 through 3.0.1, and the default still, give given ``DUPONT``, family ``Marie``. ``Parser.suggest()`` suggests it for a list whose names write the family in capitals of four letters or more. In lists that do not follow the convention capitals also write a given name or a credential, so it is off by default, and it cannot be set with ``unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE``. See :ref:`capitals-as-family` and :ref:`Settings for a list of names <suggest-capitals>`. :issue:`659`
- **Add Policy.initials_as_family, to read the letters ending a name as its family name.** ``Parser(policy=Policy(initials_as_family=True)).parse("Lakshmi R S")`` gives given ``Lakshmi``, family ``R S``, where 1.4.0 through 3.0.1, and the default still, give middle ``R``, family ``S``. ``locales.NE`` turns it on, and ``Parser.suggest()`` suggests it for a list whose names repeat one run of letters (Nepal's ``B K``). The same string is a middle and a family initial in many lists and a byline written surname first in a bibliography, so it is off by default. :issue:`1163`, :issue:`1254`
- **Add Parser.suggest(), to read the settings a list of names is written in.** ``Parser().suggest(["Taylor Morgan", "Kim Minjun", "Wang Xiaoming", "Nguyen Anh", "Garcia Emily"]).parser.parse("Taylor Morgan")`` gives given ``Morgan``, family ``Taylor``, where ``Parser().parse("Taylor Morgan")`` gives given ``Taylor``, family ``Morgan``, the list carrying the evidence for a family-first ``name_order``; a group of East Slavic or Turkic patronymics gets the patronymic rule too. A list of names with no common surname, nor a common given name that is rarely a surname, carries no evidence and keeps the base, and moving the base takes from 5 names (Chinese, Korean, Czech) to 50 (Indian, Russian). A later release may suggest other settings for the same list, so keep the ones you applied with your data. See :ref:`suggest-settings`. :issue:`1308`, :issue:`1355`, :issue:`1356`, :issue:`1357`, :issue:`1397`, :issue:`1403`
- **Add Parser.suggest(), to read the settings a list of names is written in.** ``Parser().suggest(["Taylor Morgan", "Kim Minjun", "Wang Xiaoming", "Nguyen Anh", "Garcia Emily"]).parser.parse("Taylor Morgan")`` gives given ``Morgan``, family ``Taylor``, where ``Parser().parse("Taylor Morgan")`` gives given ``Taylor``, family ``Morgan``, the list carrying the evidence for a family-first ``name_order``; a group of East Slavic or Turkic patronymics gets the patronymic rule too. A list of names with no common surname, nor a common given name that is rarely a surname, carries no evidence and keeps the base, and moving the base takes from 5 names (Chinese, Korean, Czech) to 50 (Indian, Russian). A later release may suggest other settings for the same list, so keep the ones you applied with your data. See :ref:`suggest-settings`. :issue:`1308`, :issue:`1355`, :issue:`1356`, :issue:`1357`, :issue:`1397`, :issue:`1403`, :issue:`1442`
- **Fix the commas of Ethiopic, Burmese, N'Ko, Mongolian, Manchu, Lisu, Vai and Bamum, and the Ethiopic wordspace, which did not divide a name.** ``parse("ከበደ፣ አበበ")`` gives family ``ከበደ``, given ``አበበ``, where 1.4.0 through 3.0.1 gave given ``ከበደ፣``, family ``አበበ``; the other scripts' commas read the same way, every non-ASCII comma also divides the words of a bracketed credential as the ASCII one does, and ``አበበ፡ከበደ፡ተሰማ`` divides into three words at the wordspace ``፡``. :issue:`1202`
- **Fix a Mongolian case suffix joined by a narrow no-break space, which read as a word of its own.** ``Parser(policy=Policy(name_order=FAMILY_FIRST)).parse("ᠬᠣᠷᠯᠤ᠎ᠠ ᠶ᠋ᠢᠨ ᠴᠣᠢᠢᠪᠠᠯᠰᠠᠩ")`` gives family ``ᠬᠣᠷᠯᠤ᠎ᠠ ᠶ᠋ᠢᠨ``, given ``ᠴᠣᠢᠢᠪᠠᠯᠰᠠᠩ``, where 2.0.0 through 3.0.1 split at the U+202F and gave given ``ᠶ᠋ᠢᠨ``. 1.4.0, which has no name order, split there too, reading middle ``ᠶ᠋ᠢᠨ``. Elsewhere U+202F still divides like a space. :issue:`1236`
- **Fix the unbalanced-delimiter report on Dutch 't and 's, and read 's as part of the surname.** ``parse("Pieter 't Hart")`` and ``parse("Arent van 's-Gravesande")`` report nothing, where 2.0.0 through 3.0.1 reported ``unbalanced-delimiter``; ``Willem Jacob 's Gravesande`` gives family ``'s Gravesande``, where 1.4.0 through 3.0.1 gave middle ``Jacob 's``; and ``Jan van 't Hof 'Jantje'`` gives nickname ``Jantje`` as 1.4.0 did, where 2.0.0 through 3.0.1 gave ``t Hof 'Jantje``. :issue:`1241`
Expand Down
47 changes: 34 additions & 13 deletions docs/suggest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ the base parser's value.
How many names to give it
-------------------------

Give it names from one source, written one way, and a few hundred of
them at most:
Give it names from one source, written one way. A few hundred is
enough:

- **Under five names** often gets no suggestion. That is safe: a list
short of evidence keeps the parser it was given.
- **Fifty names** settles most kinds of list.
- **A few hundred** settles nearly every kind measured. More rarely
helps, and can hurt.
helps.

For a large dataset, take a sample from each source instead of passing
everything:
Expand All @@ -69,10 +69,19 @@ everything:
PolicyPatch(name_order=FAMILY_FIRST)

A sample is quicker, a suggestion costing about what parsing the same
names does, but that is not the main reason. A very long list can be
read less well than a sample of it, because the order is decided among
the names that vote, and in a list where few names vote a handful of
stray votes weigh more the longer the list is.
names does. The order's own votes are not read worse in a long list:
they must be at least 1% of the names (:ref:`suggest-deciding`), so a
few stray order votes in a list where few names vote decide nothing,
and every kind of list measured that was written in its base's own
order kept it as well at 2,000 names as at a few hundred.

The other settings have no such floor. In a long list where almost no
name carries their evidence, a handful of names can still decide
``patronymic_rules``, ``initials_as_family`` or ``capitals_as_family``:
five names written given name, patronymic, family name among a
thousand written family first without one decide the East Slavic rule,
and with it a given-first order for all of them. A sample of a few
hundred names makes that rarer.

The one kind of list measured that more names kept helping is bylines
written initials first (``AM Hoy``) under a family-first base, where
Expand Down Expand Up @@ -196,7 +205,8 @@ and enough of them agree:
- Section
* - ``name_order``
- 2 voting for one end
- more than two thirds of the names that cast an order vote
- more than two thirds of the names that cast an order vote, and
at least 1% of the list's names
- this one
* - ``patronymic_rules``
- 5 carrying one rule's patronymic
Expand All @@ -217,6 +227,16 @@ vote: a tie, or two names against one, decides nothing. A name with no
evidence on the order, and a name whose evidence is contested, casts no
order vote and is outside that share.

The names voting for one end must also be at least 1% of the list's
names, voting or not, save the names a comma leaves out, which state
their own order. A list of 200 names or fewer needs no more than the
two names it needs anyway; in a longer list where few names vote, it
keeps a handful of stray votes (a surname that is also a given name,
written first) from deciding the order for every name. Where this alone
holds the order back, the order evidence's note says so, and it says
so too where the votes it holds back are against the given-first order
a decided East Slavic rule sets.

Two is the floor, not what a typical list needs. Two names decide a
list only where no other name votes against them, and how many names a
list needs before enough of them vote depends on what its names carry:
Expand Down Expand Up @@ -635,8 +655,9 @@ The figures below were measured on groups drawn from real names
written in a known order. They give a general idea of what to expect
and how it varies, and will differ for every dataset.

- **A list written in the base's own order** keeps it in at least 97%
of groups from 2 to 200 names, save the two kinds of list below.
- **A list written in the base's own order** keeps it in at least 95%
of groups from 2 to 2,000 names, and 97% for nearly every kind, save
the two kinds of list below.
- **A list written the other way round** takes more names to move the
base, from 5 for Chinese, Taiwanese, Korean, Czech, Polish and
Italian names to 50 for Russian and Indian ones. A group whose votes
Expand All @@ -652,10 +673,10 @@ Two kinds of list keep their order less often:
- **Two or three capitals at one end** cast no capitals vote
(:ref:`suggest-evidence`), so a list of such names carries little
evidence either way. Researchers' bylines written initials first kept a
given-first base in at least 97% of groups, but a list of nothing
given-first base in at least 95% of groups, but a list of nothing
but two or three joined initials (``AM Hoy``) kept it in just under
95% of groups of 50. Where you know how such a list is written, set
``name_order`` yourself.
95% of groups of 50 and 93% of groups of 100. Where you know how such
a list is written, set ``name_order`` yourself.

``capitals_as_family`` was suggested in at least 95% of groups from 4
names for researchers who typed their family name in capitals, and
Expand Down
29 changes: 17 additions & 12 deletions nameparser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,11 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
``name_order`` is
decided in either direction, keeping this parser's family-first
spelling where it has one, where at least two names vote for
one end and they are more than two thirds of the names casting
an order vote. A patronymic rule is decided where more than four
one end, they are more than two thirds of the names casting
an order vote, and they are at least 1% of the group's names a
comma does not leave out: in a long list where few names vote, a
few stray votes decide nothing, and the order evidence's note
says so. A patronymic rule is decided where more than four
in five of the names that cast a vote carry its patronymic (and
at least five do), for the East Slavic and the Turkic rule alike;
a name whose only vote was a set-aside trailing initial counts
Expand Down Expand Up @@ -385,22 +388,24 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
bare str, bytes, a mapping or a non-str item raises TypeError.

Measured 2026-11-10, re-taken 2026-11-11, 2026-11-12,
2026-11-14 and 2026-11-15, with tools/differential/suggest_measure.py
on groups drawn from real names written in a known order, 300
groups a size (decisions/group-suggestion's 2026-11-15 #1357
entry holds the table): a group written in this parser's own
order kept
it in at least 97% of groups at every size from 2 to 200 names,
under either base order, save two lists. ORCID holders who
2026-11-14, 2026-11-15 and 2026-11-16, with
tools/differential/suggest_measure.py on groups drawn from real
names written in a known order, 300 groups a size
(decisions/group-suggestion's 2026-11-16 ORDER FLOOR entry holds
the table): a group written in this parser's own order kept it
in at least 97% of groups at every size from 2 to 2,000 names,
under either base order, save three lists. ORCID holders who
typed their given name in capitals (``ANNA Smith``), which the
capitals signal reads as a family name, kept their given-first
order in 52% of groups of two and 4% of five (why, in that
file's 2026-11-12 CAPITALS entry). A list of
nothing but bylines written two or three joined initials first
(``AM Hoy``) kept it in at least 97% of groups at every size
but 50 names, where it kept it in 95% (94.7), the name tables
voting on a few of its names; ORCID's bylines of every writing
kept it in at least 97%.
measured, to 500 names (it holds 644), but 50 and 100 names,
where it kept it in 94.7% and 93.3%, the name tables voting on
a few of its names; ORCID's bylines of
every writing kept it in 95.3% and 96.7% at 100 and 200 names
and at least 97% at every other size.
Moving the base takes more names, and
how many depends on what the names carry: groups of Chinese,
Taiwanese, Korean, Czech, Polish or Italian names (the romanized
Expand Down
67 changes: 58 additions & 9 deletions nameparser/_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ def name_votes(text: str, lexicon: Lexicon
#: STRICTLY MORE THAN to decide the order: more than two thirds, so a
#: tie, or two names against one, decides nothing.
_MIN_SHARE = 2 / 3
#: The share of ALL the group's names, voting or not, save those a
#: comma left out (which state their own order, and which the order
#: decided reads none of), that the names voting for one end must be at
#: least to decide the order: in a long list where few names vote, two
#: stray votes are more than two thirds of the voters and would decide
#: it. At 200 names or fewer it asks no more than _MIN_VOTES does
#: (decisions/group-suggestion, 2026-11-16 ORDER FLOOR, #1442).
_MIN_ORDER_GROUP_SHARE = 0.01
#: The share of the names casting any vote that one patronymic rule
#: (East Slavic or Turkic) must hold strictly more than to decide it,
#: higher than _MIN_SHARE because a decided East Slavic rule brought a
Expand Down Expand Up @@ -1004,20 +1012,25 @@ class _Tally:
pass. A plain class rather than a dataclass: it is never pickled or
returned."""

__slots__ = ("names", "contested", "by_name", "by_signal")
__slots__ = ("names", "left_out", "contested", "by_name", "by_signal")

def __init__(self) -> None:
self.names = 0
#: names a comma left out (`_comma_note`), which cast no vote
self.left_out = 0
self.contested = 0
#: names per value voted for
self.by_name: Counter[Vote] = Counter()
#: signal votes per (signal, value)
self.by_signal: Counter[tuple[Signal, Vote]] = Counter()

def add(self, pairs: list[tuple[Signal, Vote]]) -> None:
def add(self, pairs: list[tuple[Signal, Vote]], left_out: bool = False
) -> None:
"""One name's votes on this setting: its signals' votes, and
one name vote where they agree."""
one name vote where they agree. ``left_out`` is a name a comma
left out."""
self.names += 1
self.left_out += left_out
for pair in pairs:
self.by_signal[pair] += 1
values = {vote for _, vote in pairs}
Expand All @@ -1027,10 +1040,24 @@ def add(self, pairs: list[tuple[Signal, Vote]]) -> None:
self.contested += 1

def winner(self) -> Vote | None:
"""The value whose names are at least _MIN_VOTES and strictly
more than _MIN_SHARE of the names that cast a vote, if one
is."""
return self.top(_MIN_VOTES, _MIN_SHARE, sum(self.by_name.values()))
"""The value whose names are at least _MIN_VOTES, strictly
more than _MIN_SHARE of the names that cast a vote and at least
_MIN_ORDER_GROUP_SHARE of the group's names a comma did not
leave out, if one is."""
end = self.top(_MIN_VOTES, _MIN_SHARE, sum(self.by_name.values()))
return None if end is None or self._short_of_group(end) else end

def held_back(self) -> Vote | None:
"""The value the votes would decide but for
_MIN_ORDER_GROUP_SHARE, if one is."""
end = self.top(_MIN_VOTES, _MIN_SHARE, sum(self.by_name.values()))
return end if end is not None and self._short_of_group(end) else None

def _short_of_group(self, end: Vote) -> bool:
# a name a comma left out states its own order, and the order
# decided reads none of them, so it is no name of the floor's
return (self.by_name[end]
< _MIN_ORDER_GROUP_SHARE * (self.names - self.left_out))

def top(self, min_votes: int, min_share: float, total: int
) -> Vote | None:
Expand Down Expand Up @@ -1183,6 +1210,26 @@ def _comma_note(left_out: int) -> str:
f"so only a comma followed by post-nominals alone is read past")


def _floor_note(tally: _Tally, rule_decides: bool) -> str:
"""The note on votes _MIN_ORDER_GROUP_SHARE held back: where they
alone leave the order undecided, and where a decided East Slavic
rule sets the given-first order they voted against. None where the
rule sets the order they voted for, which they did not decide."""
end = tally.held_back()
if end is None or (rule_decides and end == GIVEN_FIRST):
return ""
counted = tally.names - tally.left_out
whose = (f"of the group's {counted} names" if not tally.left_out else
f"of the {counted} names no comma left out")
floor = (f"an order is decided where the names voting for one end are "
f"at least {_MIN_ORDER_GROUP_SHARE:.0%} of those names")
if rule_decides:
return (f"{tally.by_name[end]} {whose} vote {_label(end)}, too few "
f"to decide that order against the rule: {floor}")
return (f"{tally.by_name[end]} {whose} vote {_label(end)}, too few to "
f"decide the order: {floor}")


def _decide_order(tally: _Tally, base_order: tuple[Role, Role, Role],
rule_needs_given_first: bool, comma_left_out: int,
trailing_note: str = ""
Expand All @@ -1196,8 +1243,10 @@ def _decide_order(tally: _Tally, base_order: tuple[Role, Role, Role],
rule that keeps a ``FAMILY_FIRST`` base's order
(`_keeps_family_first`) is not passed here: the order is then the
votes' or the base's."""
notes = [_comma_note(comma_left_out), trailing_note]
end = tally.winner()
notes = [_comma_note(comma_left_out),
_floor_note(tally, rule_needs_given_first and end is None),
trailing_note]
if rule_needs_given_first and end != FAMILY_FIRST:
end = GIVEN_FIRST
notes.insert(0, "the East Slavic rule reorders each name; it needs "
Expand Down Expand Up @@ -1539,7 +1588,7 @@ def capitals_reader() -> Parser:
for signal, vote in votes.items():
per_setting[_setting_of(signal)].append((signal, vote))
for setting, tally in tallies.items():
tally.add(per_setting[setting])
tally.add(per_setting[setting], comma)
policy = parser.policy
# a FAMILY_FIRST base keeps its order where the group's East Slavic
# patronymics are mostly written last (#1356)
Expand Down
Loading
Loading