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.

35 changes: 26 additions & 9 deletions docs/design/decisions/group-suggestion.md

Large diffs are not rendered by default.

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 where a Russian-style patronymic stands as a vote on the order, and add Signal.PATRONYMIC_POSITION, the signal that casts it.** ``Parser().suggest(["Sidorov Ivan Petrovich", "Volkov Pavel Sergeevich", "Orlova Anna Ivanovna", "Zaitsev Oleg Nikolaevich", "Belova Vera Andreevna"]).patch`` gives ``PolicyPatch(name_order=FAMILY_FIRST, patronymic_rules=...)``, where 3.1.0 gave the rule with the given-first order, which misread any name of two words in such a list (``Sidorov Ivan`` gave family ``Ivan``); a patronymic in the middle votes given-first. :issue:`1447`
- **Fix the surname1 and surname2 views, which left a family of two surnames whole before a family comma, opening with a particle, or behind a given name a particle completes.** Under ``two_family_names``, as ``locales.ES``, ``ES_AR``, ``CS``, ``SK``, ``PT_BR`` and ``PT_PT`` turn it on, ``parser_for(locales.ES).parse("García Márquez, Gabriel")`` gives surname1 ``García``, surname2 ``Márquez``, as ``Gabriel García Márquez`` does, where 3.0.0 through 3.1.0 gave surname1 ``García Márquez``, surname2 ``''``. No field moves; a family joined by ``y`` or written as one hyphenated word stays whole, and so, where 3.0.0 through 3.1.0 divided them, do a lone particle and the word after it under a family-first order (``Van Gogh``) and a Turkic father's name with its marker; with ``capitals_as_family`` on too, the family the capitals name is divided. :issue:`1456`, :issue:`1479`
- **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 a job or degree written out after a name and a comma, which took the name over.** ``parse("Nadir Qassoumi, Bachelor")`` gives title ``Bachelor``, given ``Nadir``, family ``Qassoumi``, where 1.4.0 through 3.1.0 gave given ``Bachelor``, family ``Nadir Qassoumi``; ``Medical Doctor`` and ``Clinical Research Coordinator`` read as one title. A name the word opens reads it as the title too (``Student Mary Jones`` gives title ``Student``), and the possessive ``Master's degree`` still takes the name over. :issue:`1457`
Expand Down
76 changes: 43 additions & 33 deletions docs/suggest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ Each name votes on its order from the evidence it carries:
surname vote.
- **A common given name that is rarely a surname** (``Emily``, not
``Taylor``) as the first or last word.
- **Where a Russian-style patronymic stands** in a name of three words
(:ref:`suggest-patronymics`): last (``Sidorov Ivan Petrovich``), the
family name is written first; in the middle (``Ivan Petrovich
Sidorov``), it is written last.

Each is read past the titles and post-nominals your parser's vocabulary
lists (``Dr.``, ``PhD``, ``Jr.``). A name with a comma states its own
Expand Down Expand Up @@ -348,8 +352,9 @@ carry one rule's patronymic and they are more than four in five of the
names that cast any vote, on the order or on a patronymic.

Under the default parser a list written family name first reads its
patronymic as the family name; with the rule, each name is put back in
order and its patronymic set apart:
patronymic as the family name. Where the patronymics stand says how
the list is written, so the suggestion reads it family first, with the
rule setting each patronymic apart:

.. doctest::

Expand All @@ -360,7 +365,7 @@ order and its patronymic set apart:
'Petrovich'
>>> slavic = Parser().suggest(registry)
>>> slavic.patch
PolicyPatch(patronymic_rules=frozenset({<PatronymicRule.EAST_SLAVIC: 'east-slavic'>}))
PolicyPatch(name_order=FAMILY_FIRST, patronymic_rules=frozenset({<PatronymicRule.EAST_SLAVIC: 'east-slavic'>}))
>>> sidorov = slavic.parser.parse("Sidorov Ivan Petrovich")
>>> sidorov.given, sidorov.family, sidorov.patronymic
('Ivan', 'Sidorov', 'Petrovich')
Expand All @@ -369,11 +374,11 @@ The order that comes with the rule
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A Turkic rule is suggested alone: it reads a name written either way
round, so the order is left to the names' own votes. The East Slavic
rule reorders a name only under a given-first order, so what is
suggested with it depends on the base parser's order and on where the
list writes the patronymic, last (``Sidorov Ivan Petrovich``) or in
the middle (``Ivan Petrovich Sidorov``):
round, so the order is left to the names' own votes. Where an East
Slavic patronymic stands is itself a vote on the order, last
(``Sidorov Ivan Petrovich``) for family first and in the middle
(``Ivan Petrovich Sidorov``) for given first, so a list that writes its
patronymics one way gets that order with the rule:

.. list-table::
:header-rows: 1
Expand All @@ -383,18 +388,30 @@ the middle (``Ivan Petrovich Sidorov``):
- The list writes the patronymic
- Order suggested with the rule
* - ``GIVEN_FIRST``
- last or in the middle
- last
- ``FAMILY_FIRST``
* - ``GIVEN_FIRST``
- in the middle
- none: the base's stays
* - ``FAMILY_FIRST``
- last in more names than in the middle
- last
- none: the base's stays
* - ``FAMILY_FIRST``
- in the middle in as many names, or more
- in the middle
- ``GIVEN_FIRST``
* - ``FAMILY_FIRST_GIVEN_LAST``
- last or in the middle
- last
- ``FAMILY_FIRST``, since its own order would read the
patronymic as the given name
* - ``FAMILY_FIRST_GIVEN_LAST``
- in the middle
- ``GIVEN_FIRST``

The rule reorders a name only under a given-first order, and reads a
name written family first under a family-first one, where it reorders
none and fills the ``patronymic`` view. A name of two words in the same
list (``Sidorov Ivan``) is read in the order suggested.

.. doctest::

>>> family_first = Parser(policy=Policy(name_order=FAMILY_FIRST))
Expand All @@ -406,21 +423,13 @@ the middle (``Ivan Petrovich Sidorov``):
>>> family_first.suggest(spoken).patch
PolicyPatch(name_order=GIVEN_FIRST, patronymic_rules=frozenset({<PatronymicRule.EAST_SLAVIC: 'east-slavic'>}))

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. 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.

Where a ``FAMILY_FIRST`` base keeps its order, the rule reorders no
name there and fills the ``patronymic`` view. The names written the
other way, patronymic in the middle, get no given-first order, and the
note under ``patronymic_rules`` counts them.
Where the names' votes decide no order (a list writing as many
patronymics one way as the other, or too few one way, or other
evidence contradicting them), the rule brings the given-first order it reorders each name
under, save under a ``FAMILY_FIRST`` base whose list writes the
patronymic last in more names than in the middle, which keeps its
order; the note under ``patronymic_rules`` counts the names written the
other way.

What counts for and against
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -445,13 +454,14 @@ What the report shows
~~~~~~~~~~~~~~~~~~~~~

The ``patronymic_rules`` line has a row for each rule the names voted
for, and the ``name_order`` line a note where the rule decided the
order:
for, the ``name_order`` line a ``patronymic-position`` row for where
the patronymics stand, and a note on how the order and the rule were
decided together:

.. doctest::

>>> [e.note for e in slavic.evidence if e.setting == "name_order"]
['the East Slavic rule reorders each name; it needs a given-first order']
["the East Slavic rule is decided too, but the names' order votes decide a family-first order, under which the rule reorders no name"]

.. _suggest-initials:

Expand Down Expand Up @@ -664,9 +674,9 @@ and how it varies, and will differ for every dataset.
of groups from 2 to 2,000 names, and 97% for nearly every kind, save
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 and 200 for
Bangladeshi ones. A group whose votes fall short of the thresholds
base, from 5 for Chinese, Taiwanese, Korean, Czech, Polish, Italian
and Russian names to 50 for 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`).

Three kinds of list keep their order less often:
Expand Down
33 changes: 19 additions & 14 deletions nameparser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,11 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
name of fewer than two words once those are read past casts
none, and so does a name with a comma, unless only
post-nominals follow the comma. A patronymic votes only where
the patronymic rule reads one, and a trailing initial
(``Smith J.``) only where at least three names, and 60% of the
the patronymic rule reads one, and an East Slavic one votes on
the order too, by where it stands: last for family-first
(``Sidorov Ivan Petrovich``), in the middle for given-first
(``Ivan Petrovich Sidorov``). A trailing initial
(``Smith J.``) votes only where at least three names, and 60% of the
group's names holding a name word, end in initials no other
signal in the same name contradicts. A capitals word of two
or three letters ending a name in mixed case (``Armitage JO``),
Expand All @@ -347,11 +350,12 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
note says how many.
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: 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
unless its names' own votes decide family-first, as a list of
patronymics written last does, which the rule 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
Expand Down Expand Up @@ -394,8 +398,8 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
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-19 #1364 entry holds
the sizes): a group written in this parser's own order kept it
(decisions/group-suggestion's 2026-11-19 #1364 and #1447
entries hold 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 @@ -414,12 +418,13 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
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,
surnames and the common given names) and of Russian ones (where
their patronymics stand) were read right in 95% of groups from 5
names; German, Dutch, Spanish, British, French,
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
Nigerian and Brazilian from 20; Indian from 50; and PSC's
Bangladeshi filers from 200 (PatentsView's Philippine inventors
from 20, through the Russian names among them). 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
Expand Down
39 changes: 34 additions & 5 deletions nameparser/_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@
(Hangul, Han) simply matches nothing. A patronymic
votes, Latin or Cyrillic, only where the pipeline's rule reads one
(rules/O1's three name words, rules/O2's four), through the pipeline's
own predicates, never a copy of them. No signal raises on any string.
own predicates, never a copy of them, and an East Slavic one casts a
second vote, on the order, by where it stands as rules/O1 reads it
(``Signal.PATRONYMIC_POSITION``: last family-first, in the middle
given-first). No signal raises on any string.

``suggest`` tallies the group's votes and decides two settings
together, ``patronymic_rules`` first and ``name_order`` second: a
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 (a ``FAMILY_FIRST_GIVEN_LAST`` base then gets ``FAMILY_FIRST``),
unless the names' own votes decide family-first, as a list of
patronymics written last does, which it never 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
Expand Down Expand Up @@ -140,6 +144,13 @@ class Signal(StrEnum):
#: A patronymic one rule reads (Russian ``Petrovich``, Azerbaijani
#: ``Huseyn oglu``), the evidence on ``patronymic_rules``.
PATRONYMIC = "patronymic"
#: Where an East Slavic patronymic of three name words stands, read
#: where rules/O1 reads it, the evidence on ``name_order``: in the
#: middle (``Ivan Petrovich Sidorov``) the family is written last,
#: the middle word winning where the last ends as a patronymic too;
#: last (``Sidorov Ivan Petrovich``) it is written first. Cast only
#: beside an East Slavic ``PATRONYMIC`` vote.
PATRONYMIC_POSITION = "patronymic-position"


_INITIAL_JOINS = re.compile(r"[.-]+")
Expand Down Expand Up @@ -361,6 +372,18 @@ def _patronymic(words: list[str]) -> PatronymicRule | None:
return None


def _patronymic_end(words: list[str]) -> tuple[Role, Role, Role]:
"""The end a name casting the East Slavic vote writes its family at,
read where rules/O1 reads it: the ending on the middle word is the
given-first shape (given, patronymic, family), whatever the last
word ends in, and otherwise the patronymic stands last, the
family-first shape the rule restores (family, given, patronymic).
Asked only of a name `_patronymic` votes East Slavic for, three
words long."""
middle = words[1].rstrip(".") or words[1]
return GIVEN_FIRST if has_patronymic_ending(middle) else FAMILY_FIRST


def _letter_run(text: str, readers: tuple[Parser, Parser]) -> str | None:
"""The letters ending `text` that are evidence of the convention
rules/O8 reads, folded and run together (`Lakshmi R. S.` gives
Expand Down Expand Up @@ -443,6 +466,8 @@ def _read(text: str, lexicon: Lexicon
patronymic = _patronymic(words)
if patronymic is not None:
votes[Signal.PATRONYMIC] = patronymic
if patronymic is PatronymicRule.EAST_SLAVIC:
votes[Signal.PATRONYMIC_POSITION] = _patronymic_end(words)
return votes, False, words


Expand Down Expand Up @@ -1191,14 +1216,18 @@ def _keeps_family_first(
with the ending on both its middle and its last word counts as
middle, as rules/O1 reads it. ``FAMILY_FIRST_GIVEN_LAST`` is never
kept: that order takes the patronymic of such a list for the given
name, and the given-first order with the rule reads it."""
name; the names' position votes give it ``FAMILY_FIRST``
(`_decide_order`), and where they decide no order the given-first
order with the rule reads it. Since the position votes (#1447) the
question is asked only where the votes decide no order or decide
the base's own."""
if policy.name_order != FAMILY_FIRST or order_end == GIVEN_FIRST:
return None
last = middle = 0
for _, votes, _, words in with_words:
if votes.get(Signal.PATRONYMIC) is PatronymicRule.EAST_SLAVIC:
# _patronymic votes East Slavic on three words alone
if has_patronymic_ending(words[1].rstrip(".") or words[1]):
if _patronymic_end(words) == GIVEN_FIRST:
middle += 1
else:
last += 1
Expand Down
Loading