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
4 changes: 2 additions & 2 deletions AGENTS.md

Large diffs are not rendered by default.

40 changes: 30 additions & 10 deletions docs/design/decisions/group-suggestion.md

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ it, and ``suggestion.base`` is the parser you started from:
>>> print(suggestion)
Suggested for 5 names (base: Parser(Lexicon(default), Policy())):
name_order FAMILY_FIRST 4 for, 0 against, 1 no evidence
surname FAMILY_FIRST 3
surname FAMILY_FIRST 4
given-name FAMILY_FIRST 2
patronymic_rules unchanged (none) no evidence
initials_as_family unchanged (False) no evidence
Expand All @@ -125,10 +125,10 @@ parser has: all five names are in mixed case with no word in capitals,
so they are evidence for leaving ``capitals_as_family`` off.

Four names vote for family first: ``Kim``, ``Wang`` and ``Nguyen`` by
the romanized surname in front, ``Garcia Emily`` by the common given
name at the end (``Garcia`` is not one of the surnames ``suggest``
reads). ``Wang Xiaoming`` carries both kinds, so the surname and
given-name rows count it once each.
the common surname in front, ``Garcia Emily`` by the surname in front
and the common given name at the end. ``Wang Xiaoming`` and ``Garcia
Emily`` carry both kinds, so the surname and given-name rows count each
of them once.

``Taylor Morgan`` gives no evidence, so the suggested parser reads it
family first only because the rest of the list is written that way;
Expand All @@ -140,9 +140,10 @@ disagrees <suggest-disagreeing>`).
What ``suggest`` decides
~~~~~~~~~~~~~~~~~~~~~~~~

The evidence is in the names themselves: a common romanized Chinese,
Korean or Vietnamese surname, or a common given name that is rarely
a surname (``Mary``, not ``James``), at one end; a
The evidence is in the names themselves: a common surname (a
romanized Chinese, Korean or Vietnamese one, or one rarely written as
a given name, ``Garcia``), or a common given name that is rarely a
surname (``Mary``, not ``James``), at one end; a
family name written in capitals; a lowercase particle; initials after
the name, as a bibliography writes them (:ref:`suggest-evidence`).

Expand Down
1 change: 1 addition & 0 deletions docs/release_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release Log

nameparser 3.2 is under development.

- **Change Parser.suggest() to read common surnames beyond the Chinese, Korean and Vietnamese ones, most of them Spanish.** ``Parser().suggest(["García Zorvan", "Quispe Qelliot"]).patch`` gives ``PolicyPatch(name_order=FAMILY_FIRST)``, where 3.1.0 found no evidence in either name and suggested nothing; a list of two to five Spanish names written family first now moves a given-first parser more often. :issue:`1364`
- **Fix Malaysian a/l, a/p and anak, which read as middle names and cut the father's name.** ``parse("KUMAR A/L RAJAN NAIDU")`` gives family ``A/L RAJAN NAIDU`` and the same ``patronymic``, as ``bin`` reads, where 1.4.0 through 3.1.0 gave middle ``A/L RAJAN``, family ``NAIDU``; ``anak`` opening a name written without a comma (Balinese ``Anak Agung``) is left to position, the given name by default, and reported. :issue:`1468`
- **Fix Dutch Oude, which read as a middle name.** ``parse("Piet Oude Luttikhuis")`` gives family ``Oude Luttikhuis``, where 1.4.0 through 3.1.0 gave middle ``Oude``, family ``Luttikhuis``; ``Oude`` opening a name stays the given name, reported, being a rare Dutch given name too. :issue:`1455`
- **Add locales.NL, which reads ten as a family-name particle.** ``parser_for(locales.NL).parse("Jan ten Brink")`` gives family ``ten Brink``, where the default, as 1.4.0 through 3.1.0, gives middle ``ten``; a ``Ten`` opening a name stays the given name, reported, save under ``strict=True``. It also takes a Chinese given-name syllable inside a name into the family (``Kheng Ten Choo`` gives family ``Ten Choo``), and choosing Dutch reads ``VD`` as ``van der`` rather than the credential (``John Smith, VD`` gives family ``John Smith VD``). See :ref:`dutch-particles`. :issue:`1455`
Expand Down
37 changes: 23 additions & 14 deletions docs/suggest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ the settings its names agree on, and a parser that reads with them.
'Morgan'

Four names vote for family first: ``Kim``, ``Wang`` and ``Nguyen`` by
the romanized surname in front, ``Garcia Emily`` by the common given
name at the end; ``Wang Xiaoming`` carries both, so each signal's row
counts it. ``Taylor Morgan`` gives no evidence: it is read family
the common surname in front, ``Garcia Emily`` by the surname in front
and the common given name at the end; ``Wang Xiaoming`` and ``Garcia
Emily`` carry both, so each signal's row counts them. ``Taylor Morgan`` gives no evidence: it is read family
first because the list is, and nothing in the name can confirm that.

Each name votes on its order from the evidence it carries
Expand Down Expand Up @@ -113,7 +113,7 @@ the names that disagree with it:
>>> print(suggestion)
Suggested for 5 names (base: Parser(Lexicon(default), Policy())):
name_order FAMILY_FIRST 4 for, 0 against, 1 no evidence
surname FAMILY_FIRST 3
surname FAMILY_FIRST 4
given-name FAMILY_FIRST 2
patronymic_rules unchanged (none) no evidence
initials_as_family unchanged (False) no evidence
Expand Down Expand Up @@ -179,7 +179,7 @@ The report counts it as ``against`` and names it on its last line:
>>> print(mixed)
Suggested for 6 names (base: Parser(Lexicon(default), Policy())):
name_order FAMILY_FIRST 4 for, 1 against, 1 no evidence
surname FAMILY_FIRST 3
surname FAMILY_FIRST 4
given-name FAMILY_FIRST 2
given-name GIVEN_FIRST 1
patronymic_rules unchanged (none) no evidence
Expand Down Expand Up @@ -249,7 +249,7 @@ A setting whose votes fall short of its threshold above keeps the
base parser's value rather than a guess, whatever the other settings
decide. Where every setting falls short, or no name in the list
carries evidence, the patch is empty. None of these
names holds a romanized surname, a given name that is rarely a
names holds a listed surname, a given name that is rarely a
surname, or any other evidence on the order:

.. doctest::
Expand Down Expand Up @@ -310,8 +310,11 @@ Each name votes on its order from the evidence it carries:
of bylines may get no order suggestion: where you know a list is
bylines, set ``name_order=FAMILY_FIRST`` yourself.
- **A lowercase particle** first or before the last word.
- **A common romanized Chinese, Korean or Vietnamese surname** as the
first or last word.
- **A common surname** as the first or last word: a romanized
Chinese, Korean or Vietnamese one, or one that researchers rarely
write as a given name (``García``, ``Quispe``, ``Popov``), most of
them Spanish. A name with a listed surname at both ends casts no
surname vote.
- **A common given name that is rarely a surname** (``Emily``, not
``Taylor``) as the first or last word.

Expand Down Expand Up @@ -407,7 +410,9 @@ The names' own order votes come before the table in two cases:

- **They decide a family-first order.** The rule never overrides it:
the list gets the rule with that order, under which the rule
reorders no name.
reorders no name. A ``FAMILY_FIRST_GIVEN_LAST`` base gets
``FAMILY_FIRST`` there, since its own order would read the
patronymic as the given name (``Popov Ivan Ivanovich``).
- **They decide given-first under a** ``FAMILY_FIRST`` **base.** The
second row does not apply, and the list gets ``GIVEN_FIRST`` with
the rule.
Expand Down Expand Up @@ -657,14 +662,14 @@ and how it varies, and will differ for every dataset.

- **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.
the three 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
fall short of the thresholds keeps the base rather than guess
(:ref:`suggest-deciding`).
Italian names to 50 for Russian and Indian ones and 200 for
Bangladeshi ones. A group whose votes fall short of the thresholds
keeps the base rather than guess (:ref:`suggest-deciding`).

Two kinds of list keep their order less often:
Three kinds of list keep their order less often:

- **Given names in capitals** (``ANNA Smith``) have their capitals read
as a family name, and such a list is suggested ``capitals_as_family``
Expand All @@ -677,6 +682,10 @@ Two kinds of list keep their order less often:
but two or three joined initials (``AM Hoy``) kept it in just under
95% of groups of 50 and 93% of groups of 100. Where you know how such
a list is written, set ``name_order`` yourself.
- **Given names that are common surnames elsewhere** (``Cooper``,
``Burke``, ``Moreno``) are read as surnames. A list of nothing but
such given names is read the wrong way round; mixed into a longer
list, they are outvoted.

``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
36 changes: 21 additions & 15 deletions nameparser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,19 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
A group decided East Slavic gets the rule and reads
given-first, the order the rule reorders each name under,
unless its names' own votes decide family-first, which the rule
never overrides. One case keeps a declared order instead: under
a ``FAMILY_FIRST`` parser whose names' votes do not decide
never overrides: there a ``FAMILY_FIRST_GIVEN_LAST`` parser gets
``FAMILY_FIRST``, under which the patronymic is not read as the
given name (``Popov Ivan Ivanovich``). One case keeps a
declared order instead: under a ``FAMILY_FIRST`` parser whose names' votes do not decide
given-first, where more of the names carrying the patronymic
write it last (``Sidorov Ivan Petrovich``) than in the middle
(``Ivan Petrovich Sidorov``), the group keeps that order and
gets the rule alone, which reorders no name there and fills the
``patronymic`` view; the names written the other way get no
given-first order, and the patronymic evidence's note counts
them. A tie, and a ``FAMILY_FIRST_GIVEN_LAST`` parser,
get the given-first order with the rule. A Turkic group
them. A tie, and a ``FAMILY_FIRST_GIVEN_LAST`` parser whose
names' votes do not decide family-first, get the given-first
order with the rule. A Turkic group
gets the rule alone, its order decided by its names' own votes.
``initials_as_family`` (rules/O8) is turned on where one run of
letters ends at least two names and at least half of the names
Expand Down Expand Up @@ -388,11 +391,11 @@ 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, 2026-11-15 and 2026-11-16, with
2026-11-14, 2026-11-15, 2026-11-16 and 2026-11-19, 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
(decisions/group-suggestion's 2026-11-19 #1364 entry holds
the sizes): 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
Expand All @@ -403,19 +406,22 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
(``AM Hoy``) kept it in at least 97% of groups at every size
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.
a few of its names. And a list of nothing but given names that
ORCID's holders type as surnames (``Cooper``, ``Burke``) fell
below 95% at every size and was read wrong in every group from
5 names, the surname table voting on each of them (that file's
2026-11-19 #1364 entry).
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
surnames and the common given names) were read right in 95% of
groups from 5 names; German, Dutch, Spanish, British, French,
Romanian and Vietnamese from 10; US, Japanese, Turkish,
Nigerian and Brazilian from 20; and Russian and Indian from
50. A group whose votes fall short of the thresholds keeps
the base rather than guess, so a smaller group moves it in fewer
of the draws. ``capitals_as_family``, measured 2026-11-12
Romanian, Vietnamese and Japanese from 10; US, Turkish,
Nigerian and Brazilian from 20; Russian and Indian from 50;
PatentsView's Philippine inventors from 100; and PSC's
Bangladeshi filers from 200. A group whose votes fall short of
the thresholds keeps the base rather than guess, so a smaller
group moves it in fewer of the draws. ``capitals_as_family``, measured 2026-11-12
(decisions/group-suggestion's CAPITALS entry): ORCID holders who
typed their family name in capitals were suggested it in at least
95% of groups from 4 names, and from 10 where many of the
Expand Down
39 changes: 24 additions & 15 deletions nameparser/_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
decided East Slavic rule reorders each name itself, and reorders none
under a family-first order, so it decides the order as given-first,
unless the names' own votes decide family-first, which it never
overrides, or the base reads ``FAMILY_FIRST`` and the patronymics are
overrides (a ``FAMILY_FIRST_GIVEN_LAST`` base then gets ``FAMILY_FIRST``),
or the base reads ``FAMILY_FIRST`` and the patronymics are
mostly written last, whose order it keeps (decisions/group-suggestion).
Before either it decides
``initials_as_family`` (rules/O8) from the runs of letters ending the
Expand Down Expand Up @@ -81,10 +82,11 @@
apply_patch, initials_as_family_may_move,
)
from ._types import (
ADDED_IN, FAMILY_FIRST, GIVEN_FIRST, ReadingSource, Role,
ADDED_IN, FAMILY_FIRST, FAMILY_FIRST_GIVEN_LAST, GIVEN_FIRST,
ReadingSource, Role,
_guarded_getstate, _guarded_setstate,
)
from .config._order_names import COMMON_GIVEN_NAMES, ROMANIZED_SURNAMES
from .config._order_names import COMMON_GIVEN_NAMES, SURNAMES

if TYPE_CHECKING:
from ._parser import Parser
Expand Down Expand Up @@ -128,8 +130,9 @@ class Signal(StrEnum):
TRAILING_INITIAL = "trailing-initial"
#: A lowercase particle first or before the last word.
PARTICLE = "particle"
#: A common romanized Chinese, Korean or Vietnamese surname as the
#: first or last word.
#: A common surname as the first or last word: a romanized Chinese,
#: Korean or Vietnamese one, or one ORCID's holders rarely type as a
#: given name (``García``, #1364).
SURNAME = "surname"
#: A common given name that is rarely a surname (``Emily``, not
#: ``Taylor``) as the first or last word.
Expand Down Expand Up @@ -238,13 +241,13 @@ def _listed(word: str, table: frozenset[str]) -> bool:
def _a_listed_name(word: str) -> bool:
"""A word the name tables list: name evidence, which is never read
past as a title or a post-nominal (`Law`, a Cantonese surname and a
listed title). The given-name table holds no listed suffix since
#1357, and the surname table's (`ma`, `meng`) are acronyms that may
be a name, which are not read past bare with or without this test,
so the post-nominal half acts on no shipped word; it holds for a
table built otherwise."""
return (_listed(word, ROMANIZED_SURNAMES)
or _listed(word, COMMON_GIVEN_NAMES))
listed title). The given-name and ORCID surname tables hold no
listed suffix or title (their builder refuses them), and the
romanized surname table's suffixes (`ma`, `meng`) are acronyms that
may be a name, which are not read past bare with or without this
test, so the post-nominal half acts on no shipped word; it holds for
a table built otherwise."""
return _listed(word, SURNAMES) or _listed(word, COMMON_GIVEN_NAMES)


def _is_leading_title(word: str, lexicon: Lexicon) -> bool:
Expand Down Expand Up @@ -426,9 +429,9 @@ def _read(text: str, lexicon: Lexicon
# (#1397)
silent = _opens_in_short_capitals(words) or (
_ends_in_short_capitals(words)
and _listed(words[-1], ROMANIZED_SURNAMES))
and _listed(words[-1], SURNAMES))
tables = () if silent else (
(Signal.SURNAME, ROMANIZED_SURNAMES, FAMILY_FIRST, GIVEN_FIRST),)
(Signal.SURNAME, SURNAMES, FAMILY_FIRST, GIVEN_FIRST),)
for signal, table, first_order, last_order in (
*tables,
(Signal.GIVEN_NAME, COMMON_GIVEN_NAMES, GIVEN_FIRST, FAMILY_FIRST)):
Expand Down Expand Up @@ -1239,7 +1242,11 @@ def _decide_order(tally: _Tally, base_order: tuple[Role, Role, Role],
decided East Slavic rule decides the order as given-first, since
the rule reorders each name and reorders none under a family-first
order, unless the names' own votes decide family-first: a decided
order is never overridden, and the rule then reorders no name. A
order is never overridden, and the rule then reorders no name. There
a ``FAMILY_FIRST_GIVEN_LAST`` base gets ``FAMILY_FIRST``, whose
reading the rule leaves as written (`Popov Ivan Ivanovich`, given
`Ivan`); its own spelling would read the patronymic as the given name
(decisions/group-suggestion, 2026-11-19 #1364). A
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."""
Expand All @@ -1262,6 +1269,8 @@ def _decide_order(tally: _Tally, base_order: tuple[Role, Role, Role],
# the order tally holds orders alone
order = base_order if _end(base_order) == end else cast(
"tuple[Role, Role, Role]", end)
if rule_needs_given_first and order == FAMILY_FIRST_GIVEN_LAST:
order = FAMILY_FIRST
fields: dict[str, object] = (
{} if order == base_order else {_NAME_ORDER: order})
return (tally.evidence(_NAME_ORDER, order, True,
Expand Down
Loading