diff --git a/docs/design/decisions/vocabulary-model.md b/docs/design/decisions/vocabulary-model.md index c80f7f64e..6b0bb5ad0 100644 --- a/docs/design/decisions/vocabulary-model.md +++ b/docs/design/decisions/vocabulary-model.md @@ -646,3 +646,10 @@ Open: [#1145](https://github.com/derek73/python-nameparser/issues/1145), the dis - **Measured** 2026-11-21 against a checkout of master `efdf0e16`, Python 3.11, the three together: `local_agreement.py cz-candidates --base --locale cs`, 169,254 of 170,181 records agreeing in every field (99.5%), 165 now agreeing, 4 now disagreeing and 11 changed. Of the 443 cz-candidates records holding a pair of degrees joined by `et` or `&`, those whose pair the pack read outside the title fell from 176 to 16 (`Ing et Ing` 107 to 1, `Bc et Bc` 48 to 0, `Ing & Ing` and `Bc & Bc` 1 each to 0; left, `D et Ph` 7, `DiS et DiS` 6, `arch et Ing` 1, `MSSc et MSSc` 1 and the one `Ing et Ing`; recompute: `config_diff.py diff --local cz-candidates --match '(?i)[a-z]\.?\s?(et|&)\s?[a-z]' --readings FILE default plain:CS` in each tree, the pair being a match of `([A-Za-z]+)\.\s?(et|&)\s?([A-Za-z]+)\.` in the name and outside the title where the `plain:CS` title holds no `et` or `&` as a substring, since `Bc.et Bc.` writes no space before it). Of every local corpus's names holding `bc`, `ing` or `et`, 260 read otherwise under plain `locales.CS`, none by a report alone: 193 a degree written with its period or in a pair, 24 the `bc` names above, and 43 holding `Ing` otherwise, of which about 22 are the degree read right now (`Ing Václav Novák`, `Jiří Novák, Prof Ing`) and about 19 Ing the given name opening a name read as the title (`Ing Wei Lim`, `ING MEI TAN`, `Mrs Ing Marie Berg`), the cost the pack takes, its callers' names being Czech. - **What breaks, under the pack only:** a name opening with the given name Ing (`Ing Wei Lim` reads title 'Ing'), and Ing alone after a family comma (`Lim, Ing` reads title 'Ing' and no given name), and a lone `Ing` or `Bc` (a title and no name); Ing the surname at the head of a family comma (`Ing Ho, Mei` reads title 'Ing', family 'Ho') or first under a family-first order (`Ing Wei` under `FAMILY_FIRST` reads title 'Ing', family 'Wei'); a post-nominal glued to Ing.'s stop (`Ph.D., Ing.Paed.IGIP` reads title 'Ing.Paed.IGIP', a period-joined token being a title where a chunk is one, rules/S3), 3 cz-candidates records; and `EUR ING` past a second comma, read as the title there (rules/C2), 1 record. The initials B.C. and the nursing credential BC, above. A degree in a credential list past the second comma (`Dana Novotná, prof.,Ing.,PhD`) moves from suffix to title, its name fields unchanged. - **Slovak is left as it was, save `et` and its strict cost above.** The one fielded population of Slovak names the corpora hold, the Slovak chamber in opensanctions-parliaments, writes no degree, so no measurement reaches `locales.SK`; cz-candidates' evidence is Czech, and a fragment for `ing` under `SK` waits for Slovak names to weigh it on. +- 2026-11-21 #1463 — ar.toml GIVES `cheikh` `given` AND `family` READINGS AND ms.toml GIVES `sultan` THE SAME, SO STRICT `ar` AND STRICT `ms` KEEP THEIR GATES; NO ROLE MOVES UNDER THE DEFAULT OR A PLAIN CHOICE. Decided 2026-11-21. Each word's only name reading stood in a file the strict choice drops (`cheikh`'s in fr.toml, `sultan`'s in ar.toml and tr.toml), so strict kept the chosen file's title reading and dropped the gate (rules/H9; the 2026-10-30 #753 derived-marker clause), reading the given name as a title: under strict `ar`, `Cheikh Kaddari` gave title 'Cheikh', given 'Kaddari'; under strict `ms`, `Sultan Zulkarnain` gave title 'Sultan', family 'Zulkarnain'. Both words leave tests/v2/test_reading_index.py's `STRICT_UNGATED`, as `sultan` left it under `ar` (the 2026-11-03 strict-gap batch F entry, whose "the next case of this gap" this is). Each takes a `family` reading too, as batch F gave `sultan` one in ar.toml: the gate reads a `given` reading alone (rules/H9), so the `family` one moves no role, but it names the file in `Reading.languages` where the strict choice read a family `Cheikh` or `Sultan` with none, and the counts below show both borne as family names in those countries. + - **Counted first**, the issue's third question, 2026-11-21 with `tools/name_usage.py cheikh sultan --boxes` and `--country` for the Maghreb, Egypt, Mauritania, Senegal, Saudi Arabia and Malaysia. `cheikh`: ORCID given boxes Mauritania 13 (3.79% of 343), Algeria 9, Morocco 4, Tunisia 1, Egypt 0, family boxes Tunisia 17, Algeria 14, Morocco 11, Mauritania 7; Senegal's 81 given boxes are fr.toml's, Wolof names written in French. `sultan`: ORCID given boxes Malaysia 7 of 62,996, family boxes 19, PatentsView 1 each; the Malaysian candidates write it once. Both are borne as given and as family names in the chosen language's countries, `sultan` rarely as a given one, and each reading records its counts. + - **Measured** 2026-11-21 on master `81a24221`, Python 3.11, strict against strict with the reading added, scored against ORCID's and PatentsView's boxes: `config_diff.py score strict:ar 'expr:(lambda p: Parser(lexicon=p.lexicon.add("cheikh", kind="given"), policy=p.policy))(parser_for(bare("ar"), strict=True))' --group TN --group MA --group DZ --group EG --group MR --cap 1000000`, 12 records fixed and 0 broken (Algeria 7 of 19,661, Morocco 1 of 19,635, Mauritania 4 of 336; Tunisia and Egypt 0), the issue's 8 in its four countries reproduced; the same with `strict:ms`, `"sultan"`, `bare("ms")` and `--group MY`, 1 fixed of 18,811 and 0 broken. The score's titled filter (`local_agreement.titled`, a record either column reads with a listed title typed into the given-names box) cannot drop one of these records: it reads a title as listed only where every word is in the default's `titles`, and both words are in `titles_ambiguous` there (rules/H9), so the 12 and the 1 count every record the score reads, 63 ORCID records holding `cheikh` with both boxes filed and 8 ORCID and 2 PatentsView records holding `sultan`. A word in the default's `titles` would need a direct count. Across trees, `config_diff.py diff default plain:ar plain:ms plain:MS plain:fr strict:ar strict:ms strict:ar+en strict:ms+en --local all --committed --match '(?i)cheikh|sultan' --readings FILE` in a checkout of master and of this change, the files compared line by line: of 3,567 names, the default and the four plain choices move 0; strict `ar` moves 196 and strict `ar` + `en` 196, strict `ms` 742 and strict `ms` + `en` 737, every move under strict `ar` taking the title `Cheikh` off, and under strict `ms` 733 taking the title `Sultan` off, 8 reading a credential strict `ms` does not list (en.toml's `DPT`, `DDS`) after a comma as the suffix, where the part before it, holding the title `Sultan`, had not counted as a full name (`Aisha Sultan, DPT`: given 'DPT', family 'Aisha Sultan' before), and 1 moving only its report (`Sultan II`, title-or-name to given-or-family), each landing on the plain choice's fields save where strict drops another word (ar.toml's `al` and `abu` under strict `ms`, a credential `BA`), and the 8 comma rows reporting the credential strict does not list (suffix-or-name), where the plain choice, listing it, reports nothing. `tests/v2/test_snapshot.py` passes unchanged and `build.py` reports `_compiled.py` current. + - **`Reading.languages`** of a given or family `Cheikh` gains `ar` beside `fr`, and of a given or family `Sultan` gains `ms` beside `ar` and `tr`, by default and under every choice that keeps the file; under strict `ar` a family `Cheikh`, and under strict `ms` a family `Sultan`, named no file before. + - **Accepted:** under strict `ms`, a ruler's style opening a name reads the given name, as it does by default and under `locales.MS` (`Sultan Rahmat ibni Sultan Kamil` → given 'Sultan'); behind a style it stays the title where the style is read (`His Majesty Sultan Rahmat` under strict `ms` + `en`; strict `ms` alone drops en.toml's `his` and `majesty`, before this change and after). + - **The pairs re-taken here stay ungated, as wanted:** under a strict choice the word is the particle that language writes. Re-taken 2026-11-21 on `81a24221` by the same score with each tag's ungated words given back their `given` reading: `ben` under strict `ar` fixes 62 records (Tunisia 45, Algeria 9, Morocco 8), `bin` under strict `ms` 6 (ORCID 2, PatentsView 4), `del`, `la`, `san` and `santa` under strict `it` 7, `del`, `la` and `san` under strict `fil` 2, `da`, `do` and `santa` under strict `pt-BR` 1, each breaking none. Read record by record, nearly all are a family name written first with the boxes filed that way round (`Ben Amri Salma`, given box `Ben Amri`): strict reads the whole name as the family (rules/P1's fold, `Ben Amri Salma` → family 'Ben Amri Salma'), wrong too, and the gate agrees with the boxes only because it reads the first word as a given name, so neither reading is the name and the gate's is no better. The rest are a given name the particle is spelled like: of another origin (`Bin Qiaoyu`, the Chinese given name, in Malaysia; `La Thuy`), a cost accepted under strict's premise that its data is of one origin (docs/locales.rst, "Reading one language only": strict is "for data you know to be of one origin"), which answers the issue's second question for `Bin`; and one of the language's own (`La Reina Dimaculangan`, a Philippine given name), a cost of reading `la` as the particle that the premise does not answer, left with the pair. + - **Not weighed here:** the rest of `STRICT_UNGATED`, which stays as it was: `gd`, `hr`, `sk`, `sl` and `hi`, and `marquis`, `marquise`, `tho`, `st` and `sushri`, which the issue's samples held too rarely to say anything (its first open question); the pairs of `nl`, `fr`, `ca` and `ga`, which moved none of the 822 records the issue's table read for them, so no reading of a record weighs them; `pt` and `pt-PT` (the issue's table read `pt` with `pt-BR` and holds no `pt-PT`; only `pt-BR` is re-taken here); and `my`'s ranks, which joined after the issue (#1483) and are titles, not particles, their given names written only in en.toml. None is decided as wanted by this entry (#1463). diff --git a/docs/release_log.rst b/docs/release_log.rst index d19c8d93e..22169e626 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,6 +4,7 @@ Release Log nameparser 3.2 is under development. + - **Keep Cheikh and Sultan as given names under a strict Arabic or Malay choice.** With ``languages=frozenset({"ar"})`` chosen and ``strict=True``, ``Cheikh Kaddari`` gives given ``Cheikh``, family ``Kaddari``, where 3.0.0 through 3.1.0 gave title ``Cheikh``, given ``Kaddari``; ``Sultan Zulkarnain`` under a strict ``ms`` choice reads given ``Sultan`` the same way. The default and every plain choice read both as before. :issue:`1463` - **Read the Cyrillic doctorate д-р ending a name as a credential, and the Bulgarian д.м. under a Bulgarian choice.** ``parse("Іван Петренко д-р")`` gives family ``Петренко``, suffix ``д-р``, where 1.4.0 through 3.1.0 gave middle ``Петренко``, family ``д-р``; in front of the name ``д-р`` stays the title, and after a comma it is the suffix too (``Іван Петренко, д-р``). With Bulgarian chosen (``languages=frozenset({"bg"})``), ``доц. д-р Мария Петрова, д.м.`` gives title ``доц. д-р``, family ``Петрова``, suffix ``д.м.``; by default it gives given ``д.м.``, family ``доц. Мария Петрова``, suffix ``д-р``, where 1.4.0 through 3.1.0 kept ``д-р`` in the family. :issue:`1128` - **Read Bc and Ing as titles under locales.CS, written bare or two joined by et.** ``parser_for(locales.CS).parse("Ing. et Ing. Jan Novák")`` gives title ``Ing. et Ing.``, given ``Jan``, family ``Novák``, where 3.0.0 through 3.1.0 gave given ``Ing. et Ing.``, family ``Jan Novák``; the default is unchanged. Under the pack a name that opens with the given name Ing reads it as the title (``Ing Wei Lim``), and initials ``BC`` after a comma read as the title too (``MOSS, BC``); a strict choice of ``cs`` or ``sk`` now keeps ``et`` between two degrees the pack reads (``Mgr. et Mgr.``). :issue:`970` - **Read an unlisted credential written in mixed case after a full name and a comma, such as MRes or AuD.** ``parse("Jane Smith, MRes")`` gives suffix ``MRes``, where 1.4.0 through 3.1.0 gave given ``MRes``, family ``Jane Smith``; the word must open with two capitals or end in one, so ``LeBron`` and ``PhDc`` stay given names, while a given name written so after a two-word surname reads as the credential (``García López, DAndre``). Behind one word it stays the given name (``Smith, MRes``), save behind initials spelling a credential, which read as the credential with it (``Smith, M.B. ChB``, and ``Jansen, J.P. IJsbrand``, which loses its given name). The positions only ``CapsSuffixes.EVERYWHERE`` reads still take words in capitals alone (``Alex Lee ONeill`` keeps family ``ONeill``). :issue:`1517` diff --git a/nameparser/config/_index.py b/nameparser/config/_index.py index 959954e07..67957b116 100644 --- a/nameparser/config/_index.py +++ b/nameparser/config/_index.py @@ -669,7 +669,7 @@ ('chdm', (('en', 'credential', ()),)), ('che', (('en', 'credential', ()), ('en', 'given', ()), ('en', 'family', ()))), ('chef', (('en', 'occupation', ()),)), - ('cheikh', (('ar', 'style', (('addresses', 'given'), ('same_as', 'sheikh'))), ('fr', 'style', (('addresses', 'given'), ('same_as', 'sheikh'))), ('fr', 'given', ()), ('fr', 'family', ()))), + ('cheikh', (('ar', 'style', (('addresses', 'given'), ('same_as', 'sheikh'))), ('ar', 'given', ()), ('ar', 'family', ()), ('fr', 'style', (('addresses', 'given'), ('same_as', 'sheikh'))), ('fr', 'given', ()), ('fr', 'family', ()))), ('chemist', (('en', 'occupation', ()),)), ('ches', (('en', 'credential', ()),)), ('chet', (('en', 'familiar', (('short_for', ('chester',)),)),)), @@ -3332,7 +3332,7 @@ ('sue', (('en', 'familiar', (('short_for', ('susan', 'susanne', 'suzanne')),)),)), ('suffragist', (('en', 'occupation', ()),)), ('sula', (('pt-BR', 'familiar', (('short_for', ('sulamita',)),)),)), - ('sultan', (('ar', 'nobility', ()), ('ar', 'given', ()), ('ar', 'family', ()), ('ms', 'nobility', ()), ('tr', 'nobility', ()), ('tr', 'given', ()), ('tr', 'family', ()))), + ('sultan', (('ar', 'nobility', ()), ('ar', 'given', ()), ('ar', 'family', ()), ('ms', 'nobility', ()), ('ms', 'given', ()), ('ms', 'family', ()), ('tr', 'nobility', ()), ('tr', 'given', ()), ('tr', 'family', ()))), ('sultana', (('ar', 'nobility', ()), ('ar', 'given', ()), ('ar', 'family', ()))), ('superior', (('en', 'modifier', ()),)), ('supreme', (('en', 'modifier', ()),)), diff --git a/nameparser/vocab/AGENTS.md b/nameparser/vocab/AGENTS.md index 86acff746..daf86f1c4 100644 --- a/nameparser/vocab/AGENTS.md +++ b/nameparser/vocab/AGENTS.md @@ -16,7 +16,7 @@ An acronym credential is matched with every full stop removed, so listing `P.Eng ## Step 2, for a reading a language file adds: score it under the choice that reads it -A reading written for one choice is measured under that choice's own parser, not the default's: the words around it are the choice's too. #1122 scored the readings `pt.toml` gained for a strict Portuguese choice with the default's particles and marked `carmen` (35 fixed to 0 broken) and `pilar` (20 to 3), whose Portuguese-country names were Spanish `del Carmen` and `del Pilar`; under `parser_for(locales.PT, strict=True)`, which holds no `del`, they scored 1 to 0 and 0 to 2, found by the design-docs review. Score with the choice's parser (its lexicon with and without the reading, beside its policy), and write test rows in phrases the language itself writes: the first draft's `Maria do Carmen` passed while Portuguese writes `do Carmo`. +A reading written for one choice is measured under that choice's own parser, not the default's: the words around it are the choice's too. #1122 scored the readings `pt.toml` gained for a strict Portuguese choice with the default's particles and marked `carmen` (35 fixed to 0 broken) and `pilar` (20 to 3), whose Portuguese-country names were Spanish `del Carmen` and `del Pilar`; under `parser_for(locales.PT, strict=True)`, which holds no `del`, they scored 1 to 0 and 0 to 2, found by the design-docs review. Score with the choice's parser (its lexicon with and without the reading, beside its policy), and write test rows in phrases the language itself writes: the first draft's `Maria do Carmen` passed while Portuguese writes `do Carmo`. A negative control for such a reading reverts the TOML and rebuilds, never copies `config/_index.py` from the base: the index holds every file's readings, so the base's copy reverts every reading the change adds at once, and #1463's control for `sultan` alone then failed `cheikh`'s rows too, a control that names nothing. Revert one file in a scratch copy of the tree (`git worktree add --detach`), never in a worktree anything else reads, run `build.py`, take the reading, and restore that file before the next; or take it without a revert, with the reading removed from the choice's own lexicon (`lexicon.remove(word, kind="given")`), but only where no other kept file (`mul.toml`, `und.toml`, another chosen tag) holds a reading of that kind on the word, since a `remove` drops the kind from every file: under strict `ms`, `remove("md", kind="given")` also drops `mul.toml`'s Muhammad written short. ## Step 2, for a joining word: state its costs by class, from a grid diff --git a/nameparser/vocab/ar.toml b/nameparser/vocab/ar.toml index 927a43c90..60ad7cee9 100644 --- a/nameparser/vocab/ar.toml +++ b/nameparser/vocab/ar.toml @@ -21,6 +21,8 @@ family = { us_census_2010 = 6462, wikidata = 60, as_of = 2026-10-27, note = "US [[word]] text = "cheikh" style = { addresses = "given", gender = "m", same_as = "sheikh", expands = "the French transliteration, 'Cheikh Anta Diop'" } +given = { note = "a given name in the Maghreb and Mauritania, counted 2026-11-21 (tools/name_usage.py --boxes): ORCID given boxes Mauritania 13 (3.79%), Algeria 9, Morocco 4, Tunisia 1; fr.toml's readings carry the Senegalese and Wikidata totals. Without it strict ar, which drops fr.toml's given reading, read it as a title opening a name (rules/H9): against strict ar, the reading fixes 12 ORCID records of Algeria, Morocco and Mauritania and breaks none (config_diff.py score on 81a24221) (#1463)" } +family = { note = "a family name in the Maghreb and Mauritania, counted 2026-11-21 (tools/name_usage.py --boxes): ORCID family boxes Tunisia 17, Algeria 14, Morocco 11, Mauritania 7; it moves no role, and names ar in Reading.languages where strict ar read a family Cheikh with no file (#1463)" } [[word]] text = "shaik" diff --git a/nameparser/vocab/ms.toml b/nameparser/vocab/ms.toml index 883e39c99..e3193c9f6 100644 --- a/nameparser/vocab/ms.toml +++ b/nameparser/vocab/ms.toml @@ -62,6 +62,8 @@ nobility = { default = false, addresses = "given", issue = 1180, decided = 2026- [[word]] text = "sultan" nobility = {} +given = { note = "a given name in Malaysia, rarely, counted 2026-11-21 (tools/name_usage.py --boxes): ORCID given boxes Malaysia 7, PatentsView 1. Without it strict ms, which drops ar.toml's and tr.toml's given readings, read it as a title opening a name (rules/H9): against strict ms, the reading fixes 1 ORCID record of Malaysia and breaks none (config_diff.py score on 81a24221). A ruler's style opening a name (Sultan Rahmat ibni Sultan Kamil) then reads the given name under strict ms, as it does by default and under locales.MS (#1463)" } +family = { note = "a family name in Malaysia, counted 2026-11-21 (tools/name_usage.py --boxes): ORCID family boxes 19, PatentsView 1; it moves no role, and names ms in Reading.languages where strict ms read a family Sultan with no file (#1463)" } [[word]] text = "tan" diff --git a/tests/v2/test_reading_index.py b/tests/v2/test_reading_index.py index 406fa80ca..674c70a9a 100644 --- a/tests/v2/test_reading_index.py +++ b/tests/v2/test_reading_index.py @@ -20,6 +20,7 @@ from tests.checkout import require_checkout from typing import Any +from nameparser import Lexicon, Locale from nameparser import _reading_index as ri from nameparser.config import _compiled, _index @@ -390,12 +391,13 @@ def test_a_file_holding_only_familiar_readings_is_chosen_only_strictly( #: file-strict entry measured 16 words, 27 word-and-tag pairs over 13 #: tags on 2026-10-31; the strict-gap batches of 2026-11-03 moved it, and #: #345 added hi's sushri, its Odia given name in or.toml; #1483 my's -#: ranks, whose given names only en.toml writes). A +#: ranks, whose given names only en.toml writes; #1463 took off ar's cheikh +#: and ms's sultan, each given a given reading in its file). A #: word leaves this table when a name reading is written in the chosen #: file whose names carry it, and joins it when a chosen file's #: vocabulary reading loses its gate: review each move. STRICT_UNGATED = { - "ar": {"ben", "cheikh"}, + "ar": {"ben"}, "ca": {"del", "la"}, "cs": {"st"}, "fil": {"del", "la", "san"}, @@ -405,7 +407,7 @@ def test_a_file_holding_only_familiar_readings_is_chosen_only_strictly( "hi": {"sushri"}, "hr": {"st"}, "it": {"del", "la", "san", "santa"}, - "ms": {"bin", "sultan"}, + "ms": {"bin"}, "my": {"brig", "gen", "maj", "major"}, "nl": {"den", "ten", "tho"}, "pt": {"da", "do", "santa"}, @@ -425,6 +427,81 @@ def test_the_words_strict_ungates_are_the_reviewed_set() -> None: assert got == STRICT_UNGATED +#: Names holding a word that left STRICT_UNGATED when its chosen file +#: gained the name reading (#1463): the word opening the name, in each +#: comma shape (one word, a full name and nothing before a family comma, +#: and a suffix comma) and case, behind a title of another kind, beside +#: a nickname and a generation, and two rows with the word last, which +#: the gate never reached, as edges. +_REGATED = { + "ar": ("Cheikh Kaddari", "Kaddari, Cheikh", "Kaddari, Cheikh Amine", + "Cheikh Kaddari, Amine", "Kaddari Amine, Cheikh", + ", Cheikh", "Cheikh", "CHEIKH KADDARI", "cheikh kaddari", + "Mr Cheikh Kaddari", "Dr. Cheikh Kaddari", "Cheikh Kaddari, PhD", + "(Bob), Cheikh", "Cheikh (Bob) Kaddari", "Cheikh Jr.", + "Amine Cheikh"), + "ms": ("Sultan Zulkarnain", "Zulkarnain, Sultan", "Zulkarnain, Sultan Ahmad", + "Sultan Zulkarnain, Ahmad", "Zulkarnain Ahmad, Sultan", + ", Sultan", "Sultan", "SULTAN ZULKARNAIN", "sultan zulkarnain", + "Encik Sultan Zulkarnain", "Haji Sultan Ahmad", + "Sultan bin Ahmad", "(Bob), Sultan", "Sultan (Bob) Ahmad", + "Aisha Sultan, DPT", "Sultan II", "Sultan Jr.", + "Ahmad bin Sultan"), +} + +#: The title the strict choice reads in a row, where it reads one. +_REGATED_TITLES = {"Mr Cheikh Kaddari": "Mr", "Dr. Cheikh Kaddari": "Dr.", + "Encik Sultan Zulkarnain": "Encik", + "Haji Sultan Ahmad": "Haji"} + +#: Rows the gate's other half reads: the word inside a title phrase, a +#: title under a strict choice as by default, where en.toml is chosen +#: beside the language (its style words and `of`). +_REGATED_PHRASES = { + "ar": (("Grand Cheikh Ahmed", "Grand Cheikh"),), + "ms": (("His Majesty Sultan Rahmat", "His Majesty Sultan"), + ("Sultan of Johor Ibrahim", "Sultan of Johor")), +} + + +def _choice(tags: tuple[str, ...]) -> Locale: + return Locale(code="choice", lexicon=Lexicon.empty(), + languages=frozenset(tags)) + + +@pytest.mark.parametrize("order", ["GIVEN_FIRST", "FAMILY_FIRST", + "FAMILY_FIRST_GIVEN_LAST"]) +@pytest.mark.parametrize("tags", [("ar",), ("ms",), ("ar", "en"), ("ms", "en"), + ("MS",)]) +def test_a_strict_choice_reads_a_regated_word_as_its_plain_choice_does( + tags: tuple[str, ...], order: str) -> None: + # strict drops every file holding a name reading of `cheikh` (fr.toml) + # and of `sultan` (ar.toml and tr.toml), and read each as the title + # opening a name (rules/H9) until ar.toml and ms.toml wrote one; "MS" + # is the shipped pack, the others a bare choice of those tags + import nameparser as N + from nameparser import Parser, Policy, locales, parser_for + choice = locales.MS if tags == ("MS",) else _choice(tags) + tag = tags[0].lower() + policy = Policy(name_order=getattr(N, order)) + plain, strict = (Parser(lexicon=parser_for(choice, strict=s).lexicon, + policy=policy) for s in (False, True)) + for name in _REGATED[tag]: + got, want = strict.parse(name), plain.parse(name) + assert got.as_dict() == want.as_dict(), name + assert got.title == _REGATED_TITLES.get(name, ""), name + kinds = [a.kind.value for a in got.ambiguities] + if name == "Aisha Sultan, DPT" and "en" not in tags: + # strict drops en.toml's DPT, so it reports the credential + # the plain choice lists + assert [a.kind.value for a in want.ambiguities] == [] + assert kinds == ["suffix-or-name"], name + else: + assert kinds == [a.kind.value for a in want.ambiguities], name + for name, title in _REGATED_PHRASES[tag] if "en" in tags else (): + assert strict.parse(name).title == title, name + + def test_strict_ungated_compares_with_the_plain_choice_not_the_default() -> None: # cs turns on the generation `st`, gated by en's given reading; the # default's markers hold no generation `st` at all, so a comparison @@ -461,3 +538,19 @@ def test_same_as_compiles_for_readings_of_every_kind() -> None: # only a given reading's same_as makes an abbreviated given name assert "wm" in compiled["GIVEN_NAME_ABBREVIATIONS"] assert not {"junior", "capt"} & compiled["GIVEN_NAME_ABBREVIATIONS"] + + +@pytest.mark.parametrize(("tag", "name", "word"), [ + ("ar", "Cheikh Kaddari", "Cheikh"), ("ar", "Amine Cheikh", "Cheikh"), + ("ms", "Sultan Zulkarnain", "Sultan"), ("ms", "Aisha Sultan", "Sultan"), +]) +def test_a_regated_word_names_its_chosen_file_in_either_name_role( + tag: str, name: str, word: str) -> None: + # ar.toml and ms.toml write both name readings (#1463): the given one + # keeps the gate, and the family one moves no role, but without it + # strict read a family Cheikh or Sultan naming no file + from nameparser import parser_for + strict = parser_for(_choice((tag,)), strict=True) + token = next(t for t in strict.parse(name).tokens if t.text == word) + assert token.reading is not None + assert tag in token.reading.languages