diff --git a/docs/concepts.rst b/docs/concepts.rst index 32d35ec25..aadcb8ce3 100644 --- a/docs/concepts.rst +++ b/docs/concepts.rst @@ -149,8 +149,8 @@ Vocabulary: what a word may be ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The vocabulary is consulted first. It lists what a word may be: a -title, a particle, a conjunction, a maiden marker, a post-nominal -suffix and, for some words, a given name or a surname, beside those +title, a particle, a conjunction, a maiden marker, an alias marker, a +post-nominal suffix and, for some words, a given name or a surname, beside those readings or alone. Before any of this, text set off by nickname or maiden delimiters (a ``Policy`` setting) is set aside (:ref:`nicknames-and-maiden-names`). @@ -249,8 +249,9 @@ the word stands decides whether it lands. Two examples: - **An unlisted acronym.** One written in periods (``X.Y.Z.``) is a credential behind a name that can spare it. One written in capitals (``XYZ``) is too, by default only right after a comma behind a full - name that writes a word of its own in mixed case, as ``Quill`` is - (:ref:`unlisted-credentials` says exactly where). + name that writes a word of its own in mixed case, as ``Quill`` is, and + so is one in mixed case there (``MRes``; :ref:`unlisted-credentials` + says exactly where). .. doctest:: diff --git a/docs/customize.rst b/docs/customize.rst index da907e6bb..69fedea97 100644 --- a/docs/customize.rst +++ b/docs/customize.rst @@ -6,10 +6,8 @@ smaller and more specific change than the one before: #. **Let the data choose.** If you have a list of names from one source, :meth:`Parser.suggest() ` reads - the order it is written in, a patronymic rule, whether letters - ending a name are its family name and whether family names are - written in capitals, and returns a parser set for them - (:doc:`suggest`). + the settings its names show, the order they are written in among + them, and returns a parser set for them (:doc:`suggest`). #. **Choose the language.** If you know the data's language, a locale pack (:doc:`locales`) reads that language's words and conventions, such as Spanish double surnames or Russian patronymics. Call @@ -68,6 +66,24 @@ it a title wherever it stands. Adding a title reading instead would change nothing outside a phrase, so ``add("dean", kind="title")`` warns and names the ``remove`` above. +The opposite edit, a word your data bears as a given name that the +defaults read as a title, adds the ``given`` reading. The word then +reads as a title only inside a title phrase, and the parse reports a +``title-or-name`` ambiguity where it opens a name: + +.. doctest:: + + >>> parse("Hon Chee Ming").title + 'Hon' + >>> hon_given = Parser(lexicon=Lexicon.default().add("hon", kind="given")) + >>> hon_given.parse("Hon Chee Ming").given + 'Hon' + >>> hon_given.parse("The Hon John Smith").title + 'The Hon' + +Removing the title reading instead would cost the phrase as well: +``The Hon John Smith`` would then read no title. + Both calls return a new :class:`~nameparser.Lexicon`, the one you started from (here, ``Lexicon.default()``) never being mutated. @@ -89,12 +105,17 @@ list is one reading per word: 'LEED AP' To find the credentials your own data holds that the defaults do not -list, see :ref:`finding-missing-credentials`. +list, see :ref:`finding-missing-credentials`. A credential that is +also a surname needs weighing first (`Mark a word, or leave it out`_), +and an unlisted credential in mixed case after a comma, behind a full +name holding a word in mixed case (``Jane Smith, MRes``), reads as one +already (:ref:`unlisted-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 -it when your data is Dutch: +it when your data is Dutch (``locales.NL`` reads ``ten`` but not ``in``, +:ref:`dutch-particles`): .. doctest:: @@ -334,6 +355,14 @@ arguments to ``add``: - bound_given - The words it joins past the first name word (`Bound given names`_). + * - ``completes_any=True`` + - bound_given + - It joins any plain name word after it past the first + (`Bound given names`_). + * - ``long_names_only=True`` + - bound_given + - With ``completes_any``, only in a name of four name words or more + (`Bound given names`_). * - ``completes=[...]`` - bound_second - The only words it joins behind (`Bound given names`_). @@ -493,20 +522,25 @@ Two rules follow for a given name written short: Phrases ^^^^^^^ -A reading is of one word, with two exceptions, so ``add`` refuses a -phrase of any other kind: a title addressing the given name -(``add("lt col", kind="title", addresses="given")``), matched against -the space-joined run of words already read as titles or by that run's -last word — several titles written together are one form of address -and the last one does the addressing, so ``"Her Majesty Queen -Elizabeth"`` is read by ``queen`` — and a birth marker, matched by -lookahead over the words as written: ``add("z domu", -kind="birth_marker")`` matches the pair and neither word alone, which -is how the shipped Polish entry works. The words have to stand -together — a bracketed clause or a comma between them ends the run, and -the first word is then an ordinary name word. Where a phrase and a word -starting it are both configured, the phrase wins where it matches and -the word matches everywhere else. +A reading is of one word, so ``add`` refuses a phrase, save of two +kinds: + +- **A title addressing the given name** + (``add("lt col", kind="title", addresses="given")``), matched against + the space-joined run of words already read as titles or by that run's + last word. Several titles written together are one form of address + and the last one does the addressing, so ``"Her Majesty Queen + Elizabeth"`` is read by ``queen``. +- **A birth marker**, matched by lookahead over the words as written: + ``add("z domu", kind="birth_marker")`` matches the pair and neither + word alone, which is how the shipped Polish entry works. + +The words have to stand together: a bracketed clause or a comma +between them ends the run, and the first word is then an ordinary name +word. + +Where a phrase and a word starting it are both configured, the phrase +wins where it matches and the word matches everywhere else. The limit is on what a reading holds, not on the shape a name can have. Adjacent suffix words are reassembled after they match, so a multi-word @@ -517,6 +551,8 @@ credential is reachable as its component words: >>> parse("John Smith, MD PhD").suffix 'MD PhD' +.. _alias-markers: + Alias markers ^^^^^^^^^^^^^ @@ -525,20 +561,31 @@ person is known by, which is read as the nickname, the marker dropped. ``@`` written as a word of its own and ``urf`` are read so by default. The English ``alias`` and ``aka`` ship turned off, because each is a given name or a surname more often than a marker (``Aka`` is a Turkish -and an Ivorian surname); a choice of English (``languages={"en"}``) -turns them on with the rest of English's readings that are off by -default. If your records write them as markers, add just them: +and an Ivorian surname); a choice of English +(``languages=frozenset({"en"})``, :ref:`choosing-languages`) turns them +on with the rest of English's readings that are off by default. If your +records write them as markers, add just them: .. doctest:: - >>> fec = Parser(lexicon=Lexicon.default().add( + >>> aka = Parser(lexicon=Lexicon.default().add( ... "aka", "alias", kind="alias_marker")) - >>> boscia = fec.parse("BOSCIA, FRANK AKA FRANCIS") - >>> boscia.given, boscia.nickname + >>> frank = aka.parse("QUELLWOOD, FRANK AKA FRANCIS") + >>> frank.given, frank.nickname ('FRANK', 'FRANCIS') - >>> parse("BOSCIA, FRANK AKA FRANCIS").middle + >>> parse("QUELLWOOD, FRANK AKA FRANCIS").middle 'AKA FRANCIS' +The cost is a name holding the word as a name: with the marker added, +``Frank Aka Quellwood`` reads nickname ``Quellwood`` and no family: + +.. doctest:: + + >>> aka.parse("Frank Aka Quellwood").family + '' + >>> parse("Frank Aka Quellwood").family + 'Quellwood' + The alias runs to a patronymic particle (``bin``, ``a/l``), another marker or a comma, and otherwise to the end of the name, less any trailing suffixes and titles. So two words after the marker are both taken, which @@ -880,6 +927,8 @@ falls through to nickname parsing (``"John Smith (Ba)"``, ``"Jeffrey (JD) Bricken"``), reported as a ``suffix-or-nickname`` ambiguity. +.. _malay-bt: + Malay names and bt ^^^^^^^^^^^^^^^^^^ @@ -903,7 +952,10 @@ then reads family ``Bt``, and ``Sir John Smith, Bt`` reads given ``Bt``, the name before the comma the family. The default keeps the reading because ``bt`` is rare on the lists measured, a Malaysian one included (:issue:`1467`), and ``Bt`` written in Title case reads as a -name word already (``Nur Aina Bt Rosli``). +name word already (``Nur Aina Bt Rosli``). ``locales.MS`` keeps the +credential reading too: make the edit on the pack's parser +(``dataclasses.replace(ms, lexicon=ms.lexicon.remove("bt", +kind="credential"))`` for ``ms = parser_for(locales.MS)``). Generation words that are also surnames ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -995,13 +1047,17 @@ a title only inside a title phrase: behind a style 'Major General' A language can run the other way, holding a given-name reading of a -title that its file leaves off until the language is chosen. ``Lady`` -is a given name under a Spanish choice (``locales.ES``), ``Hon`` under -a Chinese choice of languages (a :class:`~nameparser.Locale` with -``languages=frozenset({"zh"})``; the ``zh`` pack makes none, so it -leaves ``Hon`` a title), and ``Guru`` under ``locales.NE``, each staying a title -inside a phrase; :ref:`choosing-languages` shows the first two, and the table of shipped -packs in :doc:`locales` the third. +title that its file leaves off until the language is chosen. Each +stays a title inside a phrase: + +- **Lady** is a given name under a Spanish choice (``locales.ES``). +- **Hon** is a given name under a Chinese choice of languages (a + :class:`~nameparser.Locale` with ``languages=frozenset({"zh"})``); + the ``zh`` pack makes no choice, so it leaves ``Hon`` a title. +- **Guru** is a given name under ``locales.NE``. + +:ref:`choosing-languages` shows the first two, and the table of +shipped packs in :doc:`locales` the third. Where such a word opens the name and a listed phrase could have held it, the parse reports a ``title-or-name`` ambiguity, its alternative @@ -1093,8 +1149,7 @@ word out asserted (``Van`` standing alone is still a given name): 'van Gogh' For particles the default runs the other way from credentials: a -particle that is not borne as a given name holds no ``given`` reading, -which is where ``mc`` and ``ste`` were moved (:issue:`360`). +particle that is not borne as a given name holds no ``given`` reading. .. _connectives-also-initials: @@ -1203,7 +1258,8 @@ shape. Arabic-script ``عبد`` lists the names of God and the devotional names it completes, so the pair is one name wherever it stands. The Latin spellings name no word after them and complete with any, ``abdul`` only in a name of four -words or more, titles and suffixes not counted (``long_names_only``), +words or more, a title, a suffix, a nickname or a maiden name not +counted (``long_names_only``), its three-word names being split both ways by the people who write them: @@ -1222,11 +1278,15 @@ with the pair as the family, state ``abdul``'s reading without .. doctest:: - >>> lex = (Lexicon.default().remove("abdul", kind="bound_given") - ... .add("abdul", kind="bound_given", completes_any=True)) + >>> lex = Lexicon.default().add("abdul", kind="bound_given", + ... long_names_only=False) >>> Parser(lexicon=lex).parse("Tariq Abdul Aziz").family 'Abdul Aziz' +``locales.MS`` does not make this change; build the pack's parser on a +base holding the edit (``parser_for(locales.MS, +base=Parser(lexicon=lex))``). + A ``bound_second`` reading (3.2) is the other end of such a pair: the word written second, which joins the word before it. Arabic script writes many given names as a word and ``الدين`` ("of the faith") or diff --git a/docs/getting-started.rst b/docs/getting-started.rst index b536c6db3..8f6b29add 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -147,7 +147,8 @@ 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`). +the name, as a bibliography writes them; where a Russian-style +patronymic stands (:ref:`suggest-evidence`). ``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 diff --git a/docs/index.rst b/docs/index.rst index 98431d675..63001637d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -22,8 +22,10 @@ New here? :doc:`getting-started` takes you through the three steps most people need: - **Parse one name** into its fields, as above. -- **Have a list of names from one source?** :doc:`suggest` reads the - order it is written in and returns a parser configured for it. +- **Have a list of names from one source?** :doc:`suggest` reads how + it is written (its order, patronymics, and family names written as + letters, in capitals or as two) and returns a parser configured for + it. - **Joining records from several sources?** :doc:`matching` groups the names and compares them field by field. diff --git a/docs/languages.rst b/docs/languages.rst index b79f50506..5b84ca017 100644 --- a/docs/languages.rst +++ b/docs/languages.rst @@ -56,8 +56,10 @@ What the default reads and what waits for a pack The default reads the doctorates before the name (``MUDr.``, ``JUDr.``, ``PhDr.``, ``RNDr.`` and the rest), ``Mgr.``, which it -lists as Monsignor, and the degrees after it, ``DiS.``, ``DrSc.`` and -``ArtD.``. It cannot read the other words, each of which +lists as Monsignor, and the degrees after it, ``DrSc.`` and ``ArtD.``, +and ``DiS.`` after a comma (``Jan Novák, DiS.``); ``DiS.``, a surname +too, ending a name without a comma stays a name word. It cannot read +the other words, each of which another reading claims: - ``ml.`` is also a pair of initials. @@ -197,10 +199,11 @@ The four packs read two family names (``two_family_names``, see name in its own view (``surname1`` ``Pešová``, ``surname2`` ``Řehořová``). -Two given names pay for it: with no given-name list in any of the four +Two given names pay for it: no given-name list ships for these four languages to keep a given name out of the family (none is published for the whole Czech or Slovak population, and none has been looked for -in Slovenian or Croatian), ``Petr Pavel Novák`` reads family ``Pavel +in Slovenian or Croatian), so ``Petr Pavel +Novák`` reads family ``Pavel Novák``. A family comma keeps both as the default reads them, and an initial written between the given name and the surname stays the middle name: @@ -380,7 +383,7 @@ Two family names under ``es`` ``es`` reads a name as Spanish names are written, with two family names, the father's and then the mother's (``two_family_names``, see -:ref:`two-family-names`). It carries a list of 1,000 Spanish given +:ref:`two-family-names`). It carries a list of about 1,000 Spanish given names, the ones INE's 2025 census tables count as given names in at least 90% of their uses, so a given name standing before the family stays out of it: @@ -592,8 +595,8 @@ under ``pt_br``, while Portuguese inventors gain under ``pt_pt`` (57.6% → 66.1%). Most of the Brazilian names it breaks hold a second surname among the given names (``Eder Ferreira`` / ``Rangel``, read family ``Ferreira Rangel``). So choose ``pt_br`` or ``pt_pt``, by -country, for names whose family part is written whole, and keep ``pt`` for data -filed with a single surname as the family name. +country, for names whose family part is written whole, and keep ``pt`` for +Brazilian data filed with a single surname as the family name. Among the UK company register's filers the switch gains for Portuguese (59.2% → 62.8%) and Brazilian (53.7% → 62.9%) nationals. @@ -950,8 +953,8 @@ Initials :meth:`~nameparser.ParsedName.initials`, with its default ``spec``, gives an empty string for a name in Thai script (a ``spec`` of your -own keeps its literal characters), as it does for Chinese, Japanese -and Korean ones, +own keeps its literal characters), as it does for Chinese, Japanese, +Korean, Lao, Burmese and Arabic-script ones, since Thai does not write names as initials. A word in another script beside it still gives its own: @@ -1581,10 +1584,10 @@ every name, so keep it to a list that is wholly Burmese: >>> burmese.parse("Jane Doe, PA").suffix 'PA' -On the committed test corpora and ClinicalTrials.gov's officials and -site contacts, 660,410 distinct names that are mostly not Burmese, the -strict choice reads 58,776 differently from the plain pack in their -fields, 8.9% of them (measured 2026-11-19, :issue:`1483`). +On some 660,000 distinct names that are mostly not Burmese, the strict +choice reads about one in eleven differently from the plain pack in +their fields (:issue:`1483`; the measurement is in the source +repository's ``docs/design/decisions/vocabulary-collisions.md``). What the pack leaves as it is ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1607,7 +1610,8 @@ When not to use it The plain pack reads names that are not Burmese as the default does, save two words, ``U`` and ``Daw``, read as titles wherever a title is read (``Daw Smith`` gives title ``Daw``), and ``U`` as a letter of a -word joined by full stops. ``U`` is the honorific however it is +word joined by full stops (``J.U. Smith`` gives title ``J.U.``). ``U`` +is the honorific however it is written, so an initial ``U.`` can be read as the title. ``Smith, U.`` and ``Dr. U. Smith`` give no given name, though ``John U. Smith`` and ``Smith, John U.`` keep it an initial: @@ -1620,9 +1624,12 @@ U.`` keep it an initial: A Korean name written with no comma and opening with the surname ``U`` reads ``U`` as the title under the pack (``U Minjun``), where ``U, -Minjun`` keeps it as the family name. Chosen strictly, the pack also -reads a run of initials holding ``U`` as the title (``U.S. Grant`` -gives title ``U.S.``, family ``Grant``). Keep the pack to a parser of +Minjun`` keeps it as the family name. Chosen strictly, the pack drops +English's readings of runs opening with ``U``, the titles ``U.S.`` and +``U.K.`` and credentials such as ``U.S.A.``, so they read as the title +as an unlisted run does (``U.S. Grant`` gives title ``U.S.``, +family ``Grant``), and the title after one no longer joins it +(``U.S. Senator John Smith`` gives title ``U.S.``, given ``Senator``). Keep the pack to a parser of its own for the Burmese names in your data. .. _malay-names: @@ -1688,23 +1695,24 @@ given name behind the surname ``Tan`` reads as the phrase (``Tan Sri Wahyuni`` gives title ``Tan Sri``), and so does either word behind a style (``Hon. Tan Ah Kow`` gives title ``Hon. Tan``). -On Malaysia's election candidates, 3,077 distinct names written in -capitals, the default reads an honour as the title in 174 names -(``DATO'`` 103, ``DATUK`` 69, ``DATIN`` 1, ``HAJAH`` 1); the word behind -it is then the given name, which for a qualifier of the honour (``DATO' -SRI``, ``DATUK SERI``) or a title the default does not read (``HAJI``, -``CIKGU``) is still not the person's. The pack reads 248 differently -from the default. 197 of them read a title the default read as the -given name: ``USTAZ`` 72, ``CIKGU`` 45, ``HAJI`` 37, ``DATO`` 29, -``TAN SRI`` 6, ``USTAZAH`` 5, ``CIK`` 2 and ``PUAN SRI`` 1. The two -``CIK`` are ``Cikgu`` written in two words (``CIK GU``), and read given -``GU``. The other 51 read the same and add a report: 36 Chinese names -written family first with ``TAN``, 14 ``DATO' SRI`` and 1 ``DATO' -TAN``. Among the records -ORCID, PatentsView and Companies House hold of Malaysians, Indonesians -and Singaporeans, each split into boxes by the person or the filer, the -share whose boxes the parse matches moves by at most 0.1 point under -the pack (measured 2026-11-21, :issue:`1179`, :issue:`1180`). +On Malaysia's election candidates, some 3,000 names written in +capitals, the default reads an honour (``DATO'``, ``DATUK``) as the title +in about 170 of them; the word behind it is then the given name, which +for a qualifier of the honour (``DATO' SRI``, ``DATUK SERI``) or a title +the default does not read (``HAJI``, ``CIKGU``) is still not the +person's. The pack reads about 250 differently from the default: + +- **About 200 read a title the default read as the given name**, most + of them ``USTAZ``, ``CIKGU``, ``HAJI`` and ``DATO``. ``Cikgu`` written + in two words (``CIK GU``) reads given ``GU``. +- **The rest read the same and add a report**, most of them Chinese + names written family first with ``TAN``. + +Among the records ORCID, PatentsView and Companies House hold of +Malaysians, Indonesians and Singaporeans, each split into boxes by the +person or the filer, the share whose boxes the parse matches moves by +at most a tenth of a point under the pack (:issue:`1179`, +:issue:`1180`). What the pack leaves as it is ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1724,8 +1732,9 @@ stay name words (``Datuk Seri Anwar Ibrahim`` gives title ``Datuk``, given ``Seri``), and so do ``YB``, ``YM`` and ``YA`` and the police ranks (:issue:`1180`). ``Haji`` inside the father's name is a name word (``Ahmad bin Haji Abdullah`` gives family ``bin Haji Abdullah``). -``bt``, written short for ``binti``, stays a credential (Baronet), as -by default; :doc:`customize` shows how to remove it. +``bt``, written short for ``binti``, can still be read as a credential +(Baronet), as by default (``Nur Aina bt Rosli``); :ref:`malay-bt` +shows how to remove it. Plain, not strict ~~~~~~~~~~~~~~~~~ @@ -1733,7 +1742,8 @@ Plain, not strict Choose the pack plainly. Malaysian lists mix Malay, Chinese and Indian names with English and Arabic titles, and a strict choice of ``ms`` reads only the words of ``ms`` and those shared by every language, so -it drops ``Abdul``'s join and English titles such as ``Sir``: it matches the boxes of 76.16% of ORCID's -Malaysian holders, against 76.72% for the plain choice (measured -2026-11-19). +it drops ``Abdul``'s join and English titles such as ``Sir``: on +ORCID's Malaysian holders it matches about half a point fewer names' +boxes than the plain choice (the measurement is in the source +repository's ``docs/design/decisions/salutation-titles.md``). diff --git a/docs/locales.rst b/docs/locales.rst index 9cd431410..282f32752 100644 --- a/docs/locales.rst +++ b/docs/locales.rst @@ -97,7 +97,7 @@ order and the Korean split, can each be turned off Using a pack ------------ -Most packs carry one of two things: a *structural* rule, like reordering +A pack carries one or both of two things: a *structural* rule, like reordering a patronymic, that vocabulary alone can't express, or words that are right in one language and wrong as a default (`Packs that choose a language`_). Two packs, ``zh`` and ``ja``, also divide a name written @@ -128,7 +128,7 @@ with different parsers rather than enabling a pack over all of it. What a pack costs ~~~~~~~~~~~~~~~~~ -Each pack declares a surface, the names it may read differently from +Each pack declares a surface: the names it may read differently from the default. A rule's surface is a shape — a patronymic ending or marker for ``ru`` and ``tr_az``, a script for ``zh`` and ``ja``, three name words or more for the packs that read two family names — and a choice of languages @@ -139,7 +139,10 @@ can act on a name from a tradition it was not written for. A broad shape covers much: - ``es``, ``es_ar``, ``cs``, ``sk``, ``hr``, ``sl``, ``pt_br`` and - ``pt_pt`` may read any name of three words differently. + ``pt_pt`` may read any name of three name words or more differently; + ``cs`` also any name holding ``Ing`` as a word (``Ing Lim``). +- ``ne`` may read any name holding two single letters in a row + differently (``initials_as_family``), whatever its language. - ``vi``, whose name order is its shape, may read any name differently: the order moves every name a family comma does not fix, and its titles and removed readings reach the comma names too. @@ -172,6 +175,25 @@ shape covers much: ``Abramovich``. This is the trade the pack asks you to make, and it is why packs are opt-in rather than automatic. +Checking a pack against your data +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Parse a sample of your names under the default and under the pack, and +read the names the two read differently before you choose it: + +.. doctest:: + + >>> spanish_check = parser_for(locales.ES) + >>> sample = ["Lucía Ferrando Quintela", "Mark Oduya Bell", "Ana Ruiz"] + >>> [(text, parse(text).family, spanish_check.parse(text).family) + ... for text in sample + ... if parse(text).as_dict() != spanish_check.parse(text).as_dict()] + [('Lucía Ferrando Quintela', 'Quintela', 'Ferrando Quintela'), ('Mark Oduya Bell', 'Bell', 'Oduya Bell')] + +Here the pack mends the Spanish name and costs the English one its +middle name. For a list whose convention you do not know, ask +:doc:`suggest` first. + Every shipped pack is held to the same test: over the test corpus and the pack's own example names, every name it reads differently from the default is one its declared surface covers. The contract is written @@ -328,7 +350,9 @@ says which parts each pack is made of. * - ``nl`` - Dutch: family names opening with ``ten`` - Chooses ``nl``, which reads ``ten`` inside a name as the particle - opening the family name. See :ref:`dutch-particles`. + opening the family name and drops ``VD``'s credential reading + (``John Smith VD`` gives family ``VD``). See + :ref:`dutch-particles`. - ``Jan ten Brink`` → family ``ten Brink`` * - ``pt`` - Portuguese, from any country @@ -450,8 +474,10 @@ says what it can change: - ``segment_scripts``, for the script its list covers - a surname list -``vi`` is the pack whose own fragment takes readings out rather than -adding them (`What a pack's lexicon may hold`_). +``vi`` and ``cs`` are the packs whose own fragments take readings out +rather than adding them: ``cs`` removes ``Ing``'s given-name reading, +``vi`` the particle, conjunction and credential readings of Vietnamese +syllables (`What a pack's lexicon may hold`_). See :ref:`config-containers` for how that split (language vocabulary vs. behavior) is drawn. Which half a new naming rule belongs in is @@ -736,6 +762,8 @@ settle: - **Under pt_br,** a written S.B. degree reads as Sobrinho (``Howard Gordon, MD SB`` fills ``generation`` with ``SB``). +.. _stacking-packs: + Stacking packs -------------- @@ -751,7 +779,9 @@ How each part combines: - **Languages union** into one choice, with the base's own, applied first (see `Choosing languages`_), so the order the packs are given - in does not change it. + in does not change it. Where two chosen languages read one word + differently, both readings stay and the name around the word + decides (`What a choice costs`_). - **Lexicons join in order**: the packs' lexicons in the order given, then the base's, each applied after the choice, so where two disagree the later wins and the base's own words win over every @@ -930,7 +960,7 @@ A tag selects its own file and those of the languages it belongs to, never the other way: ``pt-BR`` reads ``pt.toml`` too, and ``pt`` leaves the Brazilian words alone. No other table of related languages is read, so a caller with Malay and Indonesian names chooses ``ms`` -and ``id``. +(``locales.MS``) and ``id``. Tags are compared without regard to case, and a tag is checked in one of four ways: @@ -1039,8 +1069,10 @@ of the others, and a strict one reads each as a name word: >>> korean.parse("Kim Min Ae").family 'Ae' -Chinese ``De`` is the same case under strict ``zh``: ``De Xu`` reads -given ``De``, family ``Xu``. +Chinese ``De`` is the same case under a strict choice of the language +``zh`` (a :class:`~nameparser.Locale` with ``languages=frozenset({"zh"})``, +not ``locales.ZH``, which chooses no language): ``De Xu`` reads given +``De``, family ``Xu``. What a strict choice keeps ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1132,7 +1164,10 @@ Creating your own Locale You don't need to touch nameparser's registry to use your own pack — :class:`~nameparser.Locale` is a plain, constructible value: -``Locale(code=..., lexicon=..., policy=PolicyPatch(...))``. A +``Locale(code=..., lexicon=..., policy=PolicyPatch(...), +languages=frozenset({...}))``, ``languages`` choosing the vocabulary +files of the languages it names (`Which tags are accepted`_; a word of +a language with no file goes in the pack's own ``lexicon``). A :class:`~nameparser.PolicyPatch` is a :class:`~nameparser.Policy`-shaped patch: every field defaults to :data:`~nameparser.UNSET` (leave it alone) instead of to a concrete value, so a pack only ever states what @@ -1179,7 +1214,9 @@ right, validated on its own, and it may hold any of these: - **A list and no reading.** ``zh`` is the shipped worked example: its ``Lexicon(surnames=...)`` holds a list and no reading. - **Removals.** A fragment's ``remove`` calls apply after the choice - too, as a caller's own do: ``vi``'s fragment, + too, as a caller's own do. ``cs``'s, + ``Lexicon.empty().remove("ing", kind="given")``, makes ``Ing`` a + title opening a name (``Ing Wei Lim`` gives title ``Ing``); ``vi``'s, ``Lexicon.empty().remove("van", ..., kind="particle")`` with a call each for ``kind="conjunction"`` and ``kind="credential"``, takes out those readings of the syllables it lists, and only those (``mac`` diff --git a/docs/matching.rst b/docs/matching.rst index 4d383102c..4f57b843b 100644 --- a/docs/matching.rst +++ b/docs/matching.rst @@ -493,7 +493,8 @@ read as the hyphen-minus wherever the parser reads the name alike, which it does not for a credential joined by one (``MD‐PhD``). A letter a keyboard lacks, written as one types it or as its standard transcription, reads ``folded`` too (``Łukasz`` / ``Lukasz``, -``Müller`` / ``Mueller``). +``Müller`` / ``Mueller``). A zero-width non-joiner or joiner typed at +a word's edge is dropped too. The fold drops accents only from Latin, Greek and Cyrillic letters; a mark on another script's letter, such as a Devanagari vowel sign, is @@ -510,6 +511,9 @@ In a family or maiden name, spaces and hyphens are set aside (``Jane Doe (née J.-P.)`` / ``Jane Doe (née J. P.)``), and a family or maiden name of initials alone on both sides reads no other leniency, so ``J. P., Ann`` / ``P. J., Ann`` and ``J., Ann`` / ``J. P., Ann`` conflict. +A letter in a script that writes no initials (Han, Hangul, kana, Thai, +Lao, Burmese, Arabic) is read as a word, not an initial, so ``ສ. ໃຈດີ`` +/ ``ສົມຊາຍ ໃຈດີ`` conflicts. Initials written joined into one word agree with the same letters written apart as ``joined`` (``JP Smith`` / ``J.-P. Smith``). diff --git a/docs/migrate.rst b/docs/migrate.rst index d70249d4d..da130572c 100644 --- a/docs/migrate.rst +++ b/docs/migrate.rst @@ -47,6 +47,10 @@ Which part is yours the attribute map and the ``Constants`` tables are not yours * - compares names with ``==`` - :ref:`migrate-comparison` + * - is on 3.0 or 3.1 already + - :ref:`migrate-3-1` and :ref:`migrate-3-2` for the readings that + moved; the pickles table (:ref:`migrate-pickles`) for what loads + where * - pickles parsers, lexicons or parsed names - :ref:`migrate-pickles` * - has tests whose expected readings changed after upgrading @@ -64,11 +68,11 @@ Upgrade steps 3. Search your code for those: the ``grep`` under :ref:`migrate-finding-sites` finds the names, and a read of a ``Lexicon`` set field has to be found by hand. -4. If you keep pickles, read :ref:`migrate-pickles` before leaving 3.0 - behind: a ``Lexicon``, ``Parser`` or locale pack pickled by 2.7 or - 2.8 loads under 3.0 and not under 3.1, so pickle it again under 3.0. - That load raises a ``DeprecationWarning``, so it stops a run that - turns warnings into errors. +4. If you keep pickles of a ``Lexicon``, ``Parser`` or locale pack + written by 2.7 or 2.8, install 3.0 first, load them and pickle them + again there, then upgrade further: 3.1 and 3.2 refuse them + (:ref:`migrate-pickles`). That load raises a ``DeprecationWarning``, + so it stops a run that turns warnings into errors. 5. Upgrade, and compare your fixtures with the lists under :ref:`migrate-behavior` for the releases between your old version and the new one. @@ -687,56 +691,81 @@ that wrote it: .. list-table:: :header-rows: 1 - :widths: 22 14 18 18 28 + :widths: 20 11 15 15 15 24 * - Pickled object - Written by - Under 3.0 - Under 3.1 + - Under 3.2 - What to do * - ``HumanName`` or ``Constants`` - 1.x or 2.x - does not load - does not load + - does not load - Store ``parse(text).as_dict()`` or the original string; pickle the ``Parser`` in place of a ``Constants`` * - ``Lexicon``, ``Parser`` or locale pack - 2.6 or earlier - ``ValueError`` - ``ValueError`` + - ``ValueError`` - Build the object again * - ``Lexicon``, ``Parser`` or locale pack - 2.7 or 2.8 - loads, with a ``DeprecationWarning``, unless edited in a way no readings express (below) - ``ValueError`` + - ``ValueError`` - Load it under 3.0 and pickle it again there * - ``Policy`` - 2.5 or earlier - ``ValueError`` - ``ValueError`` + - ``ValueError`` - Build the object again * - ``Policy`` - 2.6 to 2.8 - loads - loads - - Nothing - * - ``Policy``, ``PolicyPatch``, and anything holding a ``Lexicon`` - - 3.1 - - ``ValueError`` - loads - - Keep a 3.0 copy while 3.0 must read it (below) + - Nothing * - ``ParsedName`` - 2.x - loads, rendering as 2.x did - loads, rendering as 2.x did + - loads, rendering as 2.x did - Parse the text again to render it as written * - any of the rows above but the first - 3.0 - loads - loads, keeping 3.0's vocabulary, save a caller's word written with a tatweel (below) - - Build a new ``Parser()`` for 3.1's readings + - loads, as under 3.1, save also a caller's word added with a + zero-width non-joiner or joiner at its edge (below) + - Build a new ``Parser()`` for the newer readings + * - ``Policy``, ``PolicyPatch``, and anything holding a ``Lexicon`` + - 3.1 + - ``ValueError`` + - loads + - loads, keeping 3.1's vocabulary, save a caller's word added with a + zero-width non-joiner or joiner at its edge (below) + - Keep a 3.0 copy while 3.0 must read it; build a new + ``Parser()`` for 3.2's readings + * - ``Lexicon``, ``Parser`` (a ``parser_for`` one too) or matcher + - 3.2 + - ``ValueError`` (a matcher: ``ModuleNotFoundError``, 3.0 having + none) + - ``ValueError`` + - loads + - Keep a 3.1 copy while 3.1 must read it (below) + * - ``Policy``, ``PolicyPatch`` or locale pack + - 3.2 + - ``ValueError`` + - loads + - loads + - Nothing, unless 3.0 must read it A ``HumanName`` or a ``Constants`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -770,9 +799,10 @@ this release's; build a new ``Parser()`` for that. Between 3.0 and 3.1 ~~~~~~~~~~~~~~~~~~~ -A pickle keeps the vocabulary of the release that wrote it. A -``Parser`` or locale pack pickled by 3.0 loads under 3.1 and reads and -matches as 3.0 did: it reads ``Md. Rahim Uddin`` with the title +A pickle keeps the vocabulary of the release that wrote it, while what +a later release changed in the parser itself reaches it. A ``Parser`` +or locale pack pickled by 3.0 loads under 3.1 with 3.0's vocabulary: +it reads ``Md. Rahim Uddin`` with the title ``Md.``, does not split the Thai title off ``นายสมชาย``, finds no familiar form between ``Bill`` and ``William``, and a pickled ``locales.NE`` lacks the ``initials_as_family`` 3.1 gives it. Build the @@ -790,6 +820,30 @@ The other way, 3.0.x refuses with ``ValueError`` anything holding a ``Script.CYRILLIC`` is new. A ``ParsedName`` or ``Ambiguity`` loads both ways. +Between 3.1 and 3.2 +~~~~~~~~~~~~~~~~~~~ + +Anything 3.0 or 3.1 pickled that 3.1 loads, loads under 3.2, save a +``Lexicon`` holding a +word a caller added with a zero-width non-joiner or joiner at its edge, +or a ``Parser`` holding one, which raises ``ValueError``: 3.2 drops the +character when it normalizes a word (:issue:`1335`), so build it again +with the same ``add()`` calls. + +A loaded pickle keeps 3.1's vocabulary: +a ``Parser`` pickled by 3.1 reads ``Imam Taufik Sasongko`` with the +title ``Imam`` and ``Datuk Ahmad bin Ali`` with the given name +``Datuk``. What 3.2 changed in the parser itself reaches it all the +same (``Jane Smith, MRes`` reads the suffix, ``Dr/ Jane Smith`` the +title). Build the object again under 3.2 to read the 3.2 way. + +The other way, 3.1 refuses with ``ValueError`` a ``Lexicon`` pickled by +3.2, and so a ``Parser``, one ``parser_for`` built included, and a +matcher (``Parser.matching()``), each of which holds one: 3.2's +vocabulary has a reading kind, ``alias_marker``, that 3.1 does not +know. A ``Policy``, a ``PolicyPatch``, a locale pack, a ``ParsedName`` +and an ``Ambiguity`` pickled by 3.2 load under 3.1. + Pickles between 2.x releases ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -909,9 +963,10 @@ list, with reasoning, is in each release's section of ``Md``, Thai names, credentials after a comma - :ref:`migrate-3-1` * - 3.2 - - Dutch ``Oude``, Malaysian ``a/l``, ``a/p`` and ``anak``, - religious titles before a name, Korean ``Ra``, Malay and Dutch - ``Ab`` + - Titles and jobs after a comma, religious titles, ``Ra`` and ``Ab``, + credentials (mixed case, ``MD`` inside a name written in one + case, ``ud``), particles (``Oude``, ``aus``, ``Vanden``, + ``a/l``), Arabic-script names, two family names in more packs - :ref:`migrate-3-2` Each entry says what it compares with. The lists of readings through @@ -2191,10 +2246,10 @@ To keep the 3.1 reading, turn the switch off on top of the pack: >>> as_31.parse("Ana Souza Lima").family 'Lima' -A ``locales.PT_BR``, or a parser built from it, pickled by 3.1 still -loads, and reads as 3.1's pack did: a pickle holds the pack's values, -not its name. Build the parser again from ``locales.PT_BR`` to read two -family names. +A ``locales.PT_BR``, or a parser built from it, pickled by 3.1 keeps +the 3.1 pack's values, which leave ``two_family_names`` off: a pickle +holds the pack's values, not its name (:ref:`migrate-pickles`). Build the parser again +from ``locales.PT_BR`` to read two family names. Two family names under locales.HR and locales.SL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -2217,8 +2272,8 @@ both as 3.1 read them: 'Jože' To keep the 3.1 reading, turn the switch off on top of the pack, as for -``locales.PT_BR`` above. A pack or parser pickled by 3.1 reads as 3.1's -pack did. +``locales.PT_BR`` above. A pack or parser pickled by 3.1 keeps the 3.1 +pack's values, which leave ``two_family_names`` off. Malaysian a/l, a/p and anak ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -2304,10 +2359,14 @@ job's as ``kind="occupation"`` and a qualifier's as ``kind="modifier"``: .. doctest:: - >>> as_31 = Parser(lexicon=Lexicon.default().remove("student", kind="occupation")) - >>> as_31.parse("Student Mary Jones").given + >>> student_as_name = Parser( + ... lexicon=Lexicon.default().remove("student", kind="occupation")) + >>> student_as_name.parse("Student Mary Jones").given 'Student' +Each word is removed on its own: ``bachelor`` is an occupation and +``medical`` a modifier. + ud inside a compound name ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -2384,7 +2443,7 @@ ranks ``اللواء`` (major general), ``المستشار`` (counsellor) and the given name. :meth:`~nameparser.ParsedName.initials` gives nothing for a word in Arabic script, where 1.4 through 3.1 gave its first letter, and the name match reads an Arabic letter with a full stop as -a word, so ``م. علي`` no longer matches ``محمد علي``. There is no +a word, so ``ع. حسن`` no longer matches ``علي حسن``. There is no setting to restore those initials; a caller wanting a letter per word takes it from the fields: @@ -2431,13 +2490,16 @@ bear them as names (``locales.MS`` reads ``Haji`` as a title, >>> parse("Hafiz Ahmed Khan").given 'Hafiz' -To read one of the four as a name, remove its reading: +To read them as names, remove their readings: ``qari`` and +``moulana`` are religious titles, ``alhaj`` and ``alhajj`` styles: .. doctest:: - >>> as_31 = Parser(lexicon=Lexicon.default().remove("qari", kind="religious")) - >>> as_31.parse("Qari Ahmed Khan").given - 'Qari' + >>> as_31 = Parser(lexicon=Lexicon.default() + ... .remove("qari", "moulana", kind="religious") + ... .remove("alhaj", "alhajj", kind="style")) + >>> as_31.parse("Qari Ahmed Khan").given, as_31.parse("Alhaj Ahmed Khan").given + ('Qari', 'Alhaj') Imam, Timi, Sheriff and Effendi as given names ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -2458,14 +2520,27 @@ In a title phrase they stay titles (``Chief Imam``, ``Grand Imam``, >>> parse("Chief Imam Musa Bello").title 'Chief Imam' +English names move too: ``Sheriff John Smith`` gives the given name +``Sheriff``, reporting ``title-or-name``, and ``John Smith, Sheriff`` +reverses the name: + +.. doctest:: + + >>> parse("Sheriff John Smith").given + 'Sheriff' + >>> parse("John Smith, Sheriff").family + 'John Smith' + To read one of the four as a title wherever it opens a name, remove its given reading: .. doctest:: - >>> as_31 = Parser(lexicon=Lexicon.default().remove("imam", kind="given")) + >>> as_31 = Parser(lexicon=Lexicon.default().remove("imam", "sheriff", kind="given")) >>> as_31.parse("Imam Taufik Sasongko").title 'Imam' + >>> as_31.parse("Sheriff John Smith").title + 'Sheriff' Alias markers: @ and urf ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -2487,6 +2562,22 @@ word, as before: >>> parse("Rahim Osman@Usman").family 'Osman@Usman' +With no particle after it the alias takes the rest of the name, up to +any post-nominals or a comma, so a +one-word alias before the family name takes the family name with it, +and in ``Ravi Kumar urf Raju`` the word before ``urf`` is now the +family name: + +.. doctest:: + + >>> parse("Rahim @ Jaki Osman").family + '' + >>> parse("Ravi Kumar urf Raju").family + 'Kumar' + +``alias`` and ``aka`` are read so only where you add them or choose +English (:ref:`alias-markers`). + To read the two as name words again, remove their readings: .. doctest:: @@ -2535,13 +2626,15 @@ Ra as a Korean name ``Ra``, a Korean family name and given name, reads as a name where it ends or opens one, where 1.4.0 through 3.1.0 read it as the credential RA ending a name of three words (2.0 through 3.1 of two too) and the -title RA (Rechtsanwalt) opening one. Written ``RA`` in a name of mixed -case and ending it after a comma, or written ``R.A.``, it is still the -credential. ``Ra`` alone after a family comma (``Kim, Ra``), ``RA`` -opening the part after a family comma in a name written wholly in -capitals (``KING, RA``), ``RA`` in the given part after a family comma -ahead of a name word (``Smith, RA John``) and ``RA`` opening a German -name are now the given name: +title RA (Rechtsanwalt) opening one. + +- **Still the credential:** ``RA`` in a name of mixed case ending it + after a comma, and ``R.A.``. +- **Now the given name:** ``Ra`` alone after a family comma (``Kim, + Ra``); ``RA`` opening the part after a family comma in a name written + wholly in capitals (``KING, RA``); ``RA`` in the given part after a + family comma ahead of a name word (``Smith, RA John``); and ``RA`` + opening a German name. .. doctest:: @@ -2594,3 +2687,309 @@ readings and add the rank: ... .add("ab", kind="military")) >>> ab_31.parse("Ab Jansen").title 'Ab' + +A title or suffix typed with a joiner at its edge +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A zero-width non-joiner or joiner (U+200C, U+200D) typed at the edge +of a word no longer hides it from the vocabulary, so a title or suffix typed with one reads +as the title or suffix, where 1.4 through 3.1 read it as a name word. +The field keeps the character, and one inside a word is still part of +its spelling: + +.. doctest:: + + >>> zwnj = parse("Dr‌ John Smith") + >>> zwnj.title == "Dr‌", zwnj.given + (True, 'John') + +A ``Lexicon`` pickled with a word added with one at its edge is refused +on load (:ref:`migrate-pickles`). + +The Cyrillic doctorate д-р ending a name +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``д-р`` ending a name is the credential, where 1.4 through 3.1 read +it as the family name. After a comma it is the credential too, where +3.1 read it as the title and 1.4 as the given name. In front of the +name it is still the title, as in 3.1 (1.4 read the given name): + +.. doctest:: + + >>> dr_uk = parse("Іван Петренко д-р") + >>> dr_uk.family, dr_uk.suffix + ('Петренко', 'д-р') + >>> parse("д-р Іван Петренко").title + 'д-р' + +To read it as 3.1 did, remove its credential reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove("д-р", kind="credential")) + >>> as_31.parse("Іван Петренко д-р").family + 'д-р' + +A credential in mixed case after a comma +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +An unlisted credential written in mixed case after a full name and a +comma (``MRes``, ``AuD``) is the suffix, where 1.4 through 3.1 read it +as the given name and the name before the comma as the family. The word +must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` +stay given names, and behind a one-word family it stays the given name: + +.. doctest:: + + >>> mres = parse("Jane Smith, MRes") + >>> mres.family, mres.suffix + ('Smith', 'MRes') + >>> parse("Smith, MRes").given + 'MRes' + +The rule reads the word's shape, not the vocabulary, so no vocabulary +edit turns it off; a given name written so after a two-word surname +reads as the credential (``García López, DAndre``). + +Czech and Slovak post-nominals +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``DiS.``, ``DrSc.`` and ``ArtD.`` are credentials: after a full name +and a comma ``DiS.`` is the suffix, where 1.4 through 3.1 read it as +the title. ``DiS.`` is also a surname, so written without the comma at +the end of a name of mixed case it stays a name word: + +.. doctest:: + + >>> dis = parse("Jan Novák, DiS.") + >>> dis.title, dis.suffix + ('', 'DiS.') + >>> parse("Jan Novák DiS.").family + 'DiS.' + +To read it as 3.1 did, remove its credential reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove("dis", kind="credential")) + >>> as_31.parse("Jan Novák, DiS.").title + 'DiS.' + +Medical degrees and Nigerian and Hong Kong honours +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``BCh``, ``BChir`` and ``BMBCh``, the Nigerian marks ``mni``, ``fwc``, +``fsi``, ``fnse``, ``psc`` and ``ndc``, and the Hong Kong and Singapore +honours ``GBM``, ``GBS``, ``SBS``, ``BBS`` and ``BBM`` are credentials. +After a one-word family name and a comma each reads as the suffix, +where 1.4 through 3.1 read it as the given name, and ending a name, +where they read it as the family name. After a full name and a comma +each is the suffix too, where 1.4 read the given name, as 3.1 did save +for those in capitals. ``BChir``, which is also a surname, stays a name +word after a one-word name and a comma and ending a name; after a full +name and a comma it is the suffix however it is written: + +.. doctest:: + + >>> bch = parse("Jane Doe, BCh") + >>> bch.family, bch.suffix + ('Doe', 'BCh') + >>> parse("Bello, MNI").suffix + 'MNI' + +A word in mixed case such as ``BCh`` is also read by the shape the +previous entry describes, so removing its credential reading leaves it +the suffix after a full name and a comma. + +German aus +^^^^^^^^^^ + +``aus`` is a family-name particle, so ``aus der Fünten`` is one family +name, where 1.4 through 3.1 read ``aus`` as a middle name. An ``Aus`` +written as a middle name before a surname is read into the family too: + +.. doctest:: + + >>> aus = parse("Karen aus der Fünten") + >>> aus.middle, aus.family + ('', 'aus der Fünten') + >>> parse("Kevin Aus Smith").family + 'Aus Smith' + +To read it as 3.1 did, remove its particle reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove("aus", kind="preposition")) + >>> as_31.parse("Karen aus der Fünten").middle + 'aus' + +Vanden +^^^^^^ + +``Vanden``, the Dutch and Flemish *van den* written as one word, is a +family-name particle as ``Vander`` is, where 1.4 through 3.1 read it as +a middle name: + +.. doctest:: + + >>> vanden = parse("Pieter Vanden Broeck") + >>> vanden.middle, vanden.family + ('', 'Vanden Broeck') + +To read it as 3.1 did, remove its particle reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove("vanden", kind="preposition")) + >>> as_31.parse("Pieter Vanden Broeck").middle + 'Vanden' + +Korean surnames 어 and 라 +^^^^^^^^^^^^^^^^^^^^^^^^^ + +어 and 라 are Korean surnames, so an unspaced name in hangul opening +with one is split, where 1.4 through 3.1 kept it whole: + +.. doctest:: + + >>> eo = parse("어수선") + >>> eo.family, eo.given + ('어', '수선') + +A foreign name written in hangul that opens with 라 is split too; to +keep such names whole, take the surname out of the list, as +:ref:`teaching-the-splitter-a-surname` shows. + +عبد with a final ى +^^^^^^^^^^^^^^^^^^ + +A word completing ``عبد`` written with a final ``ى``, as Egyptian names +write it, joins ``عبد`` as the same word written with ``ي`` does, where +1.4 through 3.1 read it as a name of its own: + +.. doctest:: + + >>> abd = parse("سامر عبد القوى") + >>> abd.family + 'عبد القوى' + +Malaysian honours +^^^^^^^^^^^^^^^^^ + +``Datuk``, ``Dato'``, ``Datin`` and ``Hajah`` opening a name are +titles, where 1.4 through 3.1 read them as the given name; the +``locales.MS`` pack reads more Malay titles (:ref:`malay-names`): + +.. doctest:: + + >>> datuk = parse("Datuk Ahmad bin Ali") + >>> datuk.title, datuk.given + ('Datuk', 'Ahmad') + +To read one as a name, remove its reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove("datuk", kind="nobility")) + >>> as_31.parse("Datuk Ahmad bin Ali").given + 'Datuk' + +Emeritus +^^^^^^^^ + +``Emeritus`` and ``Emerita`` after ``Professor`` or ``Prof``, or +before it, join the title, where 1.4 through 3.1 read ``Emeritus`` as +the given name. ``Emerita`` alone stays the given name, being a given +name too, and a title other than ``Professor`` before ``Emeritus`` +still leaves it a name word: + +.. doctest:: + + >>> emeritus = parse("Professor Emeritus John Smith") + >>> emeritus.title, emeritus.given + ('Professor Emeritus', 'John') + >>> parse("Bishop Emeritus John Smith").given + 'Emeritus' + +To read it as 3.1 did, remove its reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove( + ... "emeritus", "emerita", kind="modifier")) + >>> as_31.parse("Professor Emeritus John Smith").given + 'Emeritus' + +Military ranks written with a hyphen +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Thirteen ranks written with a hyphen, such as ``Vice-Admiral``, +``Major-General`` and ``Air Vice-Marshal``, are titles. 3.1 read +``Air Vice-Marshal Ann Reed`` with given ``Air``, and 1.4 with title +``Air``; a hyphenated rank not listed, such as ``Squadron-Leader``, +still reads as a name word: + +.. doctest:: + + >>> avm = parse("Air Vice-Marshal Ann Reed") + >>> avm.title, avm.given + ('Air Vice-Marshal', 'Ann') + +To read one as 3.1 did, remove its reading: + +.. doctest:: + + >>> as_31 = Parser(lexicon=Lexicon.default().remove("vice-marshal", kind="military")) + >>> as_31.parse("Air Vice-Marshal Ann Reed").given + 'Air' + +MD inside a name written in one case +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``MD`` with a name word after it, in a name written wholly in capitals +or wholly in lower case, is read as a name word (Muhammad written +short, as Malaysian names write it), where 2.4 through 3.1 read it as +the degree and took the name behind it into the suffix; 1.4 through +2.3 read it as 3.2 does. Both readings are reported as +``suffix-or-name``. In a name of mixed case the degree stays: + +.. doctest:: + + >>> siti = parse("SITI NORA MD YUSRI") + >>> siti.middle, siti.family, siti.suffix + ('NORA MD', 'YUSRI', '') + >>> parse("JOHN SMITH MD JONES").family + 'JONES' + >>> parse("John Smith MD Jones").suffix + 'MD Jones' + +Under a pack +^^^^^^^^^^^^ + +Code already using a pack sees these too; each pack's own section has +the rest: + +- **locales.CS** reads ``Bc`` and ``Ing`` as titles, so a name opening + with the given name Ing reads it as the title (``Ing Wei Lim`` gives + title ``Ing``, where 3.1 gave given ``Ing``, + :ref:`west-south-slavic-packs`). +- **locales.HI** reads ``Shri`` as a title (``Shri Ravi Kumar Verma`` + gives title ``Shri``, where 3.1 gave given ``Shri``). +- **locales.ES** and **locales.ES_AR**: their given-name lists were + rewritten, so a few words read the other way (``Juan Gerhard Lopez`` + gives family ``Gerhard Lopez`` under ``locales.ES_AR``, where 3.1 + gave middle ``Gerhard``, :ref:`argentine-spanish-pack`). + +.. doctest:: + + >>> parser_for(locales.CS).parse("Ing Wei Lim").title + 'Ing' + >>> parser_for(locales.HI).parse("Shri Ravi Kumar Verma").title + 'Shri' + +This list covers parses only. 3.2 also changed what +:meth:`Parser.suggest() ` suggests for some +lists, and a name vote (``NameEvidence.votes``) may now hold ``True`` +or ``False`` (:doc:`suggest`), and with ``familiar-form`` accepted the +name match finds more familiar forms (:doc:`matching`). diff --git a/docs/policy.rst b/docs/policy.rst index 7734dc398..8eccabac3 100644 --- a/docs/policy.rst +++ b/docs/policy.rst @@ -44,6 +44,25 @@ locale pack -- call :meth:`Policy.patched() >>> Policy().patched(PolicyPatch(middle_as_family=True)) Policy(middle_as_family=True) +On top of a locale pack +~~~~~~~~~~~~~~~~~~~~~~~ + +A field the pack leaves alone goes in the base parser's policy +(``parser_for(pack, base=Parser(policy=...))``). A field the pack sets +wins over the base's value (:ref:`stacking-packs`), so change it on the +parser the pack built: + +.. doctest:: + + >>> from nameparser import locales, parser_for + >>> czech = parser_for(locales.CS) + >>> czech.parse("Petr Pavel Novák").family + 'Pavel Novák' + >>> one_family = dataclasses.replace( + ... czech, policy=dataclasses.replace(czech.policy, two_family_names=False)) + >>> one_family.parse("Petr Pavel Novák").family + 'Novák' + The fields ---------- @@ -81,13 +100,11 @@ Order and name structure * - ``patronymic_rules`` - ``frozenset[PatronymicRule]`` - empty - - Reorders patronymic-shaped names via opt-in detectors — East - Slavic formal order (``EAST_SLAVIC``) or Turkic reversed order - (``TURKIC``) — but stands down under a declared - ``FAMILY_FIRST`` or ``FAMILY_FIRST_GIVEN_LAST`` ``name_order``. - Each rule also fills ``ParsedName.patronymic``. The ``ru`` and - ``tr_az`` rows of :ref:`shipped-packs` describe what each rule - detects. + - Reorders patronymic-shaped names, East Slavic (``EAST_SLAVIC``) + or Turkic (``TURKIC``); the reordering stands down under a + family-first ``name_order``, while ``ParsedName.patronymic`` is + still filled under ``FAMILY_FIRST``. See the ``ru`` and + ``tr_az`` rows of :ref:`shipped-packs`. * - ``middle_as_family`` - ``bool`` - ``False`` @@ -98,8 +115,8 @@ Order and name structure - ``False`` - Reads the last two name words as the family name (the first two under a family-first order), for data where people carry - two family names (Spain, most of Latin America). See - :ref:`two-family-names`. + two family names (Spain, most of Latin America); several packs + turn it on. See :ref:`two-family-names`. * - ``two_given_names`` - ``bool`` - ``False`` @@ -536,13 +553,27 @@ Turn on ``two_family_names`` when the people in your data carry two family names and write both together, after the given names (or first, under a family-first order), and only then: :ref:`What it costs ` 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`_). 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. +other names. + +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, Brazilian or from Portugal, its pack reads it +better (below). + +Packs that turn it on +~~~~~~~~~~~~~~~~~~~~~ + +- **locales.ES** and **locales.ES_AR**, with a list of about 1,000 and + about 5,000 given names that the switch leaves where they stand + (`Keeping a given name out of the family`_). +- **locales.PT_BR** and **locales.PT_PT**, with about 700 Portuguese + given names (:ref:`portuguese-two-family-names`). ``locales.PT`` + leaves the switch off. +- **locales.CS**, **locales.SK**, **locales.HR** and **locales.SL**, + with no list, so a second given name is read into the family too + (``Janez Jože Novak`` gives family ``Jože Novak`` under + ``locales.SL``, :ref:`west-south-slavic-packs`). 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 @@ -615,6 +646,9 @@ What it leaves alone Ana"`` needs no switch for its ``family``; the switch divides it into ``surname1`` and ``surname2``. - **Kaur and Singh** stay where they stand (see :ref:`kaur-singh`). +- **A lone particle and the word after it** under a family-first order + stay one surname (``Van Gogh Vincent`` gives ``surname1`` ``Van + Gogh`` and no ``surname2``). .. _two-family-names-cost: @@ -625,15 +659,15 @@ Turn it on only for data written this way: - **One family name behind two given names.** ``"Juan Carlos Pérez"`` loses ``Carlos`` to the family under the switch, and Argentine names, - which carry one family name, are mostly that shape. -- **Portuguese and Brazilian names.** They carry two family names too, - the mother's first, but the people who write them often give the last - one alone as their family name. Among the UK company register's - Portuguese filers the switch breaks about six names for every five it - mends, while among ORCID's researchers working or living in Portugal, - who split their own names into its boxes, it mends about twice what - it breaks: the two populations disagree, so measure the data you have - before switching it on. + which carry one family name, are mostly that shape, which is why + ``locales.ES_AR`` holds back about 5,000 given names. +- **Portuguese-speaking names from elsewhere.** For Brazil and + Portugal choose ``locales.PT_BR`` or ``locales.PT_PT``, whose + given-name list holds back most of the cost on names written whole, + though not on Brazilian data filed with a single surname as the + family name, where ``locales.PT`` is the better choice + (:ref:`portuguese-two-family-names`); Angolan and Mozambican names + lose under the switch even with the list. - **Filipino names.** They often carry a middle name between the given name and the family name, traditionally the mother's maiden surname, and their bearers count it with their given names: ``"Maria Santos @@ -641,7 +675,7 @@ Turn it on only for data written this way: Reyes``. Among ORCID's researchers in the Philippines it breaks about four names in ten and mends about one in a hundred. -The counts behind the last two are in +The counts behind these are in ``docs/design/decisions/O6-two-family-names.md``. What it reports @@ -660,8 +694,8 @@ listed in the lexicon's ``given_names`` where it stands, under any ``name_order``. The field is empty by default, so you supply the list for your data, -or choose ``locales.ES``, which turns the switch on and carries 1,000 -Spanish given names, a name written with ñ listed with n too +or choose ``locales.ES``, which turns the switch on and carries about +1,000 Spanish given names, a name written with ñ listed with n too (``locales.ES_AR``, for Argentine names, carries about 5,000; see :ref:`spanish-portuguese-titles`), or ``locales.PT_BR`` or ``locales.PT_PT``, which carry about 700 Portuguese ones, a name @@ -1013,6 +1047,16 @@ What it leaves alone >>> chan.family, chan.suffix ('CHAN', 'GBS, JP') +With ``two_family_names`` on too, a family of two words in capitals is +divided into ``surname1`` and ``surname2``: + +.. doctest:: + + >>> both = Parser(policy=Policy(capitals_as_family=True, two_family_names=True)) + >>> aksoy = both.parse("Ayla BURSALI AKSOY") + >>> aksoy.surname1, aksoy.surname2 + ('BURSALI', 'AKSOY') + .. _capitals-as-family-cost: What it costs @@ -1460,15 +1504,20 @@ way: All-caps words ~~~~~~~~~~~~~~ -``unlisted_caps_suffixes`` reads an unlisted word of two or more -capital letters, with no period in it, and since 2.7 one of capitals -joined by a hyphen or a slash (``PU-PH``, ``MS-OMPT``) with a part of -two or more letters. After a comma it also reads a word of letters in -mixed case that opens with two capitals or ends in one (``MRes``, -``DClinPsy``, ``AuD``), the way degrees are written. A capital only -inside a word (``LeBron``, ``McKenzie``) is a name's writing, and a word -in mixed case holding a hyphen (``Pharm-D``) is left alone, since given -names are written so (``Jay-R``). Its value is a +``unlisted_caps_suffixes`` reads an unlisted word in one of these +shapes: + +- **Two or more capital letters**, with no period in it. +- **Capitals joined by a hyphen or a slash** (``PU-PH``, ``MS-OMPT``) + with a part of two or more letters, since 2.7. +- **After a comma, mixed case** opening with two capitals or ending in + one (``MRes``, ``DClinPsy``, ``AuD``), the way degrees are written. + +A capital only inside a word (``LeBron``, ``McKenzie``) is a name's +writing, and a word in mixed case holding a hyphen (``Pharm-D``) is +left alone, since given names are written so (``Jay-R``). + +Its value is a :class:`~nameparser.CapsSuffixes`, because where capitals mean a credential depends on a second convention: many records write the SURNAME in capitals (``"Jean DUPONT"``, ``"DUPONT, Jean"``). @@ -1537,8 +1586,9 @@ capitals there, since a surname typed without its apostrophe ^^^^^^^ ``CapsSuffixes.OFF`` reads none of them and reports nothing, as 2.3 -did. It is the way to keep a given name written in capitals after a -two-word surname, which the default reads as a credential: +did. It is the way to keep a given name written in capitals, or in +mixed case opening with two capitals (``DAndre``), after a two-word +surname, which the default reads as a credential: .. doctest:: @@ -1548,6 +1598,8 @@ two-word surname, which the default reads as a credential: ... policy=Policy(unlisted_caps_suffixes=CapsSuffixes.OFF)) >>> caps_off.parse("García Márquez, GABRIEL").given 'GABRIEL' + >>> caps_off.parse("García López, DAndre").given + 'DAndre' .. _finding-missing-credentials: diff --git a/docs/shapes.rst b/docs/shapes.rst index 05bdac3ee..36f60d271 100644 --- a/docs/shapes.rst +++ b/docs/shapes.rst @@ -263,6 +263,10 @@ Each row's reading kind is what :meth:`Lexicon.words(kind=...) - the following word - ``given`` - ``abdul salam ahmed`` → ``abdul salam`` + * - Bound seconds (``bound_second``) + - the word before it + - ``given`` + - ``نور الدين سامر حداد`` → ``نور الدين`` * - Particles (``particle``) - the following surname - ``family`` @@ -410,9 +414,10 @@ Nicknames and maiden names A second name written after ``@`` or ``urf`` is a nickname too, as Malaysian and Indian lists write one; it runs to a patronymic particle -such as ``bin``, so the father's name after it stays the family name -(``alias`` and ``aka`` are read so only where you add them, see -:doc:`customize`): +such as ``bin``, so the father's name after it stays the family name; +with no particle it runs to the end of the name, so ``Rahim @ Jaki +Osman`` has no family name (``alias`` and ``aka`` are read so only +where you add them, see :ref:`alias-markers`): .. doctest:: @@ -615,7 +620,8 @@ The rule is bounded so it doesn't swallow ordinary names: ``Dr. Smith, John`` gives title ``Dr.``. - **A given name written short** is that given name: the traditional English abbreviations such as ``Chas.``, ``Geo.`` and - ``Wm.``, and the Filipino ``Ma.`` (María) and ``Jo.`` (José). + ``Wm.``, the Filipino ``Ma.`` (María) and ``Jo.`` (José), and the + Malay ``Ab.`` (Abdul). Each is a ``given`` reading carrying ``same_as``, the full name (``Lexicon.default().readings_of("chas")``); written bare, or anywhere else in the name, each word reads as it would unlisted. diff --git a/docs/suggest.rst b/docs/suggest.rst index 5058fc440..f047d029a 100644 --- a/docs/suggest.rst +++ b/docs/suggest.rst @@ -43,6 +43,11 @@ decided the same way, each by its own evidence: a patronymic rule (:ref:`suggest-two-family`). Every setting the votes do not decide keeps the base parser's value. +Check the names ``suggestion.disagreeing()`` lists +(:ref:`suggest-disagreeing`), then keep ``suggestion.patch`` with your +data and parse with it, rather than asking again +(:ref:`suggest-keeping`). + .. _suggest-how-many: How many names to give it @@ -78,16 +83,24 @@ order kept it as well at 2,000 names as at a few hundred. The other settings have no such floor. In a long list where almost no name carries their evidence, a handful of names can still decide -``patronymic_rules``, ``initials_as_family`` or ``capitals_as_family``: -five names written given name, patronymic, family name among a -thousand written family first without one decide the East Slavic rule, -and with it a given-first order for all of them. A sample of a few -hundred names makes that rarer. +``patronymic_rules``, ``initials_as_family``, ``capitals_as_family`` or +``two_family_names``: + +- Five names written given name, patronymic, family name, among a + thousand that carry no evidence, decide the East Slavic rule, and + under a family-first base a given-first order with it for all of + them. +- Three Spanish names of three words among a thousand of two words + decide ``two_family_names``: its share is taken of the names it would + change, so names it leaves alone never dilute it. -The one kind of list measured that more names kept helping is bylines -written initials first (``AM Hoy``) under a family-first base, where -so few names vote that a sample of a few hundred often decides nothing. -Where you know how such a list is written, set ``name_order`` yourself. +A sample of a few hundred names makes that rarer. + +Bylines written initials first (``AM Hoy``) under a family-first base +are the one kind of list measured that more names kept helping: so few +of them vote that a sample of a few hundred often decides nothing. +Where you know how such a list is written, set ``name_order`` +yourself. A list that mixes sources written differently works against itself. Split it by source and ask once for each. :ref:`suggest-limits` gives @@ -194,7 +207,7 @@ The report counts it as ``against`` and names it on its last line: .. _suggest-deciding: -When the list decides the order +When the list decides a setting ------------------------------- Each setting is decided only where enough names carry its evidence @@ -232,6 +245,9 @@ and enough of them agree: and more than the names voting against it - :ref:`suggest-two-family` +The order +~~~~~~~~~ + 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 vote: a tie, or two names against one, decides nothing. A name with no @@ -244,14 +260,12 @@ their own order. A list of 200 names or fewer needs no more than the two names it needs anyway; in a longer list where few names vote, it keeps a handful of stray votes (a surname that is also a given name, written first) from deciding the order for every name. Where this alone -holds the order back, the order evidence's note says so, and it says -so too where the votes it holds back are against the given-first order -a decided East Slavic rule sets. +holds the order back, the note under ``name_order`` says so. Two is the floor, not what a typical list needs. Two names decide a list only where no other name votes against them, and how many names a list needs before enough of them vote depends on what its names carry: -:ref:`suggest-limits` gives the sizes measured, from 5 names to 50. +:ref:`suggest-limits` gives the sizes measured, from 5 names to 200. When it suggests nothing ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -259,9 +273,25 @@ When it suggests nothing 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 listed surname, a given name that is rarely a -surname, or any other evidence on the order: +carries evidence, the patch is empty. The usual reasons: + +- **Too few names**: under five often decide nothing + (:ref:`suggest-how-many`). +- **Names that carry no evidence**, as in the list below + (:ref:`suggest-evidence`). +- **Names that do not vote**: a name with a comma states its own order, + and a name of one word shows none (:ref:`suggest-evidence`). +- **Bylines**: initials ending the names vote only where most of the + list's names end in them (:ref:`suggest-evidence`). +- **A long list whose order votes are under 1% of its names** + (:ref:`suggest-deciding`). +- **A list mixing sources written differently**, whose votes cancel + out (:ref:`suggest-how-many`). +- **A base that already reads the list right**: the setting is decided + and shown ``(as the base)``, and the patch holds no change. + +None of these names holds a listed surname, a given name that is rarely +a surname, or any other evidence on the order: .. doctest:: @@ -302,6 +332,67 @@ Then, where you know how the list is written, set the order yourself What a name votes on -------------------- +The evidence on the order, the patronymic rule and +``two_family_names`` is a :class:`~nameparser.Signal`, which names its +row in the report and votes on one setting (the evidence on +``initials_as_family`` and ``capitals_as_family`` is no signal; +``NameEvidence.family_in_capitals`` holds the second): + +.. list-table:: + :header-rows: 1 + :widths: 30 22 22 26 + + * - Signal + - Report row + - Votes on + - Section + * - ``Signal.CAPITALS`` + - ``capitals`` + - ``name_order`` + - below + * - ``Signal.TRAILING_INITIAL`` + - ``trailing-initial`` + - ``name_order`` + - below + * - ``Signal.PARTICLE`` + - ``particle`` + - ``name_order`` + - below + * - ``Signal.SURNAME`` + - ``surname`` + - ``name_order`` + - below + * - ``Signal.GIVEN_NAME`` + - ``given-name`` + - ``name_order`` + - below + * - ``Signal.PATRONYMIC_POSITION`` + - ``patronymic-position`` + - ``name_order`` + - :ref:`suggest-patronymics` + * - ``Signal.PATRONYMIC`` + - ``patronymic`` + - ``patronymic_rules`` + - :ref:`suggest-patronymics` + * - ``Signal.FIRST_SURNAME`` + - ``first-surname`` + - ``two_family_names`` + - :ref:`suggest-two-family` + +A name's :class:`~nameparser.NameEvidence` holds its votes keyed by +signal: an order vote is the order it votes for, a patronymic vote the +rule, and a first-surname vote ``True`` or ``False``: + +.. doctest:: + + >>> from nameparser import Signal + >>> votes = Parser().suggest(["María García López", "Juan Pérez Ruiz", + ... "Ana Martínez Soto"]).names[0].votes + >>> sorted(signal.value for signal in votes) + ['first-surname', 'given-name', 'surname'] + >>> votes[Signal.FIRST_SURNAME] + True + Each name votes on its order from the evidence it carries: - **A family name written in capitals** at one end of a name in mixed @@ -437,11 +528,14 @@ list (``Sidorov Ivan``) is read in the order suggested. 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. +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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -657,13 +751,32 @@ among those it would change: >>> [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'] +The names the note counts as holding a common given name there are +read wrong under the switch, and a name whose word there neither table +lists may be (``Mark Oduya Bell`` gives family ``Oduya Bell``, where +``Pedro Zubizarreta Olano`` is read right); +``disagreeing()`` lists none of them, since they cast no vote. Check +them by hand, or choose the pack: + +.. doctest:: + + >>> with_given = Parser().suggest(["María García López", "Juan Pérez Ruiz", + ... "Ana Martínez Soto", "Maria Anna Berg", + ... "Mary Jane Smith"]) + >>> with_given.patch, with_given.disagreeing() + (PolicyPatch(two_family_names=True), ()) + >>> [e.note for e in with_given.evidence if e.setting == "two_family_names"] + ['3 of the 5 names two_family_names would change carry a common surname where it would take a first surname; 2 of them a common given name there, which casts no vote'] + 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: +The suggestion is the bare switch. Where you know a list is Spanish, +Brazilian or Portuguese, choose its pack instead (``locales.ES``, +``locales.ES_AR``, ``locales.PT_BR`` or ``locales.PT_PT``; +``locales.PT`` leaves the switch off, :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:: @@ -708,6 +821,8 @@ order and not the second family name: >>> Parser().suggest(padron).parser.parse("García López María").family 'García' +.. _suggest-keeping: + Keeping the settings you applied -------------------------------- @@ -763,9 +878,9 @@ The figures below were measured on groups drawn from real names written in a known order. They give a general idea of what to expect 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 three kinds of list below. +- **A list written in the base's own order**, save the three kinds of + list below, keeps it in at least 95% of groups from 2 to 2,000 names, + and in 97% for nearly every kind. - **A list written the other way round** takes more names to move the base, from 5 for Chinese, Taiwanese, Korean, Czech, Polish, Italian and Russian names to 50 for Indian ones and 200 for Bangladeshi @@ -797,8 +912,6 @@ surnames are no evidence. Of the lists measured that do not write their family names in capitals, only the one writing its given names so was suggested it; no other was, the bylines (``AM Hoy``) included. -The parser never detects the language of a name; the suggester may, -over a group you declare, says what it saw, and its answer is -configuration you apply. The measurements, each with its date and its -exact figures, the thresholds and the evidence declined are in +The measurements behind these figures, the thresholds and the +evidence declined are in the source repository's design record, ``docs/design/decisions/group-suggestion.md``. diff --git a/docs/usage.rst b/docs/usage.rst index 718075cdc..c0a47d58d 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -369,6 +369,17 @@ the initials within one group (:ref:`rendering-arguments`): >>> name.initials(spec="{given}{middle}{family}", delimiter="", separator="") 'JQXV' +A word in a script that writes no initials, such as Han, Hangul, kana, +Thai, Lao, Burmese or Arabic, gives none, and a word in another script +beside it still gives its own: + +.. doctest:: + + >>> parse("김민준").initials(), parse("أحمد علي").initials() + ('', '') + >>> parse("Ahmed علي").initials() + 'A.' + Initials written together in the name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~