Skip to content

Commit 1e920d6

Browse files
derek73claude
andauthored
Show how to find the credentials your data uses that the vocabulary lacks (#1515)
* 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * Narrow where an added credential is read, per the fix review Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Say why the count finds the comma shape Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bdc466d commit 1e920d6

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

‎docs/customize.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ list is one reading per word:
8888
>>> Parser(lexicon=lex).parse("John Smith LEED AP").suffix
8989
'LEED AP'
9090

91+
To find the credentials your own data holds that the defaults do not
92+
list, see :ref:`finding-missing-credentials`.
93+
9194
A surname particle is added the same way. The defaults leave out the
9295
Dutch ``in`` of ``in 't Veld``, which as a default would take a middle
9396
name spelled like it into the surname of names in every language; add

‎docs/policy.rst‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,8 @@ an unlisted word as a credential from how it is written: in periods
13261326
(``X.Y.Z.``), or in capitals (``XYZ``). The writing cannot settle it
13271327
alone, because a surname can be written either way, so both fields
13281328
also decide by position: the word has to stand behind a name that can
1329-
spare it.
1329+
spare it. For the ones written otherwise, see
1330+
:ref:`finding-missing-credentials`.
13301331

13311332
Both fields share one exception. Two letters alone right after a comma
13321333
are how a person's initials are written, and the words before the comma
@@ -1532,6 +1533,75 @@ two-word surname, which the default reads as a credential:
15321533
>>> caps_off.parse("García Márquez, GABRIEL").given
15331534
'GABRIEL'
15341535

1536+
.. _finding-missing-credentials:
1537+
1538+
Finding the credentials your data uses
1539+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1540+
1541+
A credential written in mixed case that the vocabulary does not list
1542+
(``PhDc``, ``Pharm-D``) is read by neither shape above. After a comma
1543+
behind a full name it becomes the given name, and the words before the
1544+
comma become the family name, the way ``Ruiz Paz, Ana`` is read. To
1545+
find the ones your data holds:
1546+
1547+
1. Parse every name, and keep those whose text holds a comma and whose
1548+
family name came out two or more words long.
1549+
2. Count the given names of those kept.
1550+
3. Read the count from the top. The credentials stand near it, among
1551+
real listings of a two-word surname (``Ana`` below), which only a
1552+
reader can tell apart; in data rich in two-word surnames, such as
1553+
Spanish or Portuguese names, the given names can outnumber them.
1554+
4. Add each credential to a :class:`~nameparser.Lexicon` (see
1555+
:ref:`adding-a-word`) and build a :class:`~nameparser.Parser` on it.
1556+
1557+
The count finds the comma shape, where an unlisted credential stands
1558+
out as a given name. An added
1559+
word is read as a credential after a comma and where it ends a name
1560+
with no comma, where unlisted it reads as the family name; before the
1561+
end of the name it stays a name word.
1562+
1563+
.. doctest::
1564+
1565+
>>> from collections import Counter
1566+
>>> from nameparser import Lexicon, Parser, parse
1567+
>>> records = ["Ana Ruiz Paz, PhDc", "Lena Moreau Diaz, Pharm-D",
1568+
... "Tomas Vidal Ortega, PhDc", "Ruiz Paz, Ana"]
1569+
>>> tally = Counter()
1570+
>>> for cred_text in records:
1571+
... cred_parsed = parse(cred_text)
1572+
... if "," in cred_text and len(cred_parsed.family.split()) >= 2:
1573+
... tally[cred_parsed.given] += 1
1574+
>>> tally.most_common()
1575+
[('PhDc', 2), ('Pharm-D', 1), ('Ana', 1)]
1576+
>>> with_creds = Parser(lexicon=Lexicon.default().add(
1577+
... "phdc", "pharm-d", kind="credential"))
1578+
>>> fixed = with_creds.parse("Ana Ruiz Paz, PhDc")
1579+
>>> fixed.given, fixed.family, fixed.suffix
1580+
('Ana', 'Paz', 'PhDc')
1581+
>>> with_creds.parse("Ruiz Paz, Ana").given
1582+
'Ana'
1583+
>>> parse("Ana Ruiz Paz PhDc").family
1584+
'PhDc'
1585+
>>> with_creds.parse("Ana Ruiz Paz PhDc").suffix
1586+
'PhDc'
1587+
1588+
A non-empty ``ambiguities`` holding ``suffix-or-name`` marks a name
1589+
where the parser weighed a credential against a name, as it does for
1590+
the capitals shape, and for an unlisted word behind a listed
1591+
credential, which is read as a credential and reported
1592+
(``Ana Ruiz Paz, PhD PhDc``). A mixed-case word opening the part
1593+
after the comma is never weighed, so it carries no report, and the count
1594+
above is the way to find it:
1595+
1596+
.. doctest::
1597+
1598+
>>> [a.kind.value for a in parse("Ana Ruiz Paz, XYZ").ambiguities]
1599+
['suffix-or-name']
1600+
>>> parse("Ana Ruiz Paz, PhDc").ambiguities
1601+
()
1602+
>>> [a.kind.value for a in parse("Ana Ruiz Paz, PhD PhDc").ambiguities]
1603+
['suffix-or-name']
1604+
15351605
.. _strip-flags:
15361606

15371607
Keeping emoji and control characters

0 commit comments

Comments
 (0)