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.

25 changes: 22 additions & 3 deletions docs/design/decisions/group-suggestion.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ it, and ``suggestion.base`` is the parser you started from:
patronymic_rules unchanged (none) no evidence
initials_as_family unchanged (False) no evidence
capitals_as_family unchanged (False) 5 for, 0 against, 0 no evidence
two_family_names unchanged (False) no evidence
not read: the order is family-first, and two family names are weighed under a given-first order alone

Each setting counts its names for and against the value the suggested
parser has: all five names are in mixed case with no word in capitals,
Expand Down Expand Up @@ -147,7 +149,7 @@ 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`).

``suggest`` decides four settings from it, each only where enough of
``suggest`` decides five settings from it, each only where enough of
the list's names carry its evidence, and leaves every other one as the
parser you called it on has it:

Expand All @@ -163,6 +165,10 @@ parser you called it on has it:
- **Family names in capitals** (:ref:`capitals-as-family`): for a list
that writes the family name in capitals of four letters or more
(``Mary SMITH``) (:ref:`suggest-capitals`).
- **Two family names** (:ref:`two-family-names`): for a list written
given name first whose names carry a common surname where a second
given name would stand (``Gabriel García Márquez``)
(:ref:`suggest-two-family`).

Choose the language first
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 5 additions & 1 deletion docs/policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,11 @@ under a family-first order), and only then:
:ref:`What it costs <two-family-names-cost>` shows what it does to
other names. ``locales.ES``, ``locales.ES_AR``, ``locales.PT_BR`` and
``locales.PT_PT`` turn it on together with a list of given names that it holds back (see
`Keeping a given name out of the family`_).
`Keeping a given name out of the family`_). For a list of names,
``Parser.suggest()`` turns the bare switch on where enough of the names
write a common surname where the switch would take a word into the
family (:ref:`suggest-two-family`); where you know the list is Spanish
or Portuguese, the pack reads it better.

In Spain and most of Latin America a person carries two family names,
the father's first and then the mother's, and writes both after the
Expand Down
1 change: 1 addition & 0 deletions docs/release_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release Log

- **Fix Abdel, Abd and Abou past the first word of a name, which read as a middle name of their own.** ``parse("Tariq Abdel Aziz")`` gives family ``Abdel Aziz``, where 1.4.0 through 3.1.0 gave middle ``Abdel``, family ``Aziz``. ``Abdul`` joins only in a name of four words or more, titles and suffixes not counted, so ``Tariq Abdul Aziz`` keeps middle ``Abdul``; and after a family comma ``Abd`` before a name word is no longer the credential ABD. :issue:`1464`
- **Add locales.MS, a Malay pack, which reads Malaysian titles written before a name: Puan, Cik, Ustaz, Ustazah and Cikgu.** ``parser_for(locales.MS).parse("Puan Siti binti Ahmad")`` gives title ``Puan``, given ``Siti``, family ``binti Ahmad``, where the default, as 1.4.0 through 3.1.0, gives given ``Puan``; ``Tuan`` stays a name word, being a hereditary prefix and a Vietnamese given name, and the pack reads the Indonesian given name ``Puan`` as the title too (``Puan Maharani``): keep it to Malaysian names. See :ref:`malay-names`. :issue:`1179`
- **Change Parser.suggest() to suggest two_family_names for a list whose names end in two family names, and add Signal.FIRST_SURNAME, the signal that votes for it.** ``Parser().suggest(["María García López", "Juan Pérez Ruiz", "Ana Martínez Soto"]).patch`` gives ``PolicyPatch(two_family_names=True)``, where 3.1.0 suggested nothing; it is weighed only where the list's order is given-first, and lists measured from Argentina, Brazil and Portugal are rarely or never suggested it. ``NameEvidence.votes`` may now hold ``True`` or ``False``, the switch's value a name votes for. :issue:`1452`
- **Fix Arabic titles written short, which read as the given name, and stop giving initials for Arabic-script names.** ``parse("د. أحمد علي حسن")`` gives title ``د.``, given ``أحمد``, where 1.4.0 through 3.1.0 gave given ``د.``; ``أ.د.``, ``م.م.``, a title glued to the name and the ranks ``اللواء`` and ``المستشار`` read as titles too, and ``initials()`` gives nothing for a word in Arabic script, as for Thai and Burmese, nor does the name match read its letter as an initial. A title written with a slash (``د/``) still reads as the given name. :issue:`1149`
- **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 ud inside a South Asian compound name, which read as a credential and took the rest of the name.** ``parse("NADIR ZIA UD DIN")`` gives middle ``ZIA UD``, family ``DIN``, as 1.4.0 through 2.3.0 did, where 2.4.0 through 3.1.0 gave family ``ZIA``, suffix ``UD DIN``; ``UD`` alone after a name and a comma now reads as initials (``Anke Vissering, UD`` gives given ``UD``, family ``Anke Vissering``, where 1.4.0 through 3.1.0 gave suffix ``UD``). ``bt`` stays a credential: for Malay names remove it, as :doc:`customize` shows. :issue:`1467`
Expand Down
115 changes: 104 additions & 11 deletions docs/suggest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ first because the list is, and nothing in the name can confirm that.

Each name votes on its order from the evidence it carries
(:ref:`suggest-evidence`), and the group decides the order where enough
of its names agree (:ref:`suggest-deciding`). Three more settings are
of its names agree (:ref:`suggest-deciding`). Four more settings are
decided the same way, each by its own evidence: a patronymic rule
(:ref:`suggest-patronymics`), ``initials_as_family``
(:ref:`suggest-initials`) and ``capitals_as_family``
(:ref:`suggest-capitals`). Every setting the votes do not decide keeps
(:ref:`suggest-initials`), ``capitals_as_family``
(:ref:`suggest-capitals`) and ``two_family_names``
(:ref:`suggest-two-family`). Every setting the votes do not decide keeps
the base parser's value.

.. _suggest-how-many:
Expand Down Expand Up @@ -118,6 +119,8 @@ the names that disagree with it:
patronymic_rules unchanged (none) no evidence
initials_as_family unchanged (False) no evidence
capitals_as_family unchanged (False) 5 for, 0 against, 0 no evidence
two_family_names unchanged (False) no evidence
not read: the order is family-first, and two family names are weighed under a given-first order alone

The report reads as follows:

Expand All @@ -139,8 +142,8 @@ The report reads as follows:
SMITH`` the surname in front says family first and the capitals at
the end say family last). A contested name casts no order vote and
never disagrees on the order.
- **The indented rows** under ``name_order`` and ``patronymic_rules``
count the names by kind of evidence and the value it votes for. A
- **The indented rows** under ``name_order``, ``patronymic_rules``
and ``two_family_names`` count the names by kind of evidence and the value it votes for. A
name carrying two kinds is in two rows (``Wang Xiaoming`` above), so
the rows can add up to more than the names for.
- **An indented sentence**, where one follows, is a note saying why
Expand Down Expand Up @@ -185,6 +188,8 @@ The report counts it as ``against`` and names it on its last line:
patronymic_rules unchanged (none) no evidence
initials_as_family unchanged (False) no evidence
capitals_as_family unchanged (False) 6 for, 0 against, 0 no evidence
two_family_names unchanged (False) no evidence
not read: the order is family-first, and two family names are weighed under a given-first order alone
disagreeing (1): Emily Clark

.. _suggest-deciding:
Expand Down Expand Up @@ -220,6 +225,12 @@ and enough of them agree:
- 2 writing the family name in capitals of four letters or more
- more than two thirds of the names with evidence either way
- :ref:`suggest-capitals`
* - ``two_family_names``
- 3 with a common surname where the switch would take a first
surname
- more than three in ten of the names the switch would change,
and more than the names voting against it
- :ref:`suggest-two-family`

The group decides ``name_order`` when at least two names vote for one
end and they are more than two thirds of the names that cast an order
Expand Down Expand Up @@ -274,6 +285,7 @@ mixed case as ``for`` the switch staying off, :ref:`suggest-report`.)
patronymic_rules unchanged (none) no evidence
initials_as_family unchanged (False) no evidence
capitals_as_family unchanged (False) 3 for, 0 against, 0 no evidence
two_family_names unchanged (False) no evidence

Then, where you know how the list is written, set the order yourself
(:ref:`name-order`):
Expand Down Expand Up @@ -581,18 +593,99 @@ A list left with the switch off shows no note unless a name writes its
family in capitals, and counts its names in mixed case as ``for``
(:ref:`suggest-report`).

.. _suggest-two-family:

Lists that give two family names
--------------------------------

``suggest()`` turns ``two_family_names`` on (see
:ref:`two-family-names`) for a list written given name first whose
names end in two family names, as Spanish-speaking lists do, so that
the word before the family name joins it:

.. doctest::

>>> hispanic = Parser().suggest(["María García López", "Juan Pérez Ruiz",
... "Ana Martínez Soto"])
>>> hispanic.patch
PolicyPatch(two_family_names=True)
>>> Parser().parse("Gabriel García Márquez").family
'Márquez'
>>> hispanic.parser.parse("Gabriel García Márquez").family
'García Márquez'

A wrong suggestion here costs more than a missed one: the switch reads
a middle name as a first surname, and in lists from countries where
two family names are rare it cost up to 53 points of whole names read
right (:issue:`1452`). So the switch is decided only where at least
three names, more than three in ten of the names it would change, carry
a common surname where it would take a first surname.

What counts for and against
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Every name the switch would change counts in that share. One of three
words or more with no comma also votes for it, against it, or not at
all, by the word the switch would take into the family:

- **For**: a common surname (``García`` in ``Gabriel García
Márquez``), from the table of words ORCID's holders type as a family
name and rarely as a given name (:ref:`suggest-evidence`).
- **Against**: a father's name (``Ivan Petrovich Sidorov``), which the
switch would read as a first surname. The names voting for it must
outnumber these, and such a name disagrees with a decided switch.
- **No evidence**: every other name, a common given name there
included (``Maria Anna Berg``), which the switch would read as a
surname. A common given name casts no vote but still counts in the
share, among the names the switch would change.

The switch is weighed only once the order is settled given name first,
by the base or by the list: a list written family first is not
suggested the switch, and neither is a list for which an East Slavic
patronymic rule is on, whose fathers' names the switch would read as
surnames. A group never turns the switch off, and a base with it on is
suggested no change to it.

What the report shows
~~~~~~~~~~~~~~~~~~~~~

The note under ``two_family_names`` counts the names voting for it
among those it would change:

.. doctest::

>>> [e.note for e in hispanic.evidence if e.setting == "two_family_names"]
['3 of the 3 names two_family_names would change carry a common surname where it would take a first surname']

Where you know the list
~~~~~~~~~~~~~~~~~~~~~~~

The suggestion is the bare switch. Where you know a list is Spanish or
Portuguese, choose the language pack instead (:ref:`suggest-packs`):
it turns the switch on too, and its given names keep a compound given
name whole, which the bare switch reads as a first surname:

.. doctest::

>>> from nameparser import locales, parser_for
>>> hispanic.parser.parse("Juan Pablo Montoya").family
'Pablo Montoya'
>>> parser_for(locales.ES).parse("Juan Pablo Montoya").family
'Montoya'

.. _suggest-packs:

Choosing a language pack
------------------------

A suggestion never chooses a language pack. It proposes the four
A suggestion never chooses a language pack. It proposes the five
``Policy`` settings above (``name_order``, ``patronymic_rules``,
``initials_as_family`` and ``capitals_as_family``) and leaves the
vocabulary as the base parser has it. The words a pack turns on, and
its other rules (two family names for Spanish, dividing a Chinese
surname from the given name), come only from choosing the pack
yourself: see :ref:`shipped-packs`.
``initials_as_family``, ``capitals_as_family`` and
``two_family_names``) and leaves the vocabulary as the base parser has
it. The words a pack turns on, and its other rules (dividing a Chinese
surname from the given name, the pack's own reading of two family
names), come only from choosing the pack yourself: see
:ref:`shipped-packs`.

Where you know a list's language, build the base with ``parser_for``
and call ``suggest()`` on that; the suggested parser keeps the pack.
Expand Down
17 changes: 16 additions & 1 deletion nameparser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,22 @@ def suggest(self, names: Iterable[str]) -> Suggestion:
never turns it off, nor turns it on under a base with
``unlisted_caps_suffixes=CapsSuffixes.EVERYWHERE``, beside which
it cannot be set; it is decided apart from the order, which the
capitals in a name vote on as before. A setting the votes do not decide keeps this parser's value, so
capitals in a name vote on as before. ``two_family_names``
(rules/O6) is weighed last, and only where the rest of the
suggestion reads given-first with the East Slavic rule off: each
name is parsed with the switch off and on, and where the switch
takes a word into the family, a common surname there votes for
it (``García`` in ``Gabriel García Márquez``), a common given
name casts no vote (``María`` in ``Ana María López``), and a
father's name votes against it. It is turned on where at least
three names vote for it, more than 30% of every name the switch
would change and more than those against; a group never turns
it off; a father's name the switch would take disagrees with it.
A caller who knows a list is Spanish or Portuguese does better
with the language's pack (``locales.ES``, ``locales.PT_BR``,
``locales.PT_PT``), whose given names the switch leaves out of
the family. A setting the votes do not
decide keeps this parser's value, so
an empty group, or one with no votes, suggests no change. A
bare str, bytes, a mapping or a non-str item raises TypeError.

Expand Down
Loading