From bb06094fef0aac1b9a21fdb48d03ebd8f8b333d4 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 12:40:53 -0800 Subject: [PATCH 1/4] Show how to find the credentials a caller's data uses that the vocabulary lacks A subsection of policy.rst's 'Credentials the vocabulary doesn't list': parse, keep comma names whose family came out two or more words long, count their given names, and add the credentials at the top with Lexicon.add(kind='credential'). It also says that a suffix-or-name report marks a credential weighed against a name, and that an unlisted mixed-case word carries none. Co-Authored-By: Claude Opus 5.5 --- docs/policy.rst | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/docs/policy.rst b/docs/policy.rst index 0fbe83c27..480fd7ad4 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -1532,6 +1532,59 @@ two-word surname, which the default reads as a credential: >>> caps_off.parse("García Márquez, GABRIEL").given 'GABRIEL' +.. _finding-missing-credentials: + +Finding the credentials your data uses +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A credential written in mixed case that the vocabulary does not list +(``PhDc``, ``Pharm-D``) is read by neither shape above. After a comma +behind a full name it becomes the given name, and the words before the +comma become the family name, the way ``Ruiz Paz, Ana`` is read. To +find the ones your data holds: + +1. Parse every name, and keep those whose text holds a comma and whose + family name came out two or more words long. +2. Count the given names of those kept. +3. Read the top of the count. The credentials stand there, among + real listings of a two-word surname (``Ana`` below), which only a + reader can tell apart. +4. Add each credential to a :class:`~nameparser.Lexicon` (see + :ref:`adding-a-word`) and build a :class:`~nameparser.Parser` on it. + +.. doctest:: + + >>> from collections import Counter + >>> records = ["Ana Ruiz Paz, PhDc", "Lena Moreau Diaz, Pharm-D", + ... "Tomas Vidal Ortega, PhDc", "Ruiz Paz, Ana"] + >>> tally = Counter() + >>> for text in records: + ... parsed = parse(text) + ... if "," in text and len(parsed.family.split()) >= 2: + ... tally[parsed.given] += 1 + >>> tally.most_common() + [('PhDc', 2), ('Pharm-D', 1), ('Ana', 1)] + >>> with_creds = Parser(lexicon=Lexicon.default().add( + ... "phdc", "pharm-d", kind="credential")) + >>> fixed = with_creds.parse("Ana Ruiz Paz, PhDc") + >>> fixed.given, fixed.family, fixed.suffix + ('Ana', 'Paz', 'PhDc') + >>> with_creds.parse("Ruiz Paz, Ana").given + 'Ana' + +A non-empty ``ambiguities`` holding ``suffix-or-name`` marks a name +where the parser weighed a credential against a name, as it does for +the capitals shape. A mixed-case word it does not read by shape is +never weighed, so it carries no report, and the count above is the way +to find it: + +.. doctest:: + + >>> [a.kind.value for a in parse("Ana Ruiz Paz, XYZ").ambiguities] + ['suffix-or-name'] + >>> parse("Ana Ruiz Paz, PhDc").ambiguities + () + .. _strip-flags: Keeping emoji and control characters From 9a5a452d501583c9ad39e42d164062af9cc09edf Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 12:44:33 -0800 Subject: [PATCH 2/4] Address the reader review of the missing-credentials recipe Scope the no-report claim to a word standing alone after the comma (a word behind a listed credential is read and reported); say an added word is read wherever it stands, with a doctest line; soften 'the top of the count' for data rich in two-word surnames; import what the block uses; rename its loop variables; link the new label from the section's intro and from customize.rst's Adding a word. Co-Authored-By: Claude Opus 5.5 --- docs/customize.rst | 3 +++ docs/policy.rst | 33 +++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/docs/customize.rst b/docs/customize.rst index 555a803e0..6207976e2 100644 --- a/docs/customize.rst +++ b/docs/customize.rst @@ -88,6 +88,9 @@ list is one reading per word: >>> Parser(lexicon=lex).parse("John Smith LEED AP").suffix 'LEED AP' +To find the credentials your own data holds that the defaults do not +list, see :ref:`finding-missing-credentials`. + A surname particle is added the same way. The defaults leave out the Dutch ``in`` of ``in 't Veld``, which as a default would take a middle name spelled like it into the surname of names in every language; add diff --git a/docs/policy.rst b/docs/policy.rst index 480fd7ad4..9bdca9aa7 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -1326,7 +1326,8 @@ an unlisted word as a credential from how it is written: in periods (``X.Y.Z.``), or in capitals (``XYZ``). The writing cannot settle it alone, because a surname can be written either way, so both fields also decide by position: the word has to stand behind a name that can -spare it. +spare it. For the ones written otherwise, see +:ref:`finding-missing-credentials`. Both fields share one exception. Two letters alone right after a comma are how a person's initials are written, and the words before the comma @@ -1546,22 +1547,28 @@ find the ones your data holds: 1. Parse every name, and keep those whose text holds a comma and whose family name came out two or more words long. 2. Count the given names of those kept. -3. Read the top of the count. The credentials stand there, among +3. Read the count from the top. The credentials stand near it, among real listings of a two-word surname (``Ana`` below), which only a - reader can tell apart. + reader can tell apart; in data rich in two-word surnames, such as + Spanish or Portuguese names, the given names can outnumber them. 4. Add each credential to a :class:`~nameparser.Lexicon` (see :ref:`adding-a-word`) and build a :class:`~nameparser.Parser` on it. +The count finds the comma shape, the one easiest to detect. An added +word is read as a credential wherever it stands, ending a name with no +comma included, where unlisted it reads as the family name. + .. doctest:: >>> from collections import Counter + >>> from nameparser import Lexicon, Parser, parse >>> records = ["Ana Ruiz Paz, PhDc", "Lena Moreau Diaz, Pharm-D", ... "Tomas Vidal Ortega, PhDc", "Ruiz Paz, Ana"] >>> tally = Counter() - >>> for text in records: - ... parsed = parse(text) - ... if "," in text and len(parsed.family.split()) >= 2: - ... tally[parsed.given] += 1 + >>> for cred_text in records: + ... cred_parsed = parse(cred_text) + ... if "," in cred_text and len(cred_parsed.family.split()) >= 2: + ... tally[cred_parsed.given] += 1 >>> tally.most_common() [('PhDc', 2), ('Pharm-D', 1), ('Ana', 1)] >>> with_creds = Parser(lexicon=Lexicon.default().add( @@ -1571,12 +1578,16 @@ find the ones your data holds: ('Ana', 'Paz', 'PhDc') >>> with_creds.parse("Ruiz Paz, Ana").given 'Ana' + >>> parse("Ana Ruiz Paz PhDc").family, with_creds.parse("Ana Ruiz Paz PhDc").suffix + ('PhDc', 'PhDc') A non-empty ``ambiguities`` holding ``suffix-or-name`` marks a name where the parser weighed a credential against a name, as it does for -the capitals shape. A mixed-case word it does not read by shape is -never weighed, so it carries no report, and the count above is the way -to find it: +the capitals shape, and for an unlisted word behind a listed +credential, which is read as a credential and reported +(``Ana Ruiz Paz, PhD PhDc``). A mixed-case word standing alone after +the comma is never weighed, so it carries no report, and the count +above is the way to find it: .. doctest:: @@ -1584,6 +1595,8 @@ to find it: ['suffix-or-name'] >>> parse("Ana Ruiz Paz, PhDc").ambiguities () + >>> [a.kind.value for a in parse("Ana Ruiz Paz, PhD PhDc").ambiguities] + ['suffix-or-name'] .. _strip-flags: From 45936e85a7ed2ecddad5abb8b2ae4394f9cba557 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 12:46:08 -0800 Subject: [PATCH 3/4] Narrow where an added credential is read, per the fix review Co-Authored-By: Claude Opus 5.5 --- docs/policy.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/policy.rst b/docs/policy.rst index 9bdca9aa7..607009024 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -1554,9 +1554,10 @@ find the ones your data holds: 4. Add each credential to a :class:`~nameparser.Lexicon` (see :ref:`adding-a-word`) and build a :class:`~nameparser.Parser` on it. -The count finds the comma shape, the one easiest to detect. An added -word is read as a credential wherever it stands, ending a name with no -comma included, where unlisted it reads as the family name. +The count finds the comma shape, the one a count can find. An added +word is read as a credential after a comma and where it ends a name +with no comma, where unlisted it reads as the family name; before the +end of the name it stays a name word. .. doctest:: @@ -1578,15 +1579,17 @@ comma included, where unlisted it reads as the family name. ('Ana', 'Paz', 'PhDc') >>> with_creds.parse("Ruiz Paz, Ana").given 'Ana' - >>> parse("Ana Ruiz Paz PhDc").family, with_creds.parse("Ana Ruiz Paz PhDc").suffix - ('PhDc', 'PhDc') + >>> parse("Ana Ruiz Paz PhDc").family + 'PhDc' + >>> with_creds.parse("Ana Ruiz Paz PhDc").suffix + 'PhDc' A non-empty ``ambiguities`` holding ``suffix-or-name`` marks a name where the parser weighed a credential against a name, as it does for the capitals shape, and for an unlisted word behind a listed credential, which is read as a credential and reported -(``Ana Ruiz Paz, PhD PhDc``). A mixed-case word standing alone after -the comma is never weighed, so it carries no report, and the count +(``Ana Ruiz Paz, PhD PhDc``). A mixed-case word opening the part +after the comma is never weighed, so it carries no report, and the count above is the way to find it: .. doctest:: From 650978f8c4a97cad1f0a5e7abb91eab7a0024041 Mon Sep 17 00:00:00 2001 From: Derek Gulbranson Date: Sat, 21 Nov 2026 12:46:28 -0800 Subject: [PATCH 4/4] Say why the count finds the comma shape Co-Authored-By: Claude Opus 5.5 --- docs/policy.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/policy.rst b/docs/policy.rst index 607009024..0ce0bb333 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -1554,7 +1554,8 @@ find the ones your data holds: 4. Add each credential to a :class:`~nameparser.Lexicon` (see :ref:`adding-a-word`) and build a :class:`~nameparser.Parser` on it. -The count finds the comma shape, the one a count can find. An added +The count finds the comma shape, where an unlisted credential stands +out as a given name. An added word is read as a credential after a comma and where it ends a name with no comma, where unlisted it reads as the family name; before the end of the name it stays a name word.