diff --git a/AGENTS.md b/AGENTS.md index dab64f44a..26dcaba4f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -272,7 +272,7 @@ The compiled sets, read by `Lexicon` (mostly as the `_sets` field of the same na - titles — `TITLES` (every title reading; prenominals), `GIVEN_NAME_TITLES` (the readings with `addresses = "given"`, e.g. "Sir", which treat the following name as given, not family — a subset of the title readings by construction, though not of `TITLES`: a word that may also be a given name, such as `king` or `sheikh`, compiles to `TITLES_AMBIGUOUS` instead) and `AFTER_GIVEN_TITLES` (the salutation readings with `after_given = true`, read as the title where one ends the given part after a family comma, rules/H8, #835 — a subset by construction); `TITLE_ABBREVIATIONS` (the title readings with `abbreviation = true`, `maj`, which rules/H5's trailing chain takes with its period where the word is in `TITLES_AMBIGUOUS`, and on a style rules/H9 gives the article before it as a partner, #999; private, like the kind sets 3.0 added); `DOTTED_TITLES` (the title readings with `dotted = true`, `us`, `uk`, `pd`, the titles abbreviating several words that a run of single letters joined by full stops spells, which rules/H10 reads as the title at the head of a name where a title the run keeps follows it, #490; private); `GLUED_TITLES` (the title readings with `attached = { side = "before" }`, Thai `นาย`, `นางสาว`, `อาจารย์`, which rules/W6's front peel splits off the start of the name's first word they are glued to, #317; private); `TITLES_AMBIGUOUS` (a title reading beside a `given` one, derived, compiled INSTEAD of into `TITLES`: a title only inside a title phrase, rules/H9, #752 phase 2i), `TITLE_MODIFIERS` and `TITLE_STYLES` (by kind) and `TITLE_PHRASES` (the two-word phrases `attaches` makes) - suffixes — `SUFFIX_ACRONYMS` (suffix readings with `acronym = true`, matched with every period removed, e.g. "M.D.") and `SUFFIX_WORDS` (the rest, e.g. "Jr."), disjoint because a word has one suffix kind; `SUFFIX_ACRONYMS_AMBIGUOUS` (an acronym reading on a word with a `given` or `family` reading, derived since 2026-10-25: the build refuses the phase 1 flag `may_be_name`; a `given` reading carrying `same_as`, a name written short, marks no clash with a suffix reading since #1383 (`ReadingProperties.marks_a_clash`), so `md`, Muhammad written short, stays an unambiguous credential); `SUFFIX_WORDS_AMBIGUOUS` (its word twin, a generation or agnomen reading, or a credential written as a word, on a word with a name reading, `fils`, `junior`, `júnior`, the agnomens and `kc`, `pc` and `dl`, gated by the count, rules/S11, since 2026-10-25, the credentials since 2026-10-30, #965, Junior since #1039) with `AGNOMENS` inside it (the `agnomen` kind) and `TITLE_CASE_NAME_WORDS` beside it (the readings written `title_case_is_name`, `fils`, `père`, `kc`, `pc`, `dl`, whose writing leans, Title case to the name; any other gated word's writing never leans, #1039); and `GLUED_HONORIFICS` (#308, `attached`), the subset of `SUFFIX_WORDS` the peel may split off the END of a name token — a separate, harsher bar, since the glued position has no writer-drawn boundary to lean on, and each word refused it carries `excluded = { attached = … }` - particles — `PARTICLES` (family-name particles, e.g. "de", "van") and `NON_GIVEN_NAME_PARTICLES`, the curated subset that is *never* a standalone given name (the particles whose word has no `given` reading, each stating `may_be_given = false`; a `given` reading on the word is what makes a particle possibly given, the phase 1 flag `may_be_given = true` refused since 2026-10-25). What the subset licenses is rules/P1's fold in `post_rules` (the "rule 1b" of older issue comments — decisions/legacy-rule-numbers maps the old numbers), and the fold has ONE site: the piece that OPENS the name. A lone never-given particle there, with at least one more name word behind it, starts the family. Titles do not move the opening position (rules/P4), so `Sir de Mesnil` reads family `de Mesnil` under every `name_order`, as `de Mesnil` does. How far the fold reaches depends on the order the name was read under: by default it takes the rest of the name (`de Mesnil Jean` → family `de Mesnil Jean`); under either family-first order it takes the particle run plus ONE name unit and lays the rest out by the order (`de Mesnil Jean` → family `de Mesnil`, given `Jean`); after a family comma it takes the rest of that part whatever the order (`Smith, de Mesnil Jean` → family `Smith de Mesnil Jean`). The leading particle stays a lone piece for the fold to find — `group` does not chain it forward, and the fold walks the particles after it itself — so `de la Vega` reads family `de la Vega` under all three orders. Behind a title-particle (`St`, `Freiherr`, P4's Except) it does chain, and under a family-first order the fold cuts that chain as it cuts a run (`St de Mesnil Jean` → family `de Mesnil`, given `Jean`, #828). The GIVEN position is not a site. It was a second one until #467, which removed it because under a family-first order that slot holds what the caller DECLARED to be the given name: `Mesnil de` under `FAMILY_FIRST` or `FAMILY_FIRST_GIVEN_LAST` reads given `de`, family `Mesnil`. Nor is a particle inside the name: `Juan de la Vega` under a family-first order reads family `Juan`, given `de la Vega`, with no ambiguity recorded — what the vocabulary forbids is the bare particle as a given name, not a name part that begins with one. A bare `de` has nothing to fold into and is placed like any one-word name, by `Policy.lone_name_word` (rules/O5, #1111): given `de` by default under every order, family `de` where the caller sets the switch to family. A leading particle OUTSIDE the set is left to position — `Van Gogh` is given `Van`, family `Gogh` by default and family `Van`, given `Gogh` under both family-first orders — and records a `PARTICLE_OR_GIVEN` ambiguity under all three, save one written in lower case in a mixed-case name under a family-first order, which the fold takes and which records none (`van Gogh` → family `van Gogh`, rules/P11, #670); a never-given particle opening the name records none (`de Mesnil`), and neither does an ambiguous one inside it (`Vincent van Gogh`). The internal `Lexicon._sets.particles_ambiguous`, the particles holding a `given` reading, is its complement within `PARTICLES`, so the two mark OPPOSITE sets — see the flip warning in `docs/migrate.rst` before translating either -- bound given names — `BOUND_GIVEN_NAMES` (`bound_given` readings, e.g. "abdul", "abu"; one that is also a particle needs a `given` reading, a build check); a group-stage rule joins the first non-title piece to its following piece before roles are assigned, reserving a family word unless a family comma has already fixed it or a given-name title stands ahead (#369, rules/P5) (ported from v1's `_join_bound_first_name`), and `BOUND_PHRASES` (#694, rules/P12, the two-word given names a bound word's `completed_by` lists, Arabic `عبد` before the names of God), each pair joined past the first name word, where P5's join does not reach, and `BOUND_COMPLETES_ANY` (#1464, the `completes_any` readings, the Latin `abdul`, `abd`, `abdel`, `abdal`, `abou`) with `BOUND_LONG_NAMES_ONLY` inside it (`long_names_only`, `abdul`), the bound words P12 joins with any plain name word after them, the second only in a name of four name words or more, both private +- bound given names — `BOUND_GIVEN_NAMES` (`bound_given` readings, e.g. "abdul", "abu"; one that is also a particle needs a `given` reading, a build check); a group-stage rule joins the first non-title piece to its following piece before roles are assigned, reserving a family word unless a family comma has already fixed it or a given-name title stands ahead (#369, rules/P5) (ported from v1's `_join_bound_first_name`), and `BOUND_PHRASES` (#694, rules/P12, the two-word given names a bound word's `completed_by` lists, Arabic `عبد` before the names of God), each pair joined past the first name word, where P5's join does not reach, and `BOUND_COMPLETES_ANY` (#1464, the `completes_any` readings, the Latin `abdul`, `abd`, `abdel`, `abdal`, `abou`) with `BOUND_LONG_NAMES_ONLY` inside it (`long_names_only`, `abdul`), the bound words P12 joins with any plain name word after them, the second only in a name of four name words or more, both private; and `BOUND_SECONDS` (#1072, the `bound_second` kind, Arabic-script `الدين` and `الله` with their Persian and Urdu spellings, and `الغنى`, `الفقار`), the words a pair writes second, which P12 joins with the plain word before them at the first name word too, with `BOUND_SECOND_PHRASES` beside it (the pairs a reading's `completes` lists, `ذو الغنى`, the only ones such a word joins), private - given names written short — `GIVEN_NAME_ABBREVIATIONS` (#789, a `given` reading carrying `same_as`, the full name: "chas", "wm", Filipino "ma", `md`), the given names written short that rules/H2's shape yields to, and that rules/C13's given-name Except reads where one is also a credential opening the part after a family comma (#1393, classify's `vocab:given-abbreviation` tag), and that rules/S8's run declines for in a name written wholly in one case with a name word behind it (#1394, `SITI NORA MD YUSRI`); nothing else reads it - names a given name's second half reads — `PARTICLE_GIVEN_NAMES` (#704, a `given` reading written `after_particle`: "carmen", "ángeles", "lurdes", "graças", the Spanish and Portuguese words a compound given name writes behind a particle, which rules/P10 reads as a middle name in `María del Carmen García`, by default, and "piedade" only under a Portuguese choice, #1118, #1122), `SAINT_PARTICLES` (the `saint` kind, `san`, `santa`, `st`, `ste`, `sta`, `sto`, whose run P10 refuses, `Santa María` being a surname) and `SHARED_NAMES` (#704, a name reading written `shared`: Sikh "kaur", "singh", which rules/O6 and O7 neither take nor complete and P10 does not complete, `Kaur del Carmen García`), private; each is read through classify's tags or the lexicon in `_post_rules` - conjunctions — `CONJUNCTIONS` (e.g. "and", "of") used to chain multi-word titles and to join name parts (rules/P3), plus `CONJUNCTIONS_AMBIGUOUS` (#383/#479, rules/P8, `may_be_initial`, refused by the build on anything but a cased single letter), the subset of single cased letters that read as an INITIAL in a name written wholly in one case — a marker set diff --git a/docs/customize.rst b/docs/customize.rst index b0faf749c..0cc1e9620 100644 --- a/docs/customize.rst +++ b/docs/customize.rst @@ -228,6 +228,10 @@ A kind belongs to a category, which decides what the reading does: - The word joins the word after it into one given name (`Bound given names`_). - ``bound_given`` + * - bound_second + - The word joins the word before it into one name (``عز الدين``), + added in 3.2 (`Bound given names`_). + - ``bound_second`` * - relation - The name after the word is the maiden name (``née``). - ``birth_marker`` @@ -325,6 +329,9 @@ arguments to ``add``: - bound_given - The words it joins past the first name word (`Bound given names`_). + * - ``completes=[...]`` + - bound_second + - The only words it joins behind (`Bound given names`_). * - ``after_particle=True`` - ``given`` - Behind a particle the word completes a given name, so @@ -1187,6 +1194,26 @@ with the pair as the family, state ``abdul``'s reading without >>> Parser(lexicon=lex).parse("Tariq Abdul Aziz").family 'Abdul Aziz' +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 +``الله`` after it, the word before varying, so ``الدين`` and ``الله`` +join any plain word before them, at the start of a name too, where the +pair is the given name. ``الغنى`` and ``الفقار`` are written +``completes=["ذو"]``, joining behind ``ذو`` alone; a word that lists +them joins behind those words only. A name of two name words keeps +them apart, as it keeps ``عبد الله``: + +.. doctest:: + + >>> noor = parse("نور الدين سامر حداد") + >>> noor.given, noor.middle + ('نور الدين', 'سامر') + >>> parse("سامر عز الدين").family + 'عز الدين' + >>> parse("عز الدين").given + 'عز' + .. _rendering-arguments: Presentation: rendering arguments diff --git a/docs/design/decisions/P12-bound-given-name-and-the-word-that-completes-it.md b/docs/design/decisions/P12-bound-given-name-and-the-word-that-completes-it.md index 7c86ce6d5..4e19b53bd 100644 --- a/docs/design/decisions/P12-bound-given-name-and-the-word-that-completes-it.md +++ b/docs/design/decisions/P12-bound-given-name-and-the-word-that-completes-it.md @@ -7,11 +7,14 @@ - The Latin `abd`, `abdel`, `abdal` and `abou` are written `completes_any`: past the first name word each joins any plain name word after it, one the vocabulary reads no other way, the pair placed by position, the family where it ends the name and one middle name inside it (`Tariq Abdel Aziz` → family 'Abdel Aziz') — 2026-11-19 #1464, reversing 2026-11-04 #694's decline. - `abdul` is written `long_names_only` beside it, joining only in a name of four name words or more, counted part by part before a maiden clause: a word with no letter and each part's leading title run (a listed title, a title phrase H9 reads with the word its connective joins, a dotted title, a title by H2's shape) counting as none, and after the pair only a plain word, a bound given name or a pair of initials in a script with case up to the next comma, a numeral `VI` to `X` written other than in Title case counting as none (`Tariq Abdul Aziz` → middle 'Abdul'; `Nadia Ali Abdul Rahim` → family 'Abdul Rahim'): the writers of a three-word `X Abdul Y` split it both ways by population — 2026-11-19 #1464. - `abu` keeps its particle and teknonymic readings and no `completes_any`; Arabic-script `عبد` keeps its list — 2026-11-19 #1464. +- A pair is read from its second word too: a `bound_second` reading (Arabic-script `الدين` and `الله`, Persian `الدین` and `اله`, Urdu `اللہ`) joins the plain word before it, one carrying no vocabulary and holding a letter, at the first name word too, the pair placed by position, under the default order the given name where it opens the name and the family where it ends it (`نور الدين سامر حداد` → given 'نور الدين'; `سامر عز الدين` → family 'عز الدين'); P5's join of a bound word opening the name wins over a pair read from the word after it (`أبو نور الدين سامر` → given 'أبو نور'); `الغنى` and `الفقار` are written `completes = ["ذو"]`, joining behind `ذو` alone; where the pair holds every name word the name is read as having it is split back into two names, as P5's reserve keeps a bound word's, save after a family comma and behind a given-name title, where P5 joins too; the pair is one unit wherever UNIT-PARTITION counts units (P1's fold, rules/O6's take and its division) — 2026-11-19 #1072. - A pair P12 joined counts as one family word for rules/O6 (two family names): under `two_family_names` `سعيد حسن عبد الله` gives family 'حسن عبد الله'; P5's pair at the start and a pair a particle chain took count as two — 2026-11-04 #694; a Latin pair the join makes past the first name word counts as one, as the Arabic-script pair does (`Ana abdul Rahman López` under `two_family_names` gives family 'abdul Rahman López'), where one at the start still counts as two — 2026-11-19 #1464. Open: `locales.MS` (#1179) could turn `abdul`'s three-word join on, its Malaysian writers filing the pair as the family 183 times to 2 in ORCID; as shipped it reads `abdul` as the default does, and a strict choice of it reads no Latin bound word at all, `ar.toml` not being chosen (2026-11-19 #1464). -Open: the second elements that join the word BEFORE them (`الدين`, `الله`, `الغنى` in `جميل عز الدين`, `هالة شكر الله`, `عائشة ذو الغنى`), the other three Arabic-script names `wikidata_native_agreement.json` held on the shape, want a mechanism of their own and are not decided here. +Open: the Latin spellings of a pair read from its second word stay out (2026-11-19 #1072): `Uddin`, the commonest, is a surname alone in South Asian names (PSC 25 records fixed and 432 broken, ORCID's Bangladesh 15 and 99, the prototype scored against the boxes on 2026-11-19), and without the `u-` forms (`Eddine`, `Eldin`, `Aldeen` and the like, and `Allah` behind a word other than `Abd`) ORCID gains 155 and loses none, but PSC 16 and 11 and PatentsView 6 and 8. + +Open: `آية الله` (Ayatollah) is no title (2026-11-19 #1072). Today's vocabulary cannot make it one: a title phrase's partner must be a title word, `الله` cannot take a title reading without breaking the pairs read from it (`ليلى شكر الله`, which a title-tagged second word does not join; `عبد الله` still joins forward), and `آية` alone is the given name Aya. Reading it as a title would need the title phrase test to accept a partner with no title reading. The shape is 16 spaced spellings in JRC-Names (`آية`/`اية الله` 11, Persian `آیت الله` 5) and 7 written joined with a ZWNJ, which the join does not touch; none in ORCID or the parliaments. Under the join `آية الله X Y` reads given 'آية الله', where 3.1.0 read given 'آية', middle 'الله X', wrong both ways. ## Log @@ -47,3 +50,29 @@ Open: the second elements that join the word BEFORE them (`الدين`, `الل - **Measured** 2026-11-19 with `tools/differential/measure.py --base` against master `1ca93b25`, on the branch's final code (`3940a393`). Moves: ORCID 1,586 names, ClinicalTrials.gov officials 399 and contacts 249, JRC-Names 592, PSC 265, PatentsView 126, TSE donors 37, `my-candidates` 24, the parliaments 9, the committed snapshot 2; every other local corpus, CLDR and GND unmoved. Each move is a middle word joining the family or middle name after it, save one shape: `Abd` opening a word pair after a family comma, which the given part had read as the credential ABD, now joins (`Haddad, Nadia Abd Karim` → middle 'Abd Karim', where 1.4.0 through 3.1.0 read suffix 'Abd'). Scored against the boxes (`local_agreement.py`, its own count, which compares every record and not only those holding a word): ORCID 1,247 records read right that did not and 31 the reverse, PSC 148 and 73, PatentsView 68 and 56; JRC-Names 61 persons whose spellings now read alike and 89 now apart (the prototype of the join in every name: 63 and 111). - **O6.** A pair this join makes counts as one family word, as `abu Bakr` does, so under `two_family_names` `Ana abdul Rahman López` gives family 'abdul Rahman López' (rules/O6's case row moved to `Umm Kulthum`, whose bound word P12 does not join past the first word, `umm` completing nothing). - **Frames.** The reference row (`Dr. Juan0001 de la Vega III`) stays 196 and `Smith, John` 98; a name whose bound word opens it pays nothing (`Abdul Rahman Ali` 132), one holding one past the first word pays two frames for the four-word count where it asks one (`Tariq Abdul Aziz` 127 → 129, the count and H2's shape test of the leading word) and 8 to 11 where the pair joins (`Tariq Abdel Aziz` 127 → 135, `Nadia Ali Abdul Rahim` 143 → 154), counted with `sys.setprofile` over 20 parses each on py3.11, 2026-11-19, on the branch's final tree. +- 2026-11-19 #1072 — A PAIR IS READ FROM ITS LISTED SECOND WORD TOO. Resolves the Open line on the second elements that join the word before them (`الدين`, `الله` behind a word other than `عبد`, `الغنى` behind `ذو`: the three Arabic-script names `wikidata_native_agreement.json` still recorded after #694, all of this shape). The second word is the fixed one and the word before it varies past any list, so the license sits on the second word: a new vocabulary kind, `bound_second`, whose only effect is this join (`bound_given` would join forward at P5 too), compiled into `BOUND_SECONDS`, and its one property, `completes`, the first words a reading joins behind alone, into `BOUND_SECOND_PHRASES`. Classify tags the first word where it carries no vocabulary and holds a letter, the second carries none but H9's contested-title tag, and, once roles are settled, a pair holding every name word the parse read is split back (post_rules), save where P5 would join it too; group's P12 join pairs them, and joins such a pair at the first name word too, which it leaves to P5 for a bound first word. One rule, P12, read from whichever word is listed; P5 keeps the bound word at the first name word, and a pair read from its second word is no bound word for P5 to read. + - **Three variants, measured side by side** on a prototype (2026-11-19, against master `34771e2d`), each with the guard for a name of two words: (A) a list of second elements behind any plain word; (B) a closed list of pairs, 37 first words before `الدين` and 36 before `الله`; (C) `الدين` behind any word, `الله` behind B's listed first words. Scored three ways: ORCID's records in Arabic script whose boxes are in Arabic script and whose name holds a second word (178), right where given and middle together equal the given box and the family the family box; the Wikidata native corpus's fields; and by the pair's place, against the convention that a pair opening the name is the given name and one ending it the family (opening and ending pairs read split on master in every population). + + | | A | B | C | + |---|--:|--:|--:| + | ORCID records fixed / broken | 33 / 0 | 26 / 0 | 26 / 0 | + | Wikidata native: the three recorded names | 3 agree | 3 | 3 | + | Egypt's House: opening `الدين` 10, ending `الدين` 7, ending `الله` 8 | 25 right | 25 | 25 | + | JRC-Names: opening `الدين` / `الله`, names of three words or more, the pair kept in one field | 33 of 33 / 60 of 60 | 23 / 18 | 33 / 18 | + | JRC-Names: ending `الدين` / `الله` | 18 of 21 / 21 of 28 | 18 / 6 | 18 / 6 | + + The 19 middle pairs of Egypt's House read right before and after. + - **Recipe of the prototype measurement** (2026-11-19, master `34771e2d`). The variants as tested: A's second words `الدين`, `الدین`, `الله`, `اله`, `اللہ`; B's first words before `الدين` (37: نور صلاح علاء محي محيي محى سعد حسام جمال عز عماد زين نجم ناصر ضياء بدر بهاء شرف شمس عصام شهاب برهان فخر سراج كمال سيف تاج جلال قطب ركن معين غياث خير نصير علم شجاع مجد) and before `الله` (36: فتح نصر فضل جاب ضيف أمان امان صنع خلف منة عطا عطاء داد دخل حسب جاد خير عوض رزق رحمت دفع شكر جار حمد هبة عطية ولي ولی ذبيح ذبیح نعمت روح حبيب لطف سعد نور); every variant with `ذو` before `الغنى`, `الغني` and `الفقار`. The ORCID score: every record whose name holds an Arabic letter and a second word and whose given and family boxes hold one, right where the parse's given and middle together equal the given box and its family the family box, words compared after lower-casing and dropping commas. The Latin forms tried: the one-word spellings ORCID writes at least 3 times (`uddin`, `eddine`, `eldin`, `aldeen`, `eldeen`, `eddin`, `el-din`, `aldin`, `addin`, `addeen`, `al-din`, `eddeen`, `el-dine`, `aldine`, `eldine`) and `allah`, scored the same way over ORCID, PSC (forename and middle-name boxes as the given) and PatentsView records of a Latin name holding one past its first word; the second figures drop the forms opening with `u`. + - **The counts in the vocabulary notes** (2026-11-19): distinct names in Arabic script in each local corpus's `raw.jsonl` (ORCID's records with an Arabic letter in the name, Egypt's House from `opensanctions-parliaments`, `eg_house_representatives`), split at whitespace and the Arabic comma, a pair counted where a second word stands behind a word other than `عبد`, as opening where the second word is the name's second word (two-word names included, which the join leaves apart), ending where it is the last, and middle otherwise; the first words before `الدين` and `الله` counted distinct over the same names (70 and 99, news spellings with a prefix or a vowel each counting apart). Recipe: the scratch `count.py` of the measurement, its logic as written here. + - **The three questions.** + - **A list of second elements, not a list of pairs:** A fixes 7 ORCID records more than B and breaks none. B misses the long tail of first words, 70 distinct before `الدين` and 99 before `الله` in the corpora, and the news spellings written with a prefix or a vowel (`وعبد`, `عبدِ`, `لسعد`, `صلاحِ`). + - **`الله` behind any plain word:** against listed first words only (A against C), 7 ORCID records more and none broken, and JRC-Names' opening `الله` 60 against 18 (names of three words or more). What must not move does not: `عبد الله`, which P12 joins forward, the bound word carrying its tag; a lone `الله`; a name of two words, `X الله`; `بن الله`, the particle being no plain word; a title before it. + - **The Latin spellings** are left out (the Open line above). + - **What A gets wrong:** `آية الله`, no title today, reads as a given name (the Open line above); a phrase of three words or more that is no name would join as a name does, though none was found in the corpora (`بيت الله`, a place in news text, stands as two words, which the join leaves apart, and `بیت اللہ` is a given name too). A second word written with its marks (`الدّين`) is not listed and keeps the pair apart, as P12's completing words do. + - **The alike views:** on the branch's build (`local_corpora.py alike --base`, 2026-11-19), JRC-Names reads 4 persons' spellings apart that read alike before and 1 alike that did not (the prototype: 5 and 1), and the parliaments 9 apart, none brought together. Each of the 9 is a member spelled short in one entry, ending in the pair (`X عز الدين`, a family of two words now), and with a longer chain in another (a family of one word): the view compares the family's word count, and the two writings hold different families. Not a misreading. + - **The Persian population** is small: 9 JRC-Names spellings and 11 ORCID records hold a second word and `الدین`, `اله`, `ی` or `ک` (the letter set the measurement used), the join moving 8 of each; the ORCID ones are inside the 33 / 0. + - **Review fixes before the PR** (2026-11-19): the first build counted every role-less word for the guard, so a title or a suffix beside a two-word pair joined it into the whole name (`Dr. عز الدين` read family 'عز الدين' and no given name); it now counts as the four-word gate does. And `_vocab.unit_ends` and O6's division knew a pair only by the bound word's tag, so under `two_family_names` a pair joined from its second word was cut (`سامر عز الدين حداد` read middle 'عز'), and P1's family-first fold cut it (`آل عز الدين سامر` read family 'آل عز'); both read the new tag now, as they read the forward pair's. + - **ORCID by `local_agreement.py orcid-researchers --base`** against `34771e2d` on the branch's build (2026-11-19): 33 records read right that did not, none the reverse, and 6 read differently and wrong both ways. + - **A second round on the fix commits** (2026-11-19) found the guard's count narrowed: counting after the pair only a plain word, as `abdul`'s four-word gate does, left a bare title ending the name uncounted, though the parse reads it as the family (`عز الدين الحاج` read given 'عز', middle 'الدين'); the guard now counts it, and the given part after a family comma. It also found the pair cut before a family comma under `two_family_names` (`حداد عز الدين، سامر` left undivided while `سامر حداد عز الدين` divided `حداد` | `عز الدين`): group stripped the pair's tag where a family comma's part joins nothing, and the unit readers then saw two words; the tag stays now, as `vocab:bound-given` does, and classify joins no pair written across a comma. The review of that fix found the widened count wider than the parse: a bare title behind a credential was counted though the trailing run takes it (`عز الدين PhD الحاج` joined the pair into the whole name), and every comma part past the first was counted, a suffix comma's included; the count stops at the first suffix word, numeral or period-marked title after the pair, and reads only the given part after a family comma, and only where it opens with no suffix word. A third review found that this count narrowed again, refusing a pair before a word the trailing run then left a middle name (`عز الدين الابن حداد`, `عز الدين V حداد`): classify cannot know what the trailing run will take, so every count there approximates a later stage's reading. The guard was moved to that reading: classify tags every candidate pair, and post_rules splits a pair holding every name word the parse read, after P5's exceptions, a family comma and a given-name title, which the classify-time guards had missed too (`، عز الدين` and `الدكتور عز الدين` read given 'عز الدين', as `، عبد الله` and `الدكتور عبد الله` do). `abdul`'s four-word gate keeps its own count, measured under #1464: whether it should count a bare trailing title too is left to a change that measures it. + - **The real build** reads the 857 corpus names holding a second word as prototype A does, save one: a JRC-Names `عبد الغني` of two words, which the prototype joined at the first word, keying its exception on the second word's text, and the build keys on the pair's tag, reading it as master does. + - **Frames:** a name holding no word of `BOUND_SECONDS` pays nothing (the reference row 196, `Smith, John` 98, `سعيد حسن` 126); a name holding one pays the pair test, and a pair that joins 10 or 11 (`ليلى عز الدين` 171 → 181, `نور الدين سامر حداد` 195 → 206), and a name of two name words pays nothing for the split unless its first word carries the pair's tag, counted with `sys.setprofile` over 20 parses each on py3.11, on the branch's build. diff --git a/docs/design/mechanisms.md b/docs/design/mechanisms.md index 2c1b27d34..9a384c1a5 100644 --- a/docs/design/mechanisms.md +++ b/docs/design/mechanisms.md @@ -61,9 +61,9 @@ This catalog converts discovery into a one-time cost — it does not remove disc **Problem shape.** A rule counts "one name word", but the input holds words that another rule has already joined into one name — and the joining structure it would read has been merged away. -**Contract statement.** Four rules build multi-word units: a particle chain (P2), a conjunction join (P3), a bound given-name pair (P5), and a bound given name with the word that completes it past the first name word (P12). A rule that counts name words counts those units, and takes each whole or not at all — with stated exceptions: rules/C3's count of the words before a comma, which counts particle surnames alone (decisions/C3, #575), and three cuts of a particle chain at the run and the one word it attaches to, P1's family-first fold, rules/O6's family-first cut (#1024) and rules/P10's particle phrase, which reads that much of the family's chain as a middle name only where the vocabulary marks the word (#704). +**Contract statement.** Four rules build multi-word units: a particle chain (P2), a conjunction join (P3), a bound given-name pair (P5), and a bound given name with the word that completes it past the first name word, or a plain word with the listed word written second after it, at the first name word too (P12). A rule that counts name words counts those units, and takes each whole or not at all — with stated exceptions: rules/C3's count of the words before a comma, which counts particle surnames alone (decisions/C3, #575), and three cuts of a particle chain at the run and the one word it attaches to, P1's family-first fold, rules/O6's family-first cut (#1024) and rules/P10's particle phrase, which reads that much of the family's chain as a middle name only where the vocabulary marks the word (#704). -**How it works.** group builds each join as a piece, but its own prefix chain then merges the joined piece into a longer one, so PIECES no longer carries the boundary — the units are rebuilt from the tags the vocabulary layer left (`particle`, `conjunction`, `vocab:bound-given`). The rebuild is RECURSIVE: what a conjunction or a bound word joins is the next UNIT, not the next word, and absorbing a single token instead strands a particle severed from the words it chains. Note the two joins arrive here for opposite reasons — the conjunction join was built and then swallowed, while the bound-given join was never built at all (P5 joins only at the first non-title piece), so restoring piece boundaries in group would fix the first and silently split the second. +**How it works.** group builds each join as a piece, but its own prefix chain then merges the joined piece into a longer one, so PIECES no longer carries the boundary — the units are rebuilt from the tags the vocabulary layer left (`particle`, `conjunction`, `vocab:bound-given`, and `vocab:bound-second` on the first word of a pair joined from its second, #1072). The rebuild is RECURSIVE: what a conjunction or a bound word joins is the next UNIT, not the next word, and absorbing a single token instead strands a particle severed from the words it chains. Note the two joins arrive here for opposite reasons — the conjunction join was built and then swallowed, while the bound-given join was never built at all (P5 joins only at the first non-title piece), so restoring piece boundaries in group would fix the first and silently split the second. **Lives in.** nameparser/_pipeline/_vocab.py (`unit_ends`, the walk, shared since #575) and its two readers: _post_rules.py (`_units`, over classify's tags, for P1's fold) and rules/C3's counts before a comma: `_comma._whole_name`, over classify's tags (`surname_unit_facts`) since #613 moved the decision after classify, and `_vocab.name_word_count`, which builds its facts from the vocabulary (`surname_unit_tags`, held to classify's tags by an agreement test) -- a view script_segment needed while it asked a hand copy of C1 before classify ran, until #613's /simplify had it ask `_comma.decide` itself on a classified copy. A fourth walk is S2's read (#614): `_pieces._chain_units` marks each piece by the unit P2's chain WILL put it in -- opening a unit, or a name word the chain joins -- asking the chain's own `chain_run_end`, which `_group`'s chain calls too; a word the reading weighs (`_weighed`) keeps a unit of its own, as a position always counted it. The particles straight behind each other are merged ahead of the read, into the piece the chain would open its run with (`_pieces.merge_particle_runs`, #625), so a particle run is one piece the read takes whole or not at all, and no mark stands for a particle inside it. The trailing peel's words to spare and #602's run start count in those marks, the peel stops at a word the chain joins, and everything else -- the numeral fork's look at the word in front, the H5 chain, the run's title test -- reads the pieces as written. It runs before the chain joins name words to a particle run, which is why it cannot read the merged tags `unit_ends` walks; #614 had rebuilt the chain as a merged COPY instead, whose three defects in one review -- words the reading weighs hidden inside a unit, indices drifting from the pieces' -- were each patched in that copy, and #620 replaced it with the marks (decisions/S2). C3 counts particle chains only, reaching one word as the fold does: a bound pair builds a given name, and whether P3 joins a connective depends on the whole name the count is helping to decide, so neither is one surname before a comma (`_vocab.SURNAME_UNIT_TAGS`, decisions/C3). rules/P1 and rules/C3 are the counting rules, P2/P3/P5 the joining ones. diff --git a/docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md b/docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md index 32c2d43fb..c63f97108 100644 --- a/docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md +++ b/docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md @@ -1,8 +1,8 @@ # P12 — a bound given name and the word that completes it -**When:** a bound given-name word stands past the first name word, and the word after it is one the vocabulary lists as completing it, as in "طارق عبد العزيز", or a plain name word after a bound word whose reading completes with any name. +**When:** a bound given-name word stands past the first name word, and the word after it is one the vocabulary lists as completing it, as in "طارق عبد العزيز", or a plain name word after a bound word whose reading completes with any name; or a word the vocabulary lists as written second in a pair stands after a plain name word anywhere in the name, as in "سامر عز الدين". -**Then:** the two words are one name unit past the first name word, a unit that position places. +**Then:** the two words are one name unit, past the first name word or, for a pair read from its second word, at it too, a unit that position places. - **The completing word is one a reading lists** (`completed_by` on the bound word's reading): for Arabic-script `عبد`, the one-word names of God, the other divine epithets and the devotional completions written after it, each in its hamza-less and Persian spellings. ``` @@ -25,15 +25,36 @@ "Ahmad Abdel bin Omar" → middle="Abdel" · boundary "Ahmad Abdel K." → middle="Abdel" · boundary ``` +- **A listed second word completes the plain word before it** (a `bound_second` reading): Arabic script writes many given names as a varying word and `الدين` (of the faith) or `الله` after it, the Persian spellings `الدین` and `اله` and the Urdu `اللہ` too, and the word before varies past any list, several of those words being given names alone, so the license is the second word, and it is read from wherever the pair stands; a reading written `completes` joins behind the words it lists alone (`ذو` before `الغنى` and `الفقار`). + ``` + "نور الدين سامر حداد" → given="نور الدين" + "سامر عز الدين" → family="عز الدين" + "ليلى شكر الله" → family="شكر الله" + "سامر ذو الغنى" → family="ذو الغنى" + "سامر نور الدين حداد" → middle="نور الدين" + "نصر اله رضایی" → given="نصر اله" + "سامر بن الله" → family="بن الله" · boundary + ``` **Because:** Arabic script writes a theophoric given name as two words, `عبد` (servant of) and the name of God it serves, `عبد الله`, so a name holding two of them, or one behind a given name, puts the second word where a family name would stand alone. In Arabic script the words that complete `عبد` are a closed set, the names of God and a few devotional names, so the vocabulary can list them, and a list is certain where a shape is not (the article `ال` opens a nisba surname as readily as a name of God), while a Latin spelling drops the article and names no word, leaving a name word's place as the only signal. Researchers who split such a name into boxes put the pair in the family box together. **Except:** -- **The first name word is P5's**, which joins a bound word there to the word after it with its reserve, so a bound word with no word to spare there keeps its two words apart. +- **A bound word at the first name word is P5's**, which joins it to the word after it with its reserve, so a bound word with no word to spare there keeps its two words apart; a pair read from its second word joins there instead, its first word being no bound word for P5 to read. ``` "عبد الله" → given="عبد" ``` +- **A pair read from its second word needs a third name word**: where the pair holds every name word the name is read as having, its two words are two names, as P5's reserve keeps a bound word's, save after a family comma and behind a given-name title, where P5 joins too. + ``` + "عز الدين" → given="عز" + "Dr. عز الدين" → given="عز" + "عز الدين Jr." → given="عز" + "عز الدين PhD الحاج" → given="عز" + "عز الدين الحاج" → given="عز الدين" + "عز الدين الابن حداد" → given="عز الدين" + "الدكتور عز الدين" → given="عز الدين" + "، عز الدين" → given="عز الدين" + ``` - **A bound word with neither joins only at the start**: a word whose reading neither lists a completion nor completes with any name is P5's alone. ``` "Tariq Umm Aziz" → middle="Umm" @@ -47,13 +68,21 @@ "Nadia Abdul Rahim, MA" → middle="Abdul" ``` +**Precedence:** + +- **P5's join of a bound word opening the name** takes the plain word after it before a pair read from that word's second word can: the bound word's join is P5's, and the pair is split. + ``` + "أبو نور الدين سامر" → given="أبو نور" + ``` + **Accepted:** - A completing word written with its vowel points or with the alef wasla (`ٱلله`, `اَلله`) is not listed, and keeps its words apart; one JRC-Names spelling held one after `عبد` on 2026-11-04 (`عبد ِالعزيز`). - A connective's join takes the word after it first (P3), so a pair behind a connective stays apart: `طارق عبد الله و عبد الرحمن` reads middle 'عبد الله و عبد', family 'الرحمن'. - A writer who counts `Abdul` a middle name of its own in a name of four words reads the pair joined all the same: `Nadia Ali Abdul Rahim` gives family 'Abdul Rahim' where such a writer would have the family 'Rahim'. +- A word read as a title that no title reading lists is a name word, and a listed second word joins it: `آية الله سامر حداد` gives given 'آية الله', the title Ayatollah. - A kunya opening the name is P5's join of its two bound words, and the word completing the second is left to position (`أبو عبد الله محمد` reads given 'أبو عبد', middle 'الله'), as before this rule; behind a given name the kunya is the family (`محمد أبو عبد الله`). --- -**Signal:** neighbor: a bound given-name word and the word after it, which its reading lists, or which carries no vocabulary after one that completes any, `abdul` only in a name of four name words or more +**Signal:** neighbor: a bound given-name word and the word after it, which its reading lists, or which carries no vocabulary after one that completes any, `abdul` only in a name of four name words or more + neighbor: a word listed as written second and the plain word before it **history:** decisions/P12 · **implemented:** nameparser/_pipeline/_classify.py, nameparser/_pipeline/_group.py, nameparser/_pipeline/_post_rules.py diff --git a/docs/design/rules/README.md b/docs/design/rules/README.md index 509fd4b0a..9f8f7c7cc 100644 --- a/docs/design/rules/README.md +++ b/docs/design/rules/README.md @@ -95,7 +95,7 @@ The marker's unit is the whole rule, so a clause that reaches past the tolerated Terms the rules use without defining them each time, each with the rule that defines or counts it. -- **name word** — a word of the person's name itself: titles, suffixes, nicknames and particles acting as particles are not name words (R3). How name words are COUNTED is each rule's own, and there is no single count: C3, counting the words before a comma, takes a particle run and the one name word it attaches to as one word (P1's reach, not P2's whole chain), counts a connective join and a bound given-name pair as their words, and counts a suffix word opening the part as a name word where one follows it; S8 counts P2's whole chain as one name word; P1's family-first fold takes one unit, a particle chain (P2), a conjunction join (P3) or a bound given-name pair (P5) whole; O6 counts a family's words by P1's reach, a connective join and a hyphenated word counting as their words. P12's four-word gate counts the name's words before a maiden clause part by part, a word with no letter and each part's leading title run counting as none, and after the pair only a plain word, a bound given name or a pair of initials up to the next comma, a numeral written other than in Title case not counting. +- **name word** — a word of the person's name itself: titles, suffixes, nicknames and particles acting as particles are not name words (R3). How name words are COUNTED is each rule's own, and there is no single count: C3, counting the words before a comma, takes a particle run and the one name word it attaches to as one word (P1's reach, not P2's whole chain), counts a connective join and a bound given-name pair as their words, and counts a suffix word opening the part as a name word where one follows it; S8 counts P2's whole chain as one name word; P1's family-first fold takes one unit, a particle chain (P2), a conjunction join (P3) or a bound given-name pair (P5) whole; O6 counts a family's words by P1's reach, a connective join and a hyphenated word counting as their words. P12's four-word gate counts the name's words before a maiden clause part by part, a word with no letter and each part's leading title run counting as none, and after the pair only a plain word, a bound given name or a pair of initials up to the next comma, a numeral written other than in Title case not counting; its two-word guard for a pair read from its second word counts none, asking the parse instead whether the pair holds every name word it read. - **words to spare** — enough name words that reading one as a suffix still leaves the name its family word. As the second of two name words a bare ambiguous acronym has none to spare and stays the family name (S4); S10's one-letter numeral needs the same. - **credential run** — a run of words read as post-nominals: a comma part made wholly of suffix words (C1, C8), or the run an unambiguous credential starts after the name core, taking every later word of its part (S8). - **listing form** — the family name, a comma, then the given name, as in "Smith, John" (C1). diff --git a/docs/migrate.rst b/docs/migrate.rst index 96c9f0dec..497894564 100644 --- a/docs/migrate.rst +++ b/docs/migrate.rst @@ -2325,6 +2325,30 @@ apart. In a name of three words ``Abdul`` still stays apart: >>> haddad.middle, haddad.suffix ('Abd Karim', '') +A pair written with الدين or الله second +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In Arabic script, ``الدين`` and ``الله`` (``الدین``, ``اله`` and +``اللہ`` in Persian and Urdu spelling) join the word before them into +one name, and ``ذو`` joins ``الغنى`` and ``الفقار``. Position places the +pair: the given name where it opens the name, the family name where it +ends it. 1.4 through 3.1 split a pair opening or ending the name. A +name of two name words still keeps them apart, as it keeps ``عبد الله``: + +.. doctest:: + + >>> noor = parse("نور الدين سامر حداد") + >>> noor.given, noor.middle + ('نور الدين', 'سامر') + >>> parse("سامر عز الدين").family + 'عز الدين' + >>> parse("عز الدين").given + 'عز' + +``Lexicon.add`` accepts the new kind, ``bound_second``, for a word of +your own written second in such a pair, with ``completes=[...]`` naming +the only words it joins behind. + Arabic-script titles written short, and initials in Arabic script ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/release_log.rst b/docs/release_log.rst index e7e12421a..cbfec6953 100644 --- a/docs/release_log.rst +++ b/docs/release_log.rst @@ -4,6 +4,7 @@ Release Log nameparser 3.2 is under development. + - **Fix an Arabic-script name written with الدين or الله second, which read as two names.** ``parse("نور الدين سامر حداد")`` gives given ``نور الدين``, where 1.4.0 through 3.1.0 gave given ``نور``, middle ``الدين سامر``; ending the name the pair is the family name, and ``الدین``, ``اله`` and ``اللہ`` read the same way; a name of two name words keeps them apart. ``Lexicon.add`` accepts a new kind, ``bound_second``, for such a word. :issue:`1072` - **Add Qari, Moulana, Alhaj and Alhajj as titles, the religious titles written before a name in Pakistan and Bangladesh.** ``parse("Qari Ahmed Khan")`` gives title ``Qari``, given ``Ahmed``, where 1.4.0 through 3.1.0 gave given ``Qari``, middle ``Ahmed``. ``Hafiz``, ``Hafez``, ``Haji`` and the spelling ``Maulana``, often borne as given names, still read as the given name. :issue:`1469` - **Fix Abdel, Abd and Abou past the first word of a name, which read as a middle name of their own.** ``parse("Tariq Abdel Aziz")`` gives family ``Abdel Aziz``, where 1.4.0 through 3.1.0 gave middle ``Abdel``, family ``Aziz``. ``Abdul`` joins only in a name of four words or more, titles and suffixes not counted, so ``Tariq Abdul Aziz`` keeps middle ``Abdul``; and after a family comma ``Abd`` before a name word is no longer the credential ABD. :issue:`1464` - **Add locales.MS, a Malay pack, which reads Malaysian titles written before a name: Puan, Cik, Ustaz, Ustazah and Cikgu.** ``parser_for(locales.MS).parse("Puan Siti binti Ahmad")`` gives title ``Puan``, given ``Siti``, family ``binti Ahmad``, where the default, as 1.4.0 through 3.1.0, gives given ``Puan``; ``Tuan`` stays a name word, being a hereditary prefix and a Vietnamese given name, and the pack reads the Indonesian given name ``Puan`` as the title too (``Puan Maharani``): keep it to Malaysian names. See :ref:`malay-names`. :issue:`1179` diff --git a/nameparser/AGENTS.md b/nameparser/AGENTS.md index c7d29e81d..55548245f 100644 --- a/nameparser/AGENTS.md +++ b/nameparser/AGENTS.md @@ -12,7 +12,7 @@ A view the parse marks must read the same for the comma writing of a name, and a ### Counting the one-word path -Count the one-word path the way C3 counts, which is neither tokens nor pieces: a particle run and the one word it attaches to are one word (#575), a connective join and a bound given-name pair count as their words (#613, so `Ortega y Gasset, Dr.` is a whole name), and a suffix beside the surname counts as no name word at all -- a numeral of two or more letters (`VI` to `IX`) the trailing fork reads as the generation included, as a listed one is (#893: `Dumas VI, Jr.` lost its family where `Dumas III, Jr.` kept it). #603's review found the suffix half (`Vega y Lopez Jr., PhD Jones` lost its family where `Vega y Lopez, PhD Jones` kept it); #613 then reversed the connective half, and both now read given 'Vega', middle 'y', family 'Lopez' — so test a particle surname, a connective surname and a surname with a suffix, each before a comma. The same holds for any count INSIDE a part, not only the comma's: #886's numeral site in the family part counted pieces, and an unjoined particle there is a piece of its own, so `Smith van der V, John` and `SMITH VD V, JOHN` read suffix 'V' from 2.7.0 until #1080, the particles counted as words to spare; put a particle run in front of the word being counted, and one opening the part (`de Mesnil V, Jean`, which #1080's first fix still counted), in the grid of every count -- and a single-letter connective, which P3 leaves unjoined where the name has fewer than four root words and is a piece the same way: `Smith y V, John` read suffix 'V' until #1093. #1080's test review found it, though that fix's grid held `y`: but a grid read for what a change MOVES shows nothing about a shape it leaves wrong, so read the unmoved rows of a count's grid too. And write the connective in one case too, but don't assume what it is there: only the marked subset (`may_be_initial`, rules/P8) reads as an initial in a one-case name, while `Y` and `И` keep their connective tag, so `JOHN SMITH Y V` moved with its mixed-case twin under #1097 and #1098, after a decision had been asked on the premise that it could not. A suffix word OPENING the part is the other half, and counts as a name word where one follows it: from 2.4.0 the counts passed over it, so `JP Clancy, MD` lost its given name to initials that spell a credential and `Cem Akin, MD` to a given name a credential spells, until #1017, while `Md Rahman, PhD` had read title 'Md' or family 'Md Rahman' in every release. No comma grid had put a listed suffix word at the head, and real heads are full of them, so open a head with initials (`JP`, `A.M.`), a given name a credential spells (`Cem`, `Md`), a title/suffix dual (`Sr.`) and a split credential's member (`MB ChB`), behind a title too, and put a title behind the opening word (`Md Prof., PhD`): the first build counted it as the name word there in one count and not in the other, found by review. A bound given-name pair is the same trap from the other side: a count that passes over particles reads `Abu Bakr` as ONE word, `abu` being a particle and a bound word both, where `abdul Rahman` counts two, so a rule asking whether the given name already holds two words needs a bound pair of each spelling in its grid; #1057's grid held only `abdul` until its test review found O7 completing `Abu Bakr` (`_post_rules._one_given_word` counts it now). And C3's one name word is not one word as written: it passes over a title word (`Ashley Knight`) and reads a capitalized particle with its surname as one (`Bin Zhang`), so a rule keyed to a one-word head reads more two-word heads than it means to -- #1238's first build read `Bin Zhang, M.D.` and `Ashley Knight, M.S. BME` as initials, found by its grid and the ClinicalTrials.gov measurement; put a title-word surname and a capitalized particle head in the grid of any one-word-head rule, beside the lower-case Dutch particle (`de Waart`) it may mean to admit. A run of letters is a spelling too: `_LETTER` matches a Hangul syllable (`J.씨`, a glued honorific) and a decomposed accent's base, so a test that every letter is a capital needs a mark-free, cased letter in its grid and the NFD spelling beside it. And a count of the whole name's words leaves the maiden clause out (rules/M2): #1464's four-word count for `abdul` first counted `née Haddad` as two name words, so `Tariq Abdul Aziz née Haddad` joined where `Tariq Abdul Aziz` did not, found by `test_a_maiden_clause_changes_nothing_else` and not by the change's own grid, which put a clause only behind `abdel`, a word the count does not gate: put the clause behind the word a count decides for. Its code review found two more of the same: a suffix written without a comma (`Tariq Abdul Aziz Jr.`, where the grid held only `Tariq Abdul Aziz, MD`) and a title read by its shape (`Insp.`) each counted as a name word, so put a suffix with and without its comma, and a listed and a shape title, around the word a count decides for. The review of that fix found five more: a title phrase H9 reads (`Associate Dean`, `The Rt Hon`, `Dean of Students`) and a dotted title (`U.S. Senator`), tagged only later in classify, so the count moved below the H9 phrase test; an ambiguous credential (`, MA`) and a numeral `VI` to `X`, which carry another tag or none; and a pair of initials (`B.K.`), which an exclusion by the acronym's shape tag dropped though #864 reads it as the family. A count of name words reads every kind of non-name word the parse knows, and runs where the stage has tagged them all. Moving the test later then narrowed it twice, found by the next review: the join's "plain word after it" test now saw the tag H9 leaves on a contested title it reads as a name (`Ali Abdel Mahdi`), and the leading title run took a particle after a title for a title's object (`Dr Abu Bakar Abdul Rahim`); when a test moves to read more tags, re-check every test beside it that reads tags too. +Count the one-word path the way C3 counts, which is neither tokens nor pieces: a particle run and the one word it attaches to are one word (#575), a connective join and a bound given-name pair count as their words (#613, so `Ortega y Gasset, Dr.` is a whole name), and a suffix beside the surname counts as no name word at all -- a numeral of two or more letters (`VI` to `IX`) the trailing fork reads as the generation included, as a listed one is (#893: `Dumas VI, Jr.` lost its family where `Dumas III, Jr.` kept it). #603's review found the suffix half (`Vega y Lopez Jr., PhD Jones` lost its family where `Vega y Lopez, PhD Jones` kept it); #613 then reversed the connective half, and both now read given 'Vega', middle 'y', family 'Lopez' — so test a particle surname, a connective surname and a surname with a suffix, each before a comma. The same holds for any count INSIDE a part, not only the comma's: #886's numeral site in the family part counted pieces, and an unjoined particle there is a piece of its own, so `Smith van der V, John` and `SMITH VD V, JOHN` read suffix 'V' from 2.7.0 until #1080, the particles counted as words to spare; put a particle run in front of the word being counted, and one opening the part (`de Mesnil V, Jean`, which #1080's first fix still counted), in the grid of every count -- and a single-letter connective, which P3 leaves unjoined where the name has fewer than four root words and is a piece the same way: `Smith y V, John` read suffix 'V' until #1093. #1080's test review found it, though that fix's grid held `y`: but a grid read for what a change MOVES shows nothing about a shape it leaves wrong, so read the unmoved rows of a count's grid too. And write the connective in one case too, but don't assume what it is there: only the marked subset (`may_be_initial`, rules/P8) reads as an initial in a one-case name, while `Y` and `И` keep their connective tag, so `JOHN SMITH Y V` moved with its mixed-case twin under #1097 and #1098, after a decision had been asked on the premise that it could not. A suffix word OPENING the part is the other half, and counts as a name word where one follows it: from 2.4.0 the counts passed over it, so `JP Clancy, MD` lost its given name to initials that spell a credential and `Cem Akin, MD` to a given name a credential spells, until #1017, while `Md Rahman, PhD` had read title 'Md' or family 'Md Rahman' in every release. No comma grid had put a listed suffix word at the head, and real heads are full of them, so open a head with initials (`JP`, `A.M.`), a given name a credential spells (`Cem`, `Md`), a title/suffix dual (`Sr.`) and a split credential's member (`MB ChB`), behind a title too, and put a title behind the opening word (`Md Prof., PhD`): the first build counted it as the name word there in one count and not in the other, found by review. A bound given-name pair is the same trap from the other side: a count that passes over particles reads `Abu Bakr` as ONE word, `abu` being a particle and a bound word both, where `abdul Rahman` counts two, so a rule asking whether the given name already holds two words needs a bound pair of each spelling in its grid; #1057's grid held only `abdul` until its test review found O7 completing `Abu Bakr` (`_post_rules._one_given_word` counts it now). And C3's one name word is not one word as written: it passes over a title word (`Ashley Knight`) and reads a capitalized particle with its surname as one (`Bin Zhang`), so a rule keyed to a one-word head reads more two-word heads than it means to -- #1238's first build read `Bin Zhang, M.D.` and `Ashley Knight, M.S. BME` as initials, found by its grid and the ClinicalTrials.gov measurement; put a title-word surname and a capitalized particle head in the grid of any one-word-head rule, beside the lower-case Dutch particle (`de Waart`) it may mean to admit. A run of letters is a spelling too: `_LETTER` matches a Hangul syllable (`J.씨`, a glued honorific) and a decomposed accent's base, so a test that every letter is a capital needs a mark-free, cased letter in its grid and the NFD spelling beside it. And a count of the whole name's words leaves the maiden clause out (rules/M2): #1464's four-word count for `abdul` first counted `née Haddad` as two name words, so `Tariq Abdul Aziz née Haddad` joined where `Tariq Abdul Aziz` did not, found by `test_a_maiden_clause_changes_nothing_else` and not by the change's own grid, which put a clause only behind `abdel`, a word the count does not gate: put the clause behind the word a count decides for. Its code review found two more of the same: a suffix written without a comma (`Tariq Abdul Aziz Jr.`, where the grid held only `Tariq Abdul Aziz, MD`) and a title read by its shape (`Insp.`) each counted as a name word, so put a suffix with and without its comma, and a listed and a shape title, around the word a count decides for. The review of that fix found five more: a title phrase H9 reads (`Associate Dean`, `The Rt Hon`, `Dean of Students`) and a dotted title (`U.S. Senator`), tagged only later in classify, so the count moved below the H9 phrase test; an ambiguous credential (`, MA`) and a numeral `VI` to `X`, which carry another tag or none; and a pair of initials (`B.K.`), which an exclusion by the acronym's shape tag dropped though #864 reads it as the family. A count of name words reads every kind of non-name word the parse knows, and runs where the stage has tagged them all. Moving the test later then narrowed it twice, found by the next review: the join's "plain word after it" test now saw the tag H9 leaves on a contested title it reads as a name (`Ali Abdel Mahdi`), and the leading title run took a particle after a title for a title's object (`Dr Abu Bakar Abdul Rahim`); when a test moves to read more tags, re-check every test beside it that reads tags too. And a new way of joining two words into one unit must be taught to every reader of units, not only to the join: #1072's pair joined from its second word was cut by P1's family-first fold and by O6's take and division until `_vocab.unit_ends` and `_divide_family` read its tag, as they read `vocab:bound-given` (mechanisms.md#UNIT-PARTITION lists the readers); its first build also counted a title or a suffix as a name word for its two-word guard. Put the pair under `two_family_names` and a family-first order, behind a particle, and beside a title and a suffix, in the grid of any new join. Its fix then narrowed in turn, found by the review of the fix commit: counting only plain words after the pair dropped a bare trailing title the parse reads as the family (`عز الدين الحاج`), and the pair was still cut before a family comma, where group joins nothing and had stripped the tag the unit readers counted it by. Compare a name's comma writing with its comma-free twin (`حداد عز الدين، سامر` against `سامر حداد عز الدين`) in the grid of any view a join feeds. And a third review found the guard's word count, made in classify, narrowing once more, since classify cannot know what the trailing run will take: a guard on how many name words a name holds belongs where the parse has read them (post_rules here), not in a stage that guesses the later stages' reading. ### Orders diff --git a/nameparser/_lexicon.py b/nameparser/_lexicon.py index de396e5b3..ce2fe0c91 100644 --- a/nameparser/_lexicon.py +++ b/nameparser/_lexicon.py @@ -601,6 +601,15 @@ class _LexiconSets: #: do so only in a name of four words or more (rules/P12, #1464) bound_completes_any: frozenset[str] bound_long_names_only: frozenset[str] + #: the words a bound pair writes second and joins from, and the + #: pairs a reading written `completes` lists ('ذو الغنى'); a word + #: with a reading listing none joins behind any plain word, at the + #: first name word too (rules/P12, #1072) + bound_seconds: frozenset[str] + bound_second_phrases: frozenset[str] + #: the words of `bound_seconds` every reading of which lists + #: `completes`, joining behind those words alone + bound_seconds_listed: frozenset[str] #: Lexicon field -> the compiled constant it is read from, for every @@ -644,6 +653,9 @@ class _LexiconSets: "bound_phrases": "BOUND_PHRASES", "bound_completes_any": "BOUND_COMPLETES_ANY", "bound_long_names_only": "BOUND_LONG_NAMES_ONLY", + "bound_seconds": "BOUND_SECONDS", + "bound_second_phrases": "BOUND_SECOND_PHRASES", + "bound_seconds_listed": "BOUND_SECONDS_LISTED", } #: What the 2.x sets do not record: the kinds the views read (rules/R8, @@ -935,6 +947,7 @@ def _unwritten(kind: str, prop: str) -> object: _LIST_PROPS: Mapping[str, str] = MappingProxyType({ "attaches": "title kinds or title words, e.g. attaches=['military']", "completed_by": "single words, e.g. completed_by=['الله']", + "completes": "single words, e.g. completes=['ذو']", "short_for": "given names, e.g. short_for=['maxwell']", "spelling_of": "given names, e.g. spelling_of=['olga']", }) @@ -1007,11 +1020,19 @@ def _prop_value(kind: str, prop: str, value: object) -> object: f"normalizing to nothing, got {value!r}; write e.g. " f"{prop}={['maxwell'] if prop == 'short_for' else ['olga']!r}") folded = tuple(sorted({_normalize(x) for x in words} - {""})) - if prop == "completed_by" and any(" " in w for w in folded): - # rules/P12 joins a bound word to the ONE word after it - raise ValueError(f"completed_by entries must be single words, " - f"got {value!r}; list each completing word " - f"on its own") + if prop in ("completed_by", "completes") and not folded: + # an empty list would leave `completes` unwritten, which + # joins behind ANY plain word, the widest reading; the build + # refuses it too (#1072) + raise ValueError(f"{prop} must list at least one word, got " + f"{value!r}; write {prop}=None to clear a " + f"list the word's reading has") + if prop in ("completed_by", "completes") and any(" " in w for w in folded): + # rules/P12 joins two words: a bound word to the one word + # after it (completed_by), a bound_second word to the one + # before it (completes) + raise ValueError(f"{prop} entries must be single words, " + f"got {value!r}; list each word on its own") if prop in ("short_for", "spelling_of") and any( " " in w for w in folded): # the match compares a given name word by word @@ -1930,8 +1951,8 @@ class LexiconReading: #: :class:`ReadingKind`, which is the parse's. kind: str #: The kind's category (``"title"``, ``"suffix"``, ``"particle"``, - #: ``"conjunction"``, ``"bound_given"``, ``"relation"``, - #: ``"name"``). + #: ``"conjunction"``, ``"bound_given"``, ``"bound_second"``, + #: ``"relation"``, ``"name"``). category: str #: The behavioral properties as sorted ``(name, value)`` pairs, #: spelled as the files spell them (``("addresses", "given")``), a @@ -2437,14 +2458,17 @@ def add(self, *words: str, kind: str | None = None, ``nameparser._reading_index.CATEGORY`` (``"title"``, ``"office"``, ``"credential"``, ``"generation"``, ``"preposition"``, ``"conjunction"``, ``"bound_given"``, - ``"birth_marker"``, ``"given"``, ``"family"``, ...), and + ``"bound_second"`` (3.2), ``"birth_marker"``, ``"given"``, + ``"family"``, ...), and `properties` that kind's behavioral properties as the files spell them (``addresses="given"``, ``after_given=True``, ``abbreviation=True``, ``attaches=[...]``, ``acronym=...``, ``attached="after"`` on a suffix word reading and ``attached="before"`` on a one-word title reading (rules/W2 and W6), - ``may_be_initial=True``, ``completed_by=[...]`` on a - ``bound_given`` reading, ``after_particle=True`` on a + ``may_be_initial=True``, ``completed_by=[...]``, + ``completes_any=True`` and ``long_names_only=True`` on a + ``bound_given`` reading, ``completes=[...]`` on a + ``bound_second`` reading, ``after_particle=True`` on a ``given`` reading, ``shared=True`` on a name reading, ``capital_opening=True`` on a particle reading, ``dotted=True`` on a title reading, and diff --git a/nameparser/_pipeline/_assemble.py b/nameparser/_pipeline/_assemble.py index d71635966..9cf5f1603 100644 --- a/nameparser/_pipeline/_assemble.py +++ b/nameparser/_pipeline/_assemble.py @@ -58,7 +58,7 @@ AGNOMEN_TAG, AMBIGUOUS_ACRONYM_TAG, AMBIGUOUS_WORD_TAG, ATTACHED_TAG, CAPITALS_FAMILY_TAG, CREDENTIAL_WORD_TAG, FIELD_READING, GENERATION_WORD_TAG, HONORIFIC_WORD_TAG, NAME_ROLES, PATRONYMIC_TAG, SECOND_SURNAME_TAG, SHAPE_ACRONYM_TAG, - SHARED_NAME_TAG, PARTICLE_GIVEN_TAG, BOUND_PHRASE_TAG, + SHARED_NAME_TAG, PARTICLE_GIVEN_TAG, BOUND_PHRASE_TAG, BOUND_SECOND_TAG, FIRST_SURNAME_TAG, SURNAME_PAIR_TAG, SPLIT_CREDENTIAL_TAG, SPLIT_MEMBER_TAG, PAST_REACH_TAG, CHAIN_TITLE_TAG, DOTTED_TITLE_TAG, JOINED_TITLE_TAG, TITLE_AMBIGUOUS_TAG, TRAILING_TITLE_TAG, Beside, Deferred, ParseState, PendingAmbiguity, @@ -271,14 +271,15 @@ def _split_partner(tokens: tuple[WorkToken, ...], dropped: set[int], #: chain reads (#999), for which the published token keeps #: TITLE_AMBIGUOUS_TAG; and the shared-name and particle-given marks #: rules/O6 and O7 read (#704), the bound-phrase mark rules/P12 -#: reads (#694), the past-reach mark on a particle chain past rules/P1's +#: reads (#694) and its twin on a pair joined from its second word +#: (#1072), the past-reach mark on a particle chain past rules/P1's #: fold (#828), and the joined-title mark (#1104) and the #: chain-title mark (#1171) rules/H5's chain reads; and the capitals #: mark rules/O9 writes (#659), whose source `Token.reading` carries. _KIND_TAGS = frozenset({GENERATION_WORD_TAG, CREDENTIAL_WORD_TAG, HONORIFIC_WORD_TAG, PATRONYMIC_TAG, ATTACHED_TAG, TRAILING_TITLE_TAG, SHARED_NAME_TAG, PARTICLE_GIVEN_TAG, PAST_REACH_TAG, - BOUND_PHRASE_TAG, JOINED_TITLE_TAG, CHAIN_TITLE_TAG, + BOUND_PHRASE_TAG, BOUND_SECOND_TAG, JOINED_TITLE_TAG, CHAIN_TITLE_TAG, SURNAME_PAIR_TAG, CAPITALS_FAMILY_TAG}) #: The second-surname mark O6 or W5 writes (rules/R10) and the diff --git a/nameparser/_pipeline/_classify.py b/nameparser/_pipeline/_classify.py index f4cc5ec6e..54cc9aaac 100644 --- a/nameparser/_pipeline/_classify.py +++ b/nameparser/_pipeline/_classify.py @@ -30,7 +30,9 @@ two-word given names a bound word completes into (bound_phrases, #694) and the bound words that complete with any plain name word, in any name or only in one of four name words or more -(bound_completes_any, bound_long_names_only, #1464) and the titles a +(bound_completes_any, bound_long_names_only, #1464) and the words a +pair writes second and joins from, and the pairs those list +(bound_seconds, bound_second_phrases, #1072) and the titles a run of single letters may spell (dotted_titles, rules/H10, #490) and the saint particles a word glued at its full stop is cut behind (saint_particles, through `_vocab.glued_saint_cut`); and, since @@ -106,7 +108,7 @@ class (rules/S12). from nameparser._pipeline._state import ( AGNOMEN_TAG, AMBIGUOUS_ACRONYM_TAG, AMBIGUOUS_WORD_TAG, COMMA_STRIP, CREDENTIAL_WORD_TAG, GENERATION_WORD_TAG, GIVEN_ABBREVIATION_TAG, HONORIFIC_WORD_TAG, - BOUND_PHRASE_TAG, PARTICLE_GIVEN_TAG, PATRONYMIC_TAG, SHAPE_ACRONYM_TAG, SHARED_NAME_TAG, SPLIT_CREDENTIAL_TAG, SPLIT_MEMBER_TAG, TITLE_AMBIGUOUS_TAG, + BOUND_PHRASE_TAG, BOUND_SECOND_TAG, PARTICLE_GIVEN_TAG, PATRONYMIC_TAG, SHAPE_ACRONYM_TAG, SHARED_NAME_TAG, SPLIT_CREDENTIAL_TAG, SPLIT_MEMBER_TAG, TITLE_AMBIGUOUS_TAG, TITLE_CASE_NAME_TAG, CHAIN_TITLE_TAG, DOTTED_TITLE_TAG, JOINED_TITLE_TAG, TRAILING_TITLE_TAG, ParseState, @@ -656,7 +658,7 @@ def classify(state: ParseState) -> ParseState: if tags != written[i].tags: written[i] = copy_with(written[i], tags=tags) tokens = tuple(written) - # rules/P12: "the two words are one name unit past the first name word" + # rules/P12: "the two words are one name unit, past the first name word" # -- the phrase test over each word and the word after it, asked # only of a name holding a bound word, in a plain loop, so that no # other name pays a frame; the tag goes on the bound word, and @@ -693,6 +695,37 @@ def classify(state: ParseState) -> ParseState: tokens = tuple( copy_with(t, tags=t.tags | {BOUND_PHRASE_TAG}) if i in heads else t for i, t in enumerate(tokens)) + # rules/P12: "for a pair read from its second word, at it too" -- a word of + # Lexicon.bound_seconds joins the plain word before it, and a pair of + # Lexicon.bound_second_phrases joins whole, wherever it stands, the + # first name word included; a name of two name words is split back + # once roles are settled (post_rules), as P5's reserve keeps a bound + # word's pair there (decisions/P12, #1072) + seconds = sets.bound_seconds + if not seconds.isdisjoint(folded): + second_phrases = sets.bound_second_phrases + listed = sets.bound_seconds_listed + back = [] + for i in range(len(folded) - 1): + before, after = tokens[i], tokens[i + 1] + # a word carrying a role (a delimited clause) is in no + # piece group joins, so its tag would be read by nothing + if (folded[i + 1] not in seconds or i in stemmed + or after.tags - _CONTESTED_TAGS + # no pair is written across a comma + or any(before.span.end <= c < after.span.start + for c in state.comma_offsets)): + continue + if f"{folded[i]} {folded[i + 1]}" not in second_phrases and ( + folded[i + 1] in listed or before.tags + or not _HAS_LETTER.search(before.text)): + continue + back.append(i) + if back: + tokens = tuple( + copy_with(t, tags=t.tags | {BOUND_PHRASE_TAG, + BOUND_SECOND_TAG}) + if i in back else t for i, t in enumerate(tokens)) # rules/S12: "a credential written split across a space reads as one # word" -- each adjacent pair of a segment asked once, here, and # the answer written on its first word for group's merge and the diff --git a/nameparser/_pipeline/_group.py b/nameparser/_pipeline/_group.py index 8bdc94e4b..4661a0f08 100644 --- a/nameparser/_pipeline/_group.py +++ b/nameparser/_pipeline/_group.py @@ -27,8 +27,9 @@ the bound-given join, and split off so neither reaches it (#614), which assign places and reports rather than peeling again; and, last in each part, P12's join past the start of a listed pair, or of a -`completes_any` bound word and the plain word after it (#1464), the -classify tag left only on the bound word of a pair it joined (#694). +`completes_any` bound word and the plain word after it (#1464), and of a +pair read from its listed second word at the start too (#1072), the +classify tag left only on the first word of a pair it joined (#694). Reads: token tags (from classify), Lexicon.given_name_titles (the P5 licence, #369), Policy.name_order (rules/P13's joins at the end of a name read given-first, #1098) and Policy.extra_suffix_delimiters, whose @@ -88,7 +89,7 @@ trailing_start_past_titles, ) from nameparser._pipeline._state import ( - AMBIGUOUS_ACRONYM_TAG, BOUND_PHRASE_TAG, SPLIT_CREDENTIAL_TAG, + AMBIGUOUS_ACRONYM_TAG, BOUND_PHRASE_TAG, BOUND_SECOND_TAG, SPLIT_CREDENTIAL_TAG, SPLIT_MEMBER_TAG, TRAILING_TITLE_TAG, ParseState, Deferred, PendingAmbiguity, Structure, WorkToken, _AMBIGUOUS_CREDENTIAL_TAGS, copy_with, @@ -718,17 +719,23 @@ def _settle_splits(pieces: list[Piece], ptags: list[set[str]]) -> None: k += 1 -# rules/P12: "the two words are one name unit past the first name word" +# rules/P12: "the two words are one name unit, past the first name word" # -- past the piece P5's leading join reads, which this leaves as it -# was, its reserve included; classify's tag says the word and the -# token after it are a listed phrase, or a `completes_any` bound word -# before a plain word (history: decisions/P12, #694, #1464) +# was, its reserve included, save a pair read from its second word, +# which joins there too; classify's tag says the word and the token +# after it are a listed phrase, a `completes_any` bound word before a +# plain word, or a plain word before a listed second word (history: +# decisions/P12, #694, #1464, #1072) def _join_bound_phrases(pieces: list[Piece], ptags: list[set[str]], tokens: Sequence[WorkToken], joined_heads: set[int]) -> None: # built in one pass: a merge per pair would shift every piece # behind it, a quadratic in a run of pairs (merge_pieces' note) - k = leading_titles(pieces, ptags, tokens) + 1 + k = leading_titles(pieces, ptags, tokens) + # P5's first word, save a pair joined from its second word, which + # joins there too (#1072) + if not (k < len(pieces) and BOUND_SECOND_TAG in tokens[pieces[k][0]].tags): + k += 1 out, out_tags = pieces[:k], ptags[:k] n = len(pieces) joined = False @@ -1633,6 +1640,10 @@ def group(state: ParseState) -> ParseState: # pair a chain or a comma kept apart, count as two for i in part: if BOUND_PHRASE_TAG in tokens[i].tags and i not in heads: + # BOUND_SECOND_TAG stays, as `vocab:bound-given` + # does: the unit readers count the pair by it + # where no join was made, before a family comma + # (#1072) tokens[i] = copy_with( tokens[i], tags=tokens[i].tags - {BOUND_PHRASE_TAG}) pieces.extend(part_pieces) diff --git a/nameparser/_pipeline/_post_rules.py b/nameparser/_pipeline/_post_rules.py index a6c01883d..3f58e95b3 100644 --- a/nameparser/_pipeline/_post_rules.py +++ b/nameparser/_pipeline/_post_rules.py @@ -63,6 +63,7 @@ from __future__ import annotations import bisect +import dataclasses from collections.abc import Sequence from nameparser._lexicon import Lexicon, _normalize, _run_addresses_by_given @@ -77,7 +78,7 @@ AMBIGUOUS_ACRONYM_TAG, ATTACHED_TAG, CAPITALS_FAMILY_TAG, COMMA_CHARS, COMMA_STRIP, NAME_ROLES, PATRONYMIC_TAG, - BOUND_PHRASE_TAG, PARTICLE_GIVEN_TAG, PAST_REACH_TAG, SHARED_NAME_TAG, + BOUND_PHRASE_TAG, BOUND_SECOND_TAG, PARTICLE_GIVEN_TAG, PAST_REACH_TAG, SHARED_NAME_TAG, FIRST_SURNAME_TAG, SECOND_SURNAME_TAG, SURNAME_PAIR_TAG, ParseState, PendingAmbiguity, PendingReading, Structure, WorkToken, _NEVER_FLIPPED, comma_bucket, copy_with, reported_suffix_fork, @@ -263,6 +264,58 @@ def _retag(tokens: list[WorkToken], i: int, role: Role) -> None: tokens[i] = copy_with(tokens[i], role=role) +def _split_a_lone_backward_pair(state: ParseState, tokens: list[WorkToken], + ambiguities: list[PendingAmbiguity]) -> bool: + """A pair P12 joined from its second word that holds every name word + the parse read is split back, in place: its first word takes the + order's first position and its second the order's other name role, + as P5's reserve leaves a bound word's pair of two name words, and + the one-word report assign made of it is withdrawn. True where it + split one.""" + # the caller has found the two name words adjacent, the first + # carrying the pair's tag + first = next(i for i, t in enumerate(tokens) + if t.role in (Role.GIVEN, Role.MIDDLE, Role.FAMILY)) + second = first + 1 + # rules/P5's two exceptions to its reserve, read alike: after a + # family comma the family is fixed and the pair is the given name, + # and a given-name title asserts that a given name follows + if (state.structure is Structure.FAMILY_COMMA and state.comma_offsets + and tokens[first].span.start > state.comma_offsets[0]): + return False + titles = [i for i, t in enumerate(tokens[:first]) if t.role is Role.TITLE] + if titles and _run_addresses_by_given( + (tokens[i].text for i in _addressing_run(titles, first)), + state.lexicon._sets.given_name_titles): + return False + order = state.order or state.policy.name_order + other = order[2] if order[1] is Role.MIDDLE else order[1] + tokens[first] = copy_with( + tokens[first], role=order[0], + tags=tokens[first].tags - {BOUND_PHRASE_TAG, BOUND_SECOND_TAG}) + _retag(tokens, second, other) + ambiguities[:] = [a for a in ambiguities + if not (a.kind is AmbiguityKind.GIVEN_OR_FAMILY + and {first, second} & set(a.indices))] + # a report on a later word named the field it would take beside ONE + # name unit; beside two, under a family-first order with the given + # name second, that word would be the third, the middle (assemble + # folds it into the family under middle_as_family); a word after a + # comma names the given name for the comma's other reading, which + # no count of units moves + if order[0] is Role.FAMILY and order[1] is Role.GIVEN: + comma = state.comma_offsets[0] if state.comma_offsets else None + for k, a in enumerate(ambiguities): + alt = a.alternative + if (alt is not None and alt.role is Role.GIVEN and a.indices + and min(a.indices) > second + and (comma is None + or tokens[max(a.indices)].span.start < comma)): + ambiguities[k] = dataclasses.replace( + a, alternative=dataclasses.replace(alt, role=Role.MIDDLE)) + return True + + # rules/P2: "a particle joins the words after it into one name # part, the join running until the next particle starts a group of # its own, a trailing suffix begins" @@ -287,7 +340,8 @@ def _units(tokens: list[WorkToken], idx: list[int]) -> list[list[int]]: lone-piece site test would not fire at all.) The bound-given join grouping never built at all: P5 joins only where the bound word is the first non-title piece, save a listed two-word given name P12 - joins past the first name word (#694), and at a fold site the first piece + joins past the first name word (#694) and a pair P12 joins from + its listed second word (#1072), and at a fold site the first piece is the particle -- "ibn Awf abdul Rahman" reaches here as four separate pieces. The tag is the only witness in both cases. @@ -327,8 +381,8 @@ def _family_word_count(tokens: list[WorkToken], family: list[int], as one, as the word O6 takes is counted (#959). A bound word counts with the word that completes it, the pair P12 joins being one name ('عبد الله', #694).""" - # rules/P12: "the two words are one name unit past the first name word" - # -- so the bound word counts with the word after it + # rules/P12: "the two words are one name unit, past the first name word" + # -- so the pair's first word counts with the word after it words = sum(1 if hyphen_joins else len([part for part in _HYPHENS.split(tokens[i].text) if part]) @@ -824,7 +878,10 @@ def _divide_family(tokens: list[WorkToken], family: list[int], bare = False if not completes: named += 1 - completes = "vocab:bound-given" in tag + # the word before is a bound given-name word, or the first + # word of a pair joined from its second (#1072) + completes = ("vocab:bound-given" in tag + or BOUND_SECOND_TAG in tag) if named > 1 or bare and (len(unit) > 1 or unit is first): return False _mark_surname(tokens, sorted(first + attached), FIRST_SURNAME_TAG) @@ -1326,6 +1383,16 @@ def post_rules(state: ParseState) -> ParseState: _set_apart_clauses(state, tokens) _report_delimited_members(tokens, state.lexicon, ambiguities) titles, givens, middles, families = _positions(tokens) + # rules/P12: "A pair read from its second word needs a third name + # word" -- asked of the parse, once roles are settled, so the + # trailing run's reading is the one counted (decisions/P12, #1072) + # the tag test inline, in C, so that a name of two words with no + # such pair pays no frame for it + names = givens + middles + families + if (len(names) == 2 and max(names) == min(names) + 1 + and BOUND_SECOND_TAG in tokens[min(names)].tags + and _split_a_lone_backward_pair(state, tokens, ambiguities)): + titles, givens, middles, families = _positions(tokens) # rules/H1: "a title followed by exactly one name word makes # that word the family name, whatever suffix, nickname or maiden diff --git a/nameparser/_pipeline/_state.py b/nameparser/_pipeline/_state.py index 8e76324a3..05a847e8b 100644 --- a/nameparser/_pipeline/_state.py +++ b/nameparser/_pipeline/_state.py @@ -265,6 +265,12 @@ def reported_suffix_fork(ambiguities: Sequence[PendingAmbiguity], #: it joined. Dropped from the published token like the kind tags #: above (#694). BOUND_PHRASE_TAG = "vocab:bound-phrase" +#: On the first word of a pair joined backward, from a word of +#: `Lexicon.bound_seconds` or a pair of `Lexicon.bound_second_phrases` +#: ('عز' before 'الدين'), beside BOUND_PHRASE_TAG: group joins such a +#: pair at the first name word too (rules/P12, #1072). Dropped from the +#: published token like the kind tags above. +BOUND_SECOND_TAG = "vocab:bound-second" #: rules/O9 ("the capitals settle the field"): a word in capitals that #: Policy.capitals_as_family read as the family, written by post_rules, #: so assemble reads its reading as the shape's (a word in capitals) diff --git a/nameparser/_pipeline/_vocab.py b/nameparser/_pipeline/_vocab.py index 7aa4307d8..bb7f9d753 100644 --- a/nameparser/_pipeline/_vocab.py +++ b/nameparser/_pipeline/_vocab.py @@ -2339,9 +2339,10 @@ def unit_ends(tags: Sequence[Set[str]], chain: bool = True) -> list[int]: order, partitioning `range(len(tags))`: one name word each, except where another rule has already made several words one name -- a particle and the words it chains (P2), a conjunction-joined run - (P3), and a bound given-name word with the word it completes (P5). - Each element is the tag set of one token, read for "particle", - "conjunction", "vocab:bound-given" and "vocab:suffix". + (P3), a bound given-name word with the word it completes (P5), and + a pair P12 joined from its second word (#1072). Each element is the + tag set of one token, read for "particle", "conjunction", + "vocab:bound-given", "vocab:bound-second" and "vocab:suffix". `chain` picks how far a particle reaches. True is P2's chain: the particle run and every word after it up to the next stop ("van der @@ -2386,6 +2387,10 @@ def end_of(i: int) -> int: end = i + 1 if "vocab:bound-given" in tags[i] and end < n: end = end_of(end) + elif "vocab:bound-second" in tags[i] and end < n: + # a pair joined from its second word: the word and the + # one word after it (rules/P12, #1072) + end += 1 while end + 1 < n and "conjunction" in tags[end]: end = end_of(end + 1) return end diff --git a/nameparser/_reading_index.py b/nameparser/_reading_index.py index 50599e5b1..095fb023e 100644 --- a/nameparser/_reading_index.py +++ b/nameparser/_reading_index.py @@ -39,7 +39,8 @@ #: feeds. For title, suffix, particle and conjunction, the category's own #: name is also a kind (`title = {}`: a title not yet classified), so #: classifying a word later moves no set. bound_given's one kind shares -#: its category's name; the relation (birth_marker) and name (given, +#: its category's name, and so does bound_second's, the word a bound +#: pair writes second and joins from (rules/P12, #1072); the relation (birth_marker) and name (given, #: family) categories have no generic kind. Kind #: names are unique across categories; a fine kind arrives with its #: category's classification, in a core PR, as one row here. The @@ -85,6 +86,7 @@ "alias": "particle", "conjunction": "conjunction", "bound_given": "bound_given", + "bound_second": "bound_second", "birth_marker": "relation", "given": "name", "family": "name", @@ -124,6 +126,7 @@ "conjunction": frozenset({"may_be_initial", "cased", "default"}), "bound_given": frozenset({"completed_by", "completes_any", "cased", "default", "long_names_only"}), + "bound_second": frozenset({"completes", "cased", "default"}), "relation": frozenset({"cased", "default"}), "name": frozenset({"after_particle", "cased", "default", "shared"}), "familiar": frozenset({"default"}), @@ -667,6 +670,9 @@ class Compiled(TypedDict): BOUND_PHRASES: frozenset[str] BOUND_COMPLETES_ANY: frozenset[str] BOUND_LONG_NAMES_ONLY: frozenset[str] + BOUND_SECONDS: frozenset[str] + BOUND_SECOND_PHRASES: frozenset[str] + BOUND_SECONDS_LISTED: frozenset[str] SAME_AS: dict[str, dict[str, tuple[str, ...]]] SAME_AS_NAMED: dict[str, frozenset[str]] FAMILIAR: dict[str, tuple[str, ...]] @@ -724,6 +730,9 @@ def compile_readings(readings: Iterable[ReadingProperties]) -> Compiled: bound_phrases: set[str] = set() completes_any: set[str] = set() long_names_only: set[str] = set() + seconds: set[str] = set() + second_phrases: set[str] = set() + open_seconds: set[str] = set() cased: dict[str, str] = {} same_as: dict[str, dict[str, set[str]]] = { g: {} for g in SAME_AS_GROUPS.values()} @@ -812,6 +821,12 @@ def compile_readings(readings: Iterable[ReadingProperties]) -> Compiled: completes_any.add(t) if r.flag("long_names_only"): long_names_only.add(t) + elif category == "bound_second": + seconds.add(t) + if p.get("completes"): + second_phrases.update(f"{w} {t}" for w in p["completes"]) + else: + open_seconds.add(t) elif category == "relation": markers.add(t) contested = titles & given - particles @@ -919,6 +934,17 @@ def compile_readings(readings: Iterable[ReadingProperties]) -> Compiled: # only in a name of four words or more (#1464) BOUND_COMPLETES_ANY=frozenset(completes_any), BOUND_LONG_NAMES_ONLY=frozenset(long_names_only), + # the bound_second readings, the word a bound pair writes second + # and joins from, and the pairs those written `completes` list + # ('ذو الغنى'), the only ones such a word joins: one with no + # `completes` joins behind any plain word, at the first name + # word too (rules/P12, #1072) + BOUND_SECONDS=frozenset(seconds), + BOUND_SECOND_PHRASES=frozenset(second_phrases), + # the words every reading of which lists `completes`: those join + # behind their listed words alone, where one reading listing none + # joins behind any plain word + BOUND_SECONDS_LISTED=frozenset(seconds - open_seconds), # every reading's `same_as` in the group of its kind: the words # it is a listed spelling of (`wm` of `william` among given # names, `junior` of `jr` among suffixes, `sr` of both `señor` diff --git a/nameparser/config/_compiled.py b/nameparser/config/_compiled.py index a54f6e234..b9092a9a9 100644 --- a/nameparser/config/_compiled.py +++ b/nameparser/config/_compiled.py @@ -4685,6 +4685,26 @@ 'abdul', }) +BOUND_SECONDS: frozenset[str] = frozenset({ + 'الدين', + 'الدین', + 'الغنى', + 'الفقار', + 'الله', + 'اللہ', + 'اله', +}) + +BOUND_SECOND_PHRASES: frozenset[str] = frozenset({ + 'ذو الغنى', + 'ذو الفقار', +}) + +BOUND_SECONDS_LISTED: frozenset[str] = frozenset({ + 'الغنى', + 'الفقار', +}) + SAME_AS: dict[str, dict[str, tuple[str, ...]]] = { 'family': { 'ad-': ('al-',), diff --git a/nameparser/config/_index.py b/nameparser/config/_index.py index c27b04cbe..8ea52245d 100644 --- a/nameparser/config/_index.py +++ b/nameparser/config/_index.py @@ -3040,16 +3040,23 @@ ('الحاجة', (('ar', 'religious', (('addresses', 'given'),)),)), ('الدكتور', (('ar', 'academic', (('addresses', 'given'),)),)), ('الدكتورة', (('ar', 'academic', (('addresses', 'given'),)),)), + ('الدين', (('ar', 'bound_second', ()),)), ('الدکتور', (('ar', 'academic', (('addresses', 'given'), ('same_as', 'الدكتور'))),)), ('الدکتورة', (('ar', 'academic', (('addresses', 'given'), ('same_as', 'الدكتورة'))),)), + ('الدین', (('fa', 'bound_second', (('same_as', 'الدين'),)),)), ('السفيرة', (('ar', 'office', (('addresses', 'given'),)),)), ('الشيخ', (('ar', 'style', (('addresses', 'given'),)),)), ('الشيخة', (('ar', 'style', (('addresses', 'given'),)),)), ('الشیخ', (('ar', 'style', (('addresses', 'given'), ('same_as', 'الشيخ'))),)), ('الشیخة', (('ar', 'style', (('addresses', 'given'), ('same_as', 'الشيخة'))),)), + ('الغنى', (('ar', 'bound_second', (('completes', ('ذو',)),)),)), + ('الفقار', (('ar', 'bound_second', (('completes', ('ذو',)),)),)), + ('الله', (('ar', 'bound_second', ()),)), ('اللواء', (('ar', 'military', (('addresses', 'given'),)),)), + ('اللہ', (('ur', 'bound_second', (('same_as', 'الله'),)),)), ('المستشار', (('ar', 'office', (('addresses', 'given'),)),)), ('المستشارة', (('ar', 'office', (('addresses', 'given'),)),)), + ('اله', (('fa', 'bound_second', (('same_as', 'الله'),)),)), ('ام', (('ar', 'bound_given', (('same_as', 'أم'),)),)), ('بن', (('ar', 'patronymic', ()),)), ('بنت', (('ar', 'patronymic', ()),)), diff --git a/nameparser/vocab/AGENTS.md b/nameparser/vocab/AGENTS.md index 740e20ca5..b255d0e39 100644 --- a/nameparser/vocab/AGENTS.md +++ b/nameparser/vocab/AGENTS.md @@ -59,3 +59,7 @@ Every strict choice reads `mul.toml` (#1005), so a word there is read in names o ## A reading taken out: what it used to override Taking a reading out of a word, by a `remove` in a pack's fragment or by moving it between files, leaves the readings it used to override to act, the word's own others and its neighbours', and a grid in mixed case does not show it. #1108's fragment took `van`'s particle reading out under `locales.VI`, and `NGUYEN VAN DO` then read suffix 'DO': the `van` chain had kept `DO`'s credential reading from ending the name, and only the code review's one-case row found it, every grid row being mixed case or a syllable no file holds. List every reading the word and the words it chained keep (`uv run python tools/vocab/query.py --word `), and parse each removed word with the word it used to absorb ending the name, in one case, beside a mixed-case control; then parse it after a family comma, where an order a pack sets reads nothing differently and the removal still acts (`Beethoven, Ludwig van` under `locales.VI`, found by #1108's second design-docs review). Put a removed particle in the family before a comma in the grid too, with a short given name and with initials after the comma: it had kept the given part from reading as a credential, and #1231's `locales.MY`, under the fragment #1483 later dropped for a strict choice, read `Van Buren, Ed` given 'Van', suffix 'Ed' and `De La Cruz, M.J. K.L.` suffix 'M.J. K.L.', found only by its last reviews. And before proposing a name reading to settle a clash under a language choice, check that the reading is a vocabulary one: `choose` prefers only by those, and a `given` or `family` reading never settles (decision 15 of decisions/vocabulary-model), the premise #1108 was filed on. + +## Placing an entry: the familiar tool's block + +A file holding familiar forms or spellings ends in a block `tools/vocab/familiar.py` writes, opening with `# -- BEGIN generated by tools/vocab/familiar.py` and holding only `familiar` and `spelling` readings. The build's order (check 10, by kind and then text) can put a new entry after every hand-written one, and appending it there puts it below the BEGIN marker, where the tool's next run (or `test_familiar_tool.py`, which runs it) deletes it: #1072's first `bound_second` entries in `ar.toml` and `fa.toml` went there. Put a new entry above the marker, and run `uv run python tools/vocab/familiar.py --check` after editing a file that holds one. diff --git a/nameparser/vocab/README.md b/nameparser/vocab/README.md index 88c3144bb..11be0254e 100644 --- a/nameparser/vocab/README.md +++ b/nameparser/vocab/README.md @@ -129,6 +129,7 @@ A reading's key is its **kind**. The table lists the kinds in their canonical or | `alias` | `particle` | `PARTICLES` | | `conjunction` | `conjunction` | `CONJUNCTIONS` | | `bound_given` | `bound_given` | `BOUND_GIVEN_NAMES` | +| `bound_second` | `bound_second` | `BOUND_SECONDS` | | `birth_marker` | `relation` | `MAIDEN_MARKERS` | | `given` | `name` | nothing | | `family` | `name` | nothing | @@ -194,19 +195,20 @@ A property is **behavioral** when it compiles into a set and so changes how name | `completed_by` | behavioral | `bound_given` | none | `BOUND_PHRASES`: the words that complete the bound given name into one name unit past the first name word, a list (`completed_by = ["الله", "الرحمن"]` on `عبد`), each one word written folded: `سعيد عبد الله` reads family `عبد الله` ([rules/P12](../../docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md), a bound given name and the word that completes it), while a word left off the list after it is a name of its own, as in `نوال عبد هاشم` (#694) | | `completes_any` | behavioral | `bound_given` | false | `BOUND_COMPLETES_ANY`: the bound given name completes with any plain name word after it past the first name word, one with no vocabulary reading and no initial's shape, the pair one name unit that position places, family where it ends the name and one middle name inside it: `Tariq Abdel Aziz` reads family `Abdel Aziz` ([rules/P12](../../docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md)), written on the Latin spellings, which name no word after them (#1464) | | `long_names_only` | behavioral | `bound_given` | false | `BOUND_LONG_NAMES_ONLY`, a subset of `BOUND_COMPLETES_ANY`: narrows `completes_any`, which it needs beside it (the build refuses it alone; a caller's `add` of it alone is inert), to a name of four name words or more, a title and a suffix word counting as none, so a three-word name keeps the bound word apart: `Tariq Abdul Aziz` reads middle `Abdul` ([rules/P12](../../docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md)), written on `abdul`, whose three-word names are split both ways by population (#1464) | +| `completes` | behavioral | `bound_second` | none | `BOUND_SECOND_PHRASES`, and the word into `BOUND_SECONDS_LISTED` where no reading of it leaves `completes` unwritten: the first words a `bound_second` word completes, a list (`completes = ["ذو"]` on `الغنى`), each one word written folded; written, the word joins behind those alone (`عائشة ذو الغنى` reads family `ذو الغنى`), and unwritten, behind any plain word ([rules/P12](../../docs/design/rules/P12-bound-given-name-and-the-word-that-completes-it.md), #1072) | | `dotted` | behavioral | `title` | false | `DOTTED_TITLES`: the title abbreviates several words and is written with a full stop after each letter (`us`, `uk`, German `pd`), so a run of single letters joined by full stops that spells it is that title at the head of a name where a title the name keeps follows it, as in `U.S. District Judge Marc Treadwell`, and the initials it is written as otherwise (`U.S. Grant`) ([rules/H10](../../docs/design/rules/H10-title-written-as-a-run-of-letters.md), a title written as a run of letters). A title abbreviating one word (`dr`, `mr`, `lt`) is left unmarked, since two initials spell it (`D.R. Judge Smith` reads given 'D.', middle 'R. Judge', its given names 'D.R. Judge', no title) | | `capital_opening` | behavioral | `particle` | false | `CAPITAL_OPENING_PARTICLES`: the particle is written with a capital where the word before it in the family name is no particle, nor, where it opens the family name, the word written right before it in any role (`Van der Walt` keeps its lowercase `der`), as the Armenian priestly prefix is (`ter` and `der`: `LEVON TER PETROSYAN` repairs to `Levon Ter Petrosyan`), and keeps its lowercase after one (`Jan van der Berg`) ([rules/R12](../../docs/design/rules/R12-particle-opening-the-family-name-with-a-capital.md), a particle opening the family name with a capital); it moves no parse. A Dutch surname opened by `ter` takes the capital too (`Gerard Ter Borch`), a cost accepted in decisions/R12 | | `may_be_given` | stated | `particle` | none: required where the word has no `given` reading | `false` is required where the word has no `given` reading in any file, and that absence, not the property, is what puts the word in `NON_GIVEN_NAME_PARTICLES`: a particle opening the name starts the family name ([rules/P1](../../docs/design/rules/P1-lone-particle-fold.md), the lone particle fold). `true` is refused, naming the `given` reading to write instead (check 11) | | `may_be_initial` | behavioral | `conjunction` | false | `CONJUNCTIONS_AMBIGUOUS`, on a cased single letter only: read as an initial in a name written in one case, as in `JOHN E SMITH` ([rules/P8](../../docs/design/rules/P8-single-letter-connective-against-the-initial-it-spells.md), a single-letter connective against the initial it spells) | -| `default` | behavioral | `title`, `suffix`, `particle`, `conjunction`, `bound_given`, `relation`, `name`, `familiar`, `spelling` | true | `false` keeps the reading out of every compiled set, `SUFFIX_WORDS` and `GENERATION_WORDS` included for a generation: recorded and checked as a reading, for a choice of languages to turn on (3.0's phase 3), where its writing offers the default no cue (`i`, the German regnal ordinal, written `I.`, exactly as an initial is). An exclusion does not refuse it, and it cannot read two ways beside the word's live readings (checks 4 to 6); a name reading beside it marks nothing. On a `given` or `family` reading (3.0's phase 3a) it derives no marker in the default, so the word's other readings compile as they would without it, until a pack turns the name on. It does not count as the name reading an agnomen on by default needs (check 11), and a particle whose word's only `given` readings are off is refused, which side of check 11 it takes being left to the first pack that needs one; a bound given name that is also a particle is refused with it, before check 9 would ask for its `given` reading. `true` is refused: it is what every reading is unwritten | -| `cased` | behavioral | `title`, `suffix`, `particle`, `conjunction`, `bound_given`, `relation`, `name` | the word as written | `CAPITALIZATION_EXCEPTIONS`: the case `capitalized()` gives the word (`PhD`), a mask over its letters and digits, never a replacement (#459); on a name reading, a name whose capitals case repair cannot work out from its spelling (`MacGregor`, #1014) | +| `default` | behavioral | `title`, `suffix`, `particle`, `conjunction`, `bound_given`, `bound_second`, `relation`, `name`, `familiar`, `spelling` | true | `false` keeps the reading out of every compiled set, `SUFFIX_WORDS` and `GENERATION_WORDS` included for a generation: recorded and checked as a reading, for a choice of languages to turn on (3.0's phase 3), where its writing offers the default no cue (`i`, the German regnal ordinal, written `I.`, exactly as an initial is). An exclusion does not refuse it, and it cannot read two ways beside the word's live readings (checks 4 to 6); a name reading beside it marks nothing. On a `given` or `family` reading (3.0's phase 3a) it derives no marker in the default, so the word's other readings compile as they would without it, until a pack turns the name on. It does not count as the name reading an agnomen on by default needs (check 11), and a particle whose word's only `given` readings are off is refused, which side of check 11 it takes being left to the first pack that needs one; a bound given name that is also a particle is refused with it, before check 9 would ask for its `given` reading. `true` is refused: it is what every reading is unwritten | +| `cased` | behavioral | `title`, `suffix`, `particle`, `conjunction`, `bound_given`, `bound_second`, `relation`, `name` | the word as written | `CAPITALIZATION_EXCEPTIONS`: the case `capitalized()` gives the word (`PhD`), a mask over its letters and digits, never a replacement (#459); on a name reading, a name whose capitals case repair cannot work out from its spelling (`MacGregor`, #1014) | | `short_for` | matching | `familiar` | none: required | `FAMILIAR`: the longer given names the word stands for, a non-empty list of single words written normalized, never the word itself (`max = { short_for = ["maximilian", "maxwell"] }`), read by the name match alone: where `familiar-form` is accepted, `Max Smith` and `Maximilian Smith` are consistent, and `Maximilian Smith` and `Maxwell Smith` are not: the match reads a pair whichever way it is written (`barbara = { short_for = ["babs"] }` matches as its reverse would) and never chains two pairs. An `add(w, kind="familiar", short_for=[...])` extends the longer names the word's readings list, in a reading of the caller's own that names no file; a pair is stored on the word whose reading lists the other and removed from either: `remove(w, kind="familiar", short_for=[name])` cuts the one pair, either name first, and `remove(w, kind="familiar")` every pair naming `w`, on whichever word it is stored, each name compared by its folded forms as the match reads it (decisions/name-matching, 2026-11-15 #1404); a `spelling` reading's pairs go the same way, by `spelling_of`. A `familiar` reading needs a `note` saying where the pair is attested, and takes no `same_as`, `expands`, `native` or `gender` | | `spelling_of` | matching | `spelling` | none: required | `ALTERNATE_SPELLINGS`: the given names the word is another spelling of, a non-empty list of single words written normalized, never the word itself (`olha = { spelling_of = ["olga"] }`), read by the name match alone as the opt-in `alternate-spelling`: where it is accepted, `Olha Petrenko` and `Olga Petrenko` are consistent. Unlike a `given` reading's `same_as`, it gives the word no name reading and puts it in no set a parse reads (`GIVEN_NAME_ABBREVIATIONS` among them), so `Olha. Petrenko` parses as it did. A pair is read either way and never chained, as a familiar form is. An `add(w, kind="spelling", spelling_of=[...])` extends the word's names in a reading of the caller's own. A `spelling` reading needs a `note` saying where the pair is attested, and takes no `same_as`, `expands`, `native` or `gender` | | `note` | descriptive | every category, a `name` reading included | | free text: why the reading is as it is | | `issue` | descriptive | every category but `name` | | an issue number, or a list of them | | `decided` | descriptive | every category but `name` | | a TOML date | | `expands` | descriptive | every category but `name`, `familiar` and `spelling` | | the meaning the entry was added for, not every meaning | -| `same_as` | descriptive | every category but `familiar` and `spelling` | | another word of the same category that this one is a spelling of (`jnr` is `jr`), or a list of them, each once, where the word is a spelling of several (`md = { same_as = ["muhammad", "mohammad", "mohammed", "mohamed"] }`, #1383), the first placing the entry in its file's order; every reading's `same_as` compiles into `SAME_AS`, keyed by the group of its kind (`given` for a given name or a bound given name, `family` for a surname or a particle, `title`, `suffix`; a conjunction's and a birth marker's into none), each word with every full form it carries there: the map `Lexicon` reads for the name match, which reads two words of one role as listed spellings where the words reachable from each through that role's group meet (`Wm.` and `William` as given names, `Jr.` and `Junior` as suffixes, `Ma.` and `María` as given names but never as surnames, `ma` being a given name of its own too, which the match reads as `María` only written with its period: `SAME_AS_NAMED`, a [derived marker](#derived-markers)), and which moves no word between sets; on a `given` reading, the full given name the word abbreviates, which also compiles the word into `GIVEN_NAME_ABBREVIATIONS` (see [Name readings](#name-readings)) | +| `same_as` | descriptive | every category but `familiar` and `spelling` | | another word of the same category that this one is a spelling of (`jnr` is `jr`), or a list of them, each once, where the word is a spelling of several (`md = { same_as = ["muhammad", "mohammad", "mohammed", "mohamed"] }`, #1383), the first placing the entry in its file's order; every reading's `same_as` compiles into `SAME_AS`, keyed by the group of its kind (`given` for a given name or a bound given name, `family` for a surname or a particle, `title`, `suffix`; a conjunction's, a birth marker's and a bound second word's into none), each word with every full form it carries there: the map `Lexicon` reads for the name match, which reads two words of one role as listed spellings where the words reachable from each through that role's group meet (`Wm.` and `William` as given names, `Jr.` and `Junior` as suffixes, `Ma.` and `María` as given names but never as surnames, `ma` being a given name of its own too, which the match reads as `María` only written with its period: `SAME_AS_NAMED`, a [derived marker](#derived-markers)), and which moves no word between sets; on a `given` reading, the full given name the word abbreviates, which also compiles the word into `GIVEN_NAME_ABBREVIATIONS` (see [Name readings](#name-readings)) | | `native` | descriptive | every category but `familiar` and `spelling`, a `name` reading included | | a native-script spelling | | `gender` | descriptive | every category but `familiar` and `spelling`, a `name` reading included | | `"f"`, `"m"` or `"n"`, only where the word gives a definitive clue | diff --git a/nameparser/vocab/ar.toml b/nameparser/vocab/ar.toml index d536d9a30..4c56a50aa 100644 --- a/nameparser/vocab/ar.toml +++ b/nameparser/vocab/ar.toml @@ -898,9 +898,25 @@ completed_by = [ "الکبیر", "الکریم", ] -note = "\"abd\" (servant of): the script writes Abdul Rahman as two words, عبد + الرحمن, the article attaching to the word after it, so عبد alone covers the abdul/abdel/abdal spellings -- عبد الرحمن -> given \"عبد الرحمن\". completed_by lists the words that make it one name unit past the first name word (rules/P12): the 97 one-word names of God, الله, 27 other divine epithets and 14 devotional completions (المطلب, النبي, الحسين, المسيح) found after it in ORCID and JRC-Names, each with its hamza-less and Persian spellings -- سعيد عبد الله -> family \"عبد الله\". An unlisted word after it is left alone: a short given name stands alone there (نوال عبد هاشم), and a nisba surname opens with the article too (عبد القريشي; 2026-11-04, #694, decisions/P12). The Latin abdul lists none: there the pair is a middle name as often as a family (decisions/P12)" +note = "\"abd\" (servant of): the script writes Abdul Rahman as two words, عبد + الرحمن, the article attaching to the word after it, so عبد alone covers the abdul/abdel/abdal spellings -- عبد الرحمن -> given \"عبد الرحمن\". completed_by lists the words that make it one name unit past the first name word (rules/P12): the 97 one-word names of God, الله, 27 other divine epithets and 14 devotional completions (المطلب, النبي, الحسين, المسيح) found after it in ORCID and JRC-Names, each with its hamza-less and Persian spellings -- سعيد عبد الله -> family \"عبد الله\". An unlisted word after it is left alone: a short given name stands alone there (نوال عبد هاشم), and a nisba surname opens with the article too (عبد القريشي; 2026-11-04, #694, decisions/P12). The Latin spellings list none, being written completes_any instead (#1464), and a word written second joins the word before it from its own bound_second reading (الدين, الله, #1072; decisions/P12)" issue = [269, 694] +[[word]] +text = "الدين" +bound_second = { expands = "of the faith", issue = 1072, note = "behind any plain word, the word before it varying (عز، نور، صلاح، علاء، سعد، ...: 70 distinct first words in the local corpora, several given names alone); the pair is the given name where it opens the name and the family where it ends it, counted in Arabic script 2026-11-19: Egypt's House 10 opening and 7 ending, all read split before; JRC-Names 73 opening and 21 ending; ORCID 38 opening and 20 ending (distinct names, a two-word name counted as opening, which the join leaves apart; decisions/P12's recipe; rules/P12, #1072)" } + +[[word]] +text = "الغنى" +bound_second = { expands = "the Self-Sufficient, a name of God", completes = ["ذو"], issue = 1072, note = "joined behind ذو alone: ذو الغنى, a given name (rules/P12, #1072)" } + +[[word]] +text = "الفقار" +bound_second = { expands = "the vertebrae, Dhu al-Fiqar", completes = ["ذو"], issue = 1072, note = "joined behind ذو alone: ذو الفقار, a given name (rules/P12, #1072)" } + +[[word]] +text = "الله" +bound_second = { expands = "God", issue = 1072, note = "behind any plain word but عبد, which P12 joins forward from its own list (فتح، نصر، شكر، فضل، ...: 99 distinct first words in the local corpora); counted in Arabic script 2026-11-19: Egypt's House 8 ending, all read split before; JRC-Names 88 opening and 28 ending; ORCID 19 opening and 21 ending (distinct names, a two-word name counted as opening, which the join leaves apart; decisions/P12's recipe; rules/P12, #1072)" } + # -- BEGIN generated by tools/vocab/familiar.py; edit the tool, not this block -- [[word]] diff --git a/nameparser/vocab/fa.toml b/nameparser/vocab/fa.toml index 87ca03553..6ed6b131e 100644 --- a/nameparser/vocab/fa.toml +++ b/nameparser/vocab/fa.toml @@ -112,6 +112,14 @@ text = "پسر" reason = "\"son\" without the article that marks ar الابن and he הבן as never a name" issue = 679 +[[word]] +text = "الدین" +bound_second = { expands = "of the faith", same_as = "الدين", issue = 1072, note = "the Persian spelling, with the Farsi yeh (rules/P12, #1072)" } + +[[word]] +text = "اله" +bound_second = { expands = "God", same_as = "الله", issue = 1072, note = "the Persian spelling with one lam, written apart in a given name (ولی اله, rules/P12, #1072)" } + # -- BEGIN generated by tools/vocab/familiar.py; edit the tool, not this block -- [[word]] diff --git a/nameparser/vocab/ur.toml b/nameparser/vocab/ur.toml index 0007c8289..0b344e976 100644 --- a/nameparser/vocab/ur.toml +++ b/nameparser/vocab/ur.toml @@ -27,3 +27,7 @@ may_be_given = false issue = 700 expands = "the, after a case ending: \"Zia ul-Haq\"" same_as = "al-" + +[[word]] +text = "اللہ" +bound_second = { expands = "God", same_as = "الله", issue = 1072, note = "the Urdu spelling, with the Urdu heh (rules/P12, #1072)" } diff --git a/tests/v2/cases.py b/tests/v2/cases.py index 84410d1c7..5b19525a7 100644 --- a/tests/v2/cases.py +++ b/tests/v2/cases.py @@ -22057,6 +22057,206 @@ def _check_cjk_shape_purity(self) -> None: {"given": "Tariq", "middle": "- Abdul", "family": "Aziz"}, notes="boundary: a mark with no letter is no name word in the " "count, so the name holds three"), + # #1072: a pair read from its listed second word (rules/P12) + Case('a_listed_second_word_opening_the_name_joins_the_given_name', + 'نور الدين سامر حداد', + {'given': 'نور الدين', 'middle': 'سامر', 'family': 'حداد'}, + classification='fix(#1072)', + notes="the pair read from الدين is the given name where it opens the name; 1.4.0 through 3.1.0 read given 'نور', middle 'الدين سامر'"), + Case('a_listed_second_word_ending_the_name_joins_the_family', + 'سامر عز الدين', + {'given': 'سامر', 'family': 'عز الدين'}, + classification='fix(#1072)', + notes="the issue's shape; 1.4.0 through 3.1.0 read middle 'عز', family 'الدين'"), + Case('allah_behind_a_word_other_than_abd_joins_it', + 'ليلى شكر الله', + {'given': 'ليلى', 'family': 'شكر الله'}, + classification='fix(#1072)', + notes="الله behind any plain word but عبد, which P12 joins forward; 1.4.0 through 3.1.0 read middle 'شكر', family 'الله'"), + Case('a_second_word_listing_its_first_joins_behind_it', + 'سامر ذو الغنى', + {'given': 'سامر', 'family': 'ذو الغنى'}, + classification='fix(#1072)', + notes="الغنى is written completes = ['ذو']; 1.4.0 through 3.1.0 read middle 'ذو', family 'الغنى'"), + Case('a_listed_pair_opening_the_name_is_the_given_name', + 'ذو الفقار سامر حداد', + {'given': 'ذو الفقار', 'middle': 'سامر', 'family': 'حداد'}, + classification='fix(#1072)', + notes="1.4.0 through 3.1.0 read given 'ذو', middle 'الفقار سامر'"), + Case('a_listed_second_word_inside_the_name_is_one_middle_name', + 'سامر نور الدين حداد', + {'given': 'سامر', 'middle': 'نور الدين', 'family': 'حداد'}, + notes='boundary: in the middle both words read right before the join'), + Case('a_listed_second_word_in_a_name_of_two_words_stays_apart', + 'عز الدين', + {'given': 'عز', 'family': 'الدين'}, + notes="boundary: a name of two words keeps its words apart, as P5's reserve does for a bound word"), + Case('a_listed_second_word_behind_a_particle_stays_apart', + 'سامر بن الله', + {'given': 'سامر', 'family': 'بن الله'}, + classification='fix(#269)', + notes='boundary: a word the vocabulary reads otherwise is no plain word to join'), + Case('the_persian_spelling_with_one_lam_joins', + 'نصر اله رضایی', + {'given': 'نصر اله', 'family': 'رضایی'}, + classification='fix(#1072)', + notes="1.4.0 through 3.1.0 read given 'نصر', middle 'اله'"), + Case('the_persian_spelling_of_al_din_joins', + 'شمس الدین رضایی', + {'given': 'شمس الدین', 'family': 'رضایی'}, + classification='fix(#1072)', + notes="the Farsi yeh; 1.4.0 through 3.1.0 read given 'شمس', middle 'الدین'"), + Case('the_urdu_spelling_of_allah_joins', + 'فضل اللہ خان', + {'given': 'فضل اللہ', 'family': 'خان'}, + classification='fix(#1072)', + notes="the Urdu heh; 1.4.0 through 3.1.0 read given 'فضل', middle 'اللہ'"), + Case('a_backward_pair_after_an_arabic_family_comma_is_the_given_name', + 'حداد، نور الدين سامر', + {'given': 'نور الدين', 'middle': 'سامر', 'family': 'حداد'}, + classification='fix(#1072)', + notes="the pair opens the given part; 1.4.0 through 3.1.0 read given 'نور', middle 'الدين سامر'"), + Case('a_backward_pair_after_an_empty_head_opens_the_given_name', + '، نور الدين سامر', + {'given': 'نور الدين', 'middle': 'سامر'}, + classification='fix(#1072)', + notes="nothing before the comma names no family (C15); 1.4.0 and 3.1.0 read given 'نور', middle 'الدين سامر'"), + Case('a_backward_pair_behind_a_title_is_the_given_name', + 'الشيخ نور الدين حداد', + {'title': 'الشيخ', 'given': 'نور الدين', 'family': 'حداد'}, + classification='fix(#1072)', + notes="the pair opens the name behind the title; 1.4.0 read given 'الشيخ', middle 'نور الدين', 3.1.0 given 'نور', middle 'الدين'"), + Case('a_backward_pair_with_a_mark_on_its_first_word_joins', + 'سامر عزّ الدين', + {'given': 'سامر', 'family': 'عزّ الدين'}, + classification='fix(#1072)', + notes="a shadda on the first word: the first word varies, so any plain word joins; 1.4.0 through 3.1.0 read middle 'عزّ', family 'الدين'"), + Case('a_second_word_written_with_a_mark_is_not_listed', + 'سامر عز الدّين', + {'given': 'سامر', 'middle': 'عز', 'family': 'الدّين'}, + notes="boundary: a second word written with its marks is not listed, as P12's completing words are not (rules/P12's Accepted)"), + Case('ayatollah_reads_as_a_given_name_the_accepted_reading', + 'آية الله سامر حداد', + {'given': 'آية الله', 'middle': 'سامر', 'family': 'حداد'}, + classification='fix(#1072)', + notes="accepted (decisions/P12, #1072): the title Ayatollah has no title reading, and a title phrase's partner must be a title word; 1.4.0 through 3.1.0 read given 'آية', middle 'الله سامر', wrong too"), + Case('a_backward_pair_under_family_first', + 'سامر عز الدين', + {'given': 'عز الدين', 'family': 'سامر'}, + policy=Policy(name_order=FAMILY_FIRST), + classification='fix(#1072)', + notes="position places the pair: given 'عز', middle 'الدين' through 3.1.0"), + Case('a_backward_pair_of_two_name_words_behind_a_title_stays_apart', + 'Dr. عز الدين', + {'title': 'Dr.', 'given': 'عز', 'family': 'الدين'}, + notes='boundary: a title is no name word in the two-word guard (code review)'), + Case('a_backward_pair_of_two_name_words_before_a_suffix_stays_apart', + 'عز الدين Jr.', + {'given': 'عز', 'family': 'الدين', 'suffix': 'Jr.'}, + notes='boundary: a suffix is no name word in the two-word guard'), + Case('a_backward_pair_before_a_family_comma_and_a_title_stays_apart', + 'عز الدين، الدكتور', + {'title': 'الدكتور', 'given': 'عز', 'family': 'الدين'}, + classification='fix(comma-family)', + notes='boundary: the part past the pair\'s comma counts as none; a comma followed only by an honorific reads it as the title since 2.2.0, as \'John Smith, Mr.\' does'), + Case('two_family_names_takes_a_backward_pair_whole', + 'سامر عز الدين حداد', + {'given': 'سامر', 'family': 'عز الدين حداد'}, + policy=_TWO, classification='fix(#1072)', + notes='O6 counts the pair one unit, as it counts عبد الله; read middle \'عز\', family \'الدين حداد\' through 3.1.0'), + Case('p1s_family_first_fold_keeps_a_backward_pair_whole', + 'آل عز الدين سامر', + {'given': 'سامر', 'family': 'آل عز الدين'}, + policy=Policy(name_order=FAMILY_FIRST), classification='fix(#1072)', + notes='the fold takes the particle and one unit, the pair; read family \'آل عز\', given \'الدين\' through 3.1.0'), + Case('a_backward_pair_of_two_name_words_before_a_maiden_clause_stays_apart', + 'عز الدين née حداد', + {'given': 'عز', 'family': 'الدين', 'maiden': 'حداد'}, + classification='fix(#274)', + notes='boundary: the maiden clause is no name word in the guard (test review)'), + Case('a_backward_pair_of_two_name_words_beside_a_nickname_stays_apart', + 'عز الدين (نور)', + {'given': 'عز', 'family': 'الدين', 'nickname': 'نور'}, + notes='boundary: a nickname is no name word in the guard'), + Case('a_second_word_listing_its_first_joins_no_other_word', + 'سامر نور الغنى', + {'given': 'سامر', 'middle': 'نور', 'family': 'الغنى'}, + notes='boundary: الغنى joins behind ذو alone'), + Case('a_second_word_listing_its_first_joins_no_other_word_opening', + 'نور الغنى سامر حداد', + {'given': 'نور', 'middle': 'الغنى سامر', 'family': 'حداد'}, + notes='boundary: the opening twin'), + Case('a_mark_with_no_letter_completes_no_second_word', + 'سامر حداد - الدين', + {'given': 'سامر', 'middle': 'حداد -', 'family': 'الدين'}, + notes='boundary: a mark is no plain word to join'), + Case('a_word_the_vocabulary_reads_completes_no_second_word', + 'سامر حداد جونيور الدين', + {'given': 'سامر', 'middle': 'حداد جونيور', 'family': 'الدين'}, + notes='boundary: جونيور is a suffix word, no plain word'), + Case('a_backward_pair_behind_a_given_name_title_is_the_given_name', + 'الدكتور عز الدين', + {'title': 'الدكتور', 'given': 'عز الدين'}, + classification='fix(#1072)', + notes='a given-name title asserts that a given name follows, so the pair stays joined, as P5 joins \'الدكتور عبد الله\'; 1.4.0 read given \'الدكتور\', middle \'عز\', 3.1.0 title \'الدكتور\', given \'عز\', family \'الدين\''), + Case('a_backward_pair_behind_a_title_written_short_is_the_given_name', + 'د. عز الدين', + {'title': 'د.', 'given': 'عز الدين'}, + classification='fix(#1072)', + notes="#1149's short title addresses the given name as الدكتور does, so the pair stays joined; 1.4.0 through 3.1.0 read given 'د.', middle 'عز', family 'الدين'"), + Case('a_backward_pair_after_an_empty_head_of_two_words_is_the_given_name', + '، عز الدين', + {'given': 'عز الدين'}, + classification='fix(#1072)', + notes='after a family comma the pair is the given name, as P5 reads \'، عبد الله\'; 1.4.0 through 3.1.0 read given \'عز\', middle \'الدين\''), + Case('a_backward_pair_before_a_family_comma_is_the_family', + 'عز الدين، حداد', + {'given': 'حداد', 'family': 'عز الدين'}, + notes='the part before the comma is the family, the pair one unit there for O6 too; 1.4.0 through 3.1.0 read the same fields'), + Case('a_backward_pair_behind_a_particle_is_the_family', + 'سامر بن عز الدين', + {'given': 'سامر', 'family': 'بن عز الدين'}, + classification='fix(#269)', + notes='boundary: the particle chain takes the pair'), + Case('a_backward_pair_opening_the_name_under_family_first', + 'عز الدين سامر حداد', + {'given': 'سامر', 'middle': 'حداد', 'family': 'عز الدين'}, + policy=Policy(name_order=FAMILY_FIRST), classification='fix(#1072)', + notes='the pair opens the name, so it is the family under a family-first order; 3.1.0 read family \'عز\', given \'الدين\''), + Case('a_backward_pair_before_a_bare_trailing_title_is_the_given_name', + 'عز الدين الحاج', + {'given': 'عز الدين', 'family': 'الحاج'}, + classification='fix(#1072)', + notes='a bare title ending the name is the family name word the parse reads (rules/H5), so the pair has its third name word (fix-commit review); 1.4.0 through 3.1.0 read given \'عز\', middle \'الدين\''), + Case('a_backward_pair_before_a_bare_trailing_title_under_family_first', + 'عز الدين الحاج', + {'given': 'الحاج', 'family': 'عز الدين'}, + policy=Policy(name_order=FAMILY_FIRST), classification='fix(#1072)', + notes='3.1.0 read family \'عز\', given \'الدين\', middle \'الحاج\''), + Case('two_family_names_divides_a_family_ending_in_a_backward_pair_before_a_comma', + 'حداد عز الدين، سامر', + {'given': 'سامر', 'family': 'حداد عز الدين'}, + policy=_TWO, + notes='boundary: the pair one unit before a family comma, as without it; the views divide حداد | عز الدين either way (fix-commit review)'), + Case('a_backward_pair_written_across_a_comma_is_not_joined', + 'محمد عز، الدين أحمد', + {'given': 'الدين', 'middle': 'أحمد', 'family': 'محمد عز'}, + notes='boundary: no pair is written across a comma'), + Case('a_backward_pair_before_a_suffix_and_a_title_stays_apart', + 'عز الدين PhD الحاج', + {'title': 'الحاج', 'given': 'عز', 'family': 'الدين', 'suffix': 'PhD'}, + classification='fix(#602)', + notes='boundary: the trailing run takes all behind its first word, so a title behind a credential is no name word in the guard (review of the last fix commit)'), + Case('a_backward_pair_before_a_title_and_a_suffix_joins', + 'عز الدين الحاج PhD', + {'given': 'عز الدين', 'family': 'الحاج', 'suffix': 'PhD'}, + classification='fix(#1072)', + notes='the bare title stands before the run, the family name word; read given \'عز\', middle \'الدين\' through 3.1.0'), + Case('a_backward_pair_before_a_suffix_comma_and_a_third_part_stays_apart', + 'عز الدين، Jr.، سامر', + {'given': 'عز', 'family': 'الدين', 'suffix': 'Jr., سامر'}, + ambiguities=('comma-structure',), + notes='boundary: only the given part after a family comma counts, and a part opening with a suffix word is none'), # #1149: Arabic-script titles written short, the ranks Egypt's # parliament writes, and the script-property row saying Arabic # script writes no initials. diff --git a/tests/v2/pipeline/test_post_rules.py b/tests/v2/pipeline/test_post_rules.py index 2c5224cc5..efe75c5a8 100644 --- a/tests/v2/pipeline/test_post_rules.py +++ b/tests/v2/pipeline/test_post_rules.py @@ -1726,6 +1726,61 @@ def test_the_704_tags_reach_no_published_token() -> None: assert not published & {"vocab:shared-name", "vocab:particle-given"} +@pytest.mark.parametrize("order,folded,field", [ + ("given_first", False, "family"), + ("family_first", False, "middle"), + ("family_first", True, "family"), + ("family_first_given_last", False, "given"), +]) +def test_a_split_backward_pair_leaves_a_later_words_alternative_right( + order: str, folded: bool, field: str) -> None: + # rules/P12's split of a pair holding every name word (#1072): a + # word after it, read as the suffix, would be the THIRD name word, + # which under FAMILY_FIRST is the middle, as the unjoined pair's + # reading named it (review of the guard's rewrite) + import nameparser + policy = Policy(name_order=getattr(nameparser, order.upper()), + middle_as_family=folded) + for text in ("عز الدين V", "عز الدين Junior"): + n = Parser(policy=policy).parse(text) + [report] = [a for a in n.ambiguities if a.kind.value == "suffix-or-name"] + assert report.alternative is not None + assert report.alternative.role == field, (order, folded, text) + + +def test_a_split_backward_pair_leaves_a_report_after_a_comma_alone() -> None: + # a word after a suffix comma names the given name for the comma's + # other reading, read as a family comma, which no count of units + # moves: 'Kim Lee, Ba' names it under every order (review of the + # alternative's fix) + import nameparser + for order in ("GIVEN_FIRST", "FAMILY_FIRST", "FAMILY_FIRST_GIVEN_LAST"): + for folded in (False, True): + p = Parser(policy=Policy(name_order=getattr(nameparser, order), + middle_as_family=folded)) + for text in ("عز الدين, Ba", "عز الدين, MA", "عز الدين, Junior"): + roles = [a.alternative.role for a in p.parse(text).ambiguities + if a.alternative is not None] + assert roles == ["given"], (order, folded, text, roles) + # one report on each side of the comma: the word before it moves, + # the one after it does not + n = Parser(policy=Policy(name_order=nameparser.FAMILY_FIRST)).parse( + "عز الدين V, Ba") + by_word = {a.tokens[0].text: a.alternative.role + for a in n.ambiguities if a.alternative is not None} + assert by_word == {"V": "middle", "Ba": "given"}, by_word + + +def test_the_1072_tags_reach_no_published_token() -> None: + # BOUND_SECOND_TAG and the phrase tag beside it serve group and the + # post rules only, dropped at assemble (_assemble._KIND_TAGS) + names = [parse("سامر عز الدين"), parse("نور الدين سامر حداد"), + Parser(policy=Policy(two_family_names=True)).parse( + "سامر حداد عز الدين")] + published = {tag for n in names for t in n.tokens for tag in t.tags} + assert not published & {"vocab:bound-second", "vocab:bound-phrase"} + + def test_a_saint_particle_opens_no_given_name_phrase() -> None: # rules/P10's saint clause: 'Santa María' is a surname, the given # name phrases being written with a preposition or an article. The diff --git a/tests/v2/test_layering.py b/tests/v2/test_layering.py index 50f5b3ece..23fe2238d 100644 --- a/tests/v2/test_layering.py +++ b/tests/v2/test_layering.py @@ -901,7 +901,8 @@ def test_the_check_finds_a_tool_read_through_an_alias( #: of the unambiguous title-or-suffix test after a glued stop into #: `_vocab._claimed_after_the_stop`, 203 -> 198; #1464's P12 test #: in classify reading the bound sets through a `sets =` binding, -#: 198 -> 199); +#: 198 -> 199; #1072's split of a lone backward pair in post_rules +#: reading the given-name titles, 199 -> 200); #: the tools' first 20 are 18 #: attribute loads, every tool scanned, and config_diff.py's #: `sets =` binding and the roster `getattr` through it (its @@ -928,7 +929,7 @@ def test_the_check_finds_a_tool_read_through_an_alias( #: `_lexicon._fields_of` from 4i-b until 4i-c retired it. #: A reader added through `_sets` moves these, and they are re-taken #: then: they count what the check would refuse with the move undone. -_UNGUARDED_READS = {"library": 199, "tools": 35} +_UNGUARDED_READS = {"library": 200, "tools": 35} def test_the_check_refuses_every_read_4i_a_moved() -> None: diff --git a/tests/v2/test_lexicon.py b/tests/v2/test_lexicon.py index 8affcb0ff..f84f86732 100644 --- a/tests/v2/test_lexicon.py +++ b/tests/v2/test_lexicon.py @@ -1033,6 +1033,47 @@ def family(lex: Lexicon, text: str) -> str: assert family(alone, "Nadia Ali Abdou Rahim") == "Rahim" +def test_bound_second_is_rule_p12s_backward_switch_both_ways() -> None: + # a caller's bound_second reading joins the plain word before it + # wherever it stands, `completes` narrows it to the words listed, + # and removing a shipped one gives the pair back (rules/P12, #1072) + def read(lex: Lexicon, text: str) -> dict[str, str]: + n = Parser(lexicon=lex).parse(text) + return {"given": n.given, "middle": n.middle, "family": n.family} + default = Lexicon.default() + assert read(default, "Samir Nour zzend")["family"] == "zzend" + added = default.add("zzend", kind="bound_second") + assert read(added, "Samir Nour zzend")["family"] == "Nour zzend" + assert read(added, "Nour zzend Samir Haddad")["given"] == "Nour zzend" + listed = default.add("zzend", kind="bound_second", completes=["dhu"]) + assert read(listed, "Samir Nour zzend")["family"] == "zzend" + assert read(listed, "Samir Dhu zzend")["family"] == "Dhu zzend" + assert read(default, "سامر عز الدين")["family"] == "عز الدين" + removed = default.remove("الدين", kind="bound_second") + assert read(removed, "سامر عز الدين") == { + "given": "سامر", "middle": "عز", "family": "الدين"} + # a second word the vocabulary reads otherwise too joins nothing + titled = added.add("zzend", kind="title") + assert read(titled, "Samir Nour zzend")["family"] == "zzend" + assert pickle.loads(pickle.dumps(added)) == added + + +@pytest.mark.parametrize("prop", ["completes", "completed_by"]) +def test_a_pair_list_refuses_an_empty_list_and_a_phrase(prop: str) -> None: + kind = "bound_second" if prop == "completes" else "bound_given" + with pytest.raises(ValueError, match="at least one word") as refused: + Lexicon.default().add("zzend", kind=kind, **{prop: []}) + # the fix the message offers runs and clears a shipped list: الغنى + # then joins behind any plain word + assert f"{prop}=None" in str(refused.value) + if prop == "completes": + opened = Lexicon.default().add("الغنى", kind="bound_second", + completes=None) + assert Parser(lexicon=opened).parse("سامر نور الغنى").family == "نور الغنى" + with pytest.raises(ValueError, match="must be single words"): + Lexicon.default().add("zzend", kind=kind, **{prop: ["dhu nour"]}) + + @pytest.mark.parametrize("flag", ["completes_any", "long_names_only"]) def test_p12s_switches_refuse_a_non_bool_and_another_kind(flag: str) -> None: with pytest.raises(TypeError, match=flag): @@ -1920,6 +1961,7 @@ def test_migrate_s_table_covers_every_compiled_constant() -> None: "CAPITALIZED_PARTICLES", "CAPITAL_OPENING_PARTICLES", "DOTTED_TITLES", "GLUED_TITLES", "BOUND_PHRASES", "BOUND_COMPLETES_ANY", "BOUND_LONG_NAMES_ONLY", + "BOUND_SECONDS", "BOUND_SECOND_PHRASES", "BOUND_SECONDS_LISTED", "SAME_AS", "SAME_AS_NAMED", "FAMILIAR", "ALTERNATE_SPELLINGS"} assert public_in_2x <= named diff --git a/tests/v2/test_reading_index.py b/tests/v2/test_reading_index.py index 94690a7b4..f4009f55f 100644 --- a/tests/v2/test_reading_index.py +++ b/tests/v2/test_reading_index.py @@ -65,7 +65,7 @@ def test_the_index_compiled_with_no_choice_is_the_committed_module() -> None: "may_be_initial": True, "title_case_is_name": True, "shared": True, "after_particle": True, "capital_opening": True, "dotted": True, - "completed_by": ["zzq"], "completes_any": True, + "completed_by": ["zzq"], "completes": ["zzq"], "completes_any": True, "long_names_only": True} diff --git a/tests/v2/test_types.py b/tests/v2/test_types.py index 0e499e573..7da6b40f3 100644 --- a/tests/v2/test_types.py +++ b/tests/v2/test_types.py @@ -1457,6 +1457,11 @@ def test_a_patronymic_parsedname_pickled_by_2_8_0_loads_equal() -> None: ("Ana Umm Kulthum López", _GF, False, ""), # a Latin bound pair P12 joined is one unit O6 takes (#1464) ("Ana abdul Rahman López", _GF, False, "López"), + # a pair joined from its second word is one unit, with a family + # comma and without one (#1072) + ("سامر حداد عز الدين", _GF, False, "عز الدين"), + ("حداد عز الدين، سامر", _GF, False, "عز الدين"), + ("سامر عز الدين حداد", _GF, False, "حداد"), ("Ana M. García", _GF, False, ""), ("Pérez de la Vega", _FF, False, ""), ("王 小 明", _GF, False, ""), diff --git a/tests/v2/test_vocab.py b/tests/v2/test_vocab.py index e47d200e1..47c4cbf5f 100644 --- a/tests/v2/test_vocab.py +++ b/tests/v2/test_vocab.py @@ -688,6 +688,14 @@ def _w(body: str) -> str: # (BEHAVIORAL), so any other refuses it as unknown ("dotted-not-true", {"en.toml": _w('[[word]]\ntext = "us"\nmodifier = { dotted = false }')}, "dotted must be true, or left unwritten"), ("dotted-on-a-suffix-reading", {"en.toml": _w('[[word]]\ntext = "zzq"\ncredential = { dotted = true }')}, "dotted"), + # rules/P12's completes on a bound_second reading: a list of single + # folded words, and a bound_second reading's alone (#1072) + ("completes-not-a-list", {"ar.toml": _w('[[word]]\ntext = "zzq"\nbound_second = { completes = "zzr" }')}, "completes must be a non-empty list"), + ("completes-two-words", {"ar.toml": _w('[[word]]\ntext = "zzq"\nbound_second = { completes = ["zzr zzs"] }')}, "completes must be a non-empty list"), + ("completes-empty", {"ar.toml": _w('[[word]]\ntext = "zzq"\nbound_second = { completes = [] }')}, "completes must be a non-empty list"), + ("completes-unfolded", {"ar.toml": _w('[[word]]\ntext = "zzq"\nbound_second = { completes = ["Zzr"] }')}, "completes must be a non-empty list"), + ("completes-duplicate", {"ar.toml": _w('[[word]]\ntext = "zzq"\nbound_second = { completes = ["zzr", "zzr"] }')}, "completes must be a non-empty list"), + ("completes-on-a-bound-given", {"ar.toml": _w('[[word]]\ntext = "zzq"\nbound_given = { completes = ["zzr"] }')}, "completes"), # rules/P12's completes_any and long_names_only: true or unwritten, # and long_names_only only beside completes_any, which it narrows # (#1464) @@ -1277,10 +1285,13 @@ def _sets_fed(kind: str, props: str = "{}", text: str = "zzq", with warnings.catch_warnings(): warnings.simplefilter("ignore", build.VocabWarning) # a name reading is inert compiled = build.compile_files(files) - # a word is in a set of phrases where it opens one (TITLE_PHRASES), - # and in SAME_AS where a group of it holds the word + # a word is in a set of phrases where it opens one (TITLE_PHRASES) + # or ends one (BOUND_SECOND_PHRASES, #1072), and in SAME_AS where a + # group of it holds the word return {name for name, value in compiled.items() - if text in value or any(isinstance(v, str) and v.startswith(text + " ") + if text in value or any(isinstance(v, str) + and (v.startswith(text + " ") + or v.endswith(" " + text)) for v in value) or (isinstance(value, dict) and any( isinstance(g, dict) and text in g for g in value.values()))} @@ -1307,6 +1318,7 @@ def _sets_fed(kind: str, props: str = "{}", text: str = "zzq", "dotted": ("modifier", "{ dotted = true }", "zzq"), "completed_by": ("bound_given", '{ completed_by = ["zzr"] }', "zzq"), "completes_any": ("bound_given", "{ completes_any = true }", "zzq"), + "completes": ("bound_second", '{ completes = ["zzr"] }', "zzq"), "long_names_only": ("bound_given", "{ completes_any = true, long_names_only = true }", "zzq"), diff --git a/tools/differential/corpus_rules.jsonl b/tools/differential/corpus_rules.jsonl index ce3f68355..1574c5bae 100644 --- a/tools/differential/corpus_rules.jsonl +++ b/tools/differential/corpus_rules.jsonl @@ -370,6 +370,7 @@ "Dr. juan garcia" "Dr. med. univ. Margit Popp, MSc" "Dr. nee Smith PhD Prof." +"Dr. عز الدين" "Dr. 王李小明" "Dr., John" "Dr.C Kamaraj" @@ -2019,26 +2020,41 @@ "בן חיים יעל" "בן חיים, יעל" "סאמר בן חליל" +"، عز الدين" "أ.د.أحمد علي" +"أبو نور الدين سامر" "أحمد علي حسن" "أحمد م. علي" +"الدكتور عز الدين" "جورج بوش الابن" "د.أحمد علي حسن" +"سامر بن الله" +"سامر ذو الغنى" +"سامر عز الدين" +"سامر نور الدين حداد" "سعيد عبد الله" "سلمان، محمد" "طارق عبد العزيز" "عبد اللطيف عبد الحميد" "عبد الله" "عبد الله حسن, علي" +"عز الدين" +"عز الدين Jr." +"عز الدين PhD الحاج" +"عز الدين الابن حداد" +"عز الدين الحاج" "علي ح. م." "علي عبد الکریم" +"ليلى شكر الله" "محمد بن سلمان" "محمد عبد القريشي" "محمد عبد الله أحمد" "محمد علي MD حسن" "محمد علي و" "مُحَمَّد بِن سَلمان" +"نصر اله رضایی" "نوال عبد هاشم" +"نور الدين سامر حداد" "एम. एस. वर्मा" "झलक बहादुर आ. म." "डा. राम वर्मा" diff --git a/tools/differential/snapshot.jsonl b/tools/differential/snapshot.jsonl index c6e4db04b..c96a8535c 100644 --- a/tools/differential/snapshot.jsonl +++ b/tools/differential/snapshot.jsonl @@ -1043,6 +1043,7 @@ {"name": "Dr. med. univ. Margit Popp", "title": "Dr. med. univ.", "given": "Margit", "family": "Popp", "initials": "M. P.", "capitalized_force": "Dr. Med. Univ. Margit Popp"} {"name": "Dr. med. univ. Margit Popp, MSc", "title": "Dr. med. univ.", "given": "Margit", "family": "Popp", "suffix": "MSc", "initials": "M. P.", "capitalized_force": "Dr. Med. Univ. Margit Popp, MSc"} {"name": "Dr. nee Smith PhD Prof.", "title": "Dr. Prof.", "given": "nee", "family": "Smith", "suffix": "PhD", "initials": "n. S.", "capitalized_force": "Dr. Prof. Nee Smith PhD"} +{"name": "Dr. عز الدين", "title": "Dr.", "given": "عز", "family": "الدين"} {"name": "Dr. 王李小明", "title": "Dr.", "family": "王李小明"} {"name": "Dr. 김민준씨, MA", "title": "Dr.", "given": "민준", "family": "김", "suffix": "씨, MA", "honorifics": "씨"} {"name": "Dr., John", "given": "John", "family": "Dr.", "initials": "J. D."} @@ -5997,6 +5998,7 @@ {"name": "תומר שחורי", "given": "תומר", "family": "שחורי", "initials": "ת. ש."} {"name": "תמיר כהן", "given": "תמיר", "family": "כהן", "initials": "ת. כ."} {"name": "תמרה כהן", "given": "תמרה", "family": "כהן", "initials": "ת. כ."} +{"name": "، عز الدين", "given": "عز الدين"} {"name": "آئرين ائڊلر", "given": "آئرين", "family": "ائڊلر"} {"name": "آقای امیر هوشنگ رستگار دکتر", "title": "آقای", "given": "امیر", "middle": "هوشنگ رستگار", "family": "دکتر"} {"name": "آمال فهمي", "given": "آمال", "family": "فهمي"} @@ -6005,6 +6007,7 @@ {"name": "أبو الأغا، أحمد رامي نجيب محفوظ", "order": "FAMILY_FIRST", "given": "أحمد", "middle": "رامي نجيب محفوظ", "family": "أبو الأغا"} {"name": "أبو بكر الشاطري", "given": "أبو بكر", "family": "الشاطري"} {"name": "أبو بكر سالم", "given": "أبو بكر", "family": "سالم"} +{"name": "أبو نور الدين سامر", "given": "أبو نور", "middle": "الدين", "family": "سامر"} {"name": "أحلام الجريتلي", "given": "أحلام", "family": "الجريتلي"} {"name": "أحمد حجازي", "given": "أحمد", "family": "حجازي"} {"name": "أحمد سالم", "given": "أحمد", "family": "سالم"} @@ -6045,6 +6048,7 @@ {"name": "اصغر، شازیہ", "order": "FAMILY_FIRST", "given": "شازیہ", "family": "اصغر"} {"name": "اقبال قریشی", "given": "اقبال", "family": "قریشی"} {"name": "الدكتور عايدة كورنيليا سيزار مارتن فون برول الإبن، طبيب وجراح", "title": "الدكتور", "given": "طبيب", "middle": "وجراح", "family": "عايدة كورنيليا سيزار مارتن فون برول", "suffix": "الإبن", "generation": "الإبن"} +{"name": "الدكتور عز الدين", "title": "الدكتور", "given": "عز الدين"} {"name": "السيد أحمد رامي نجيب محفوظ أبو الأغا الابن، النائب", "given": "النائب", "family": "السيد أحمد رامي نجيب محفوظ أبو الأغا", "suffix": "الابن", "generation": "الابن"} {"name": "العامر، كمال مجدي", "order": "FAMILY_FIRST", "given": "كمال", "middle": "مجدي", "family": "العامر"} {"name": "النجار، سميرة", "order": "FAMILY_FIRST", "given": "سميرة", "family": "النجار"} @@ -6062,7 +6066,7 @@ {"name": "جان همیش واټسن", "given": "جان", "middle": "همیش", "family": "واټسن"} {"name": "جلال همتی", "given": "جلال", "family": "همتی"} {"name": "جمال محمد", "given": "جمال", "family": "محمد"} -{"name": "جميل عز الدين", "given": "جميل", "middle": "عز", "family": "الدين"} +{"name": "جميل عز الدين", "given": "جميل", "family": "عز الدين"} {"name": "جورج إسحاق", "given": "جورج", "family": "إسحاق"} {"name": "جورج بوش الابن", "given": "جورج", "family": "بوش", "suffix": "الابن", "generation": "الابن"} {"name": "جورج ميشيل", "given": "جورج", "family": "ميشيل"} @@ -6112,6 +6116,10 @@ {"name": "سارہ خان", "given": "سارہ", "family": "خان"} {"name": "سامانتا", "given": "سامانتا", "ambiguities": ["GIVEN_OR_FAMILY"], "alternatives": ["GIVEN_OR_FAMILY: name as family (position)"]} {"name": "سامانتا", "order": "FAMILY_FIRST", "given": "سامانتا", "ambiguities": ["GIVEN_OR_FAMILY"], "alternatives": ["GIVEN_OR_FAMILY: name as family (position)"]} +{"name": "سامر بن الله", "given": "سامر", "family": "بن الله", "patronymic": "بن الله"} +{"name": "سامر ذو الغنى", "given": "سامر", "family": "ذو الغنى"} +{"name": "سامر عز الدين", "given": "سامر", "family": "عز الدين"} +{"name": "سامر نور الدين حداد", "given": "سامر", "middle": "نور الدين", "family": "حداد"} {"name": "سامي الكيالي", "given": "سامي", "family": "الكيالي"} {"name": "ستوبر، زيزينيا هاميش", "order": "FAMILY_FIRST", "given": "زيزينيا", "middle": "هاميش", "family": "ستوبر"} {"name": "ستیش شرما", "given": "ستیش", "family": "شرما"} @@ -6160,13 +6168,13 @@ {"name": "صالح اللحيدان", "given": "صالح", "family": "اللحيدان"} {"name": "صالح خالد الشهري", "given": "صالح", "middle": "خالد", "family": "الشهري"} {"name": "صلاح المُولَّد", "given": "صلاح", "family": "المُولَّد"} -{"name": "صنع الله إبراهيم", "given": "صنع", "middle": "الله", "family": "إبراهيم"} +{"name": "صنع الله إبراهيم", "given": "صنع الله", "family": "إبراهيم"} {"name": "طارق سلامة", "given": "طارق", "family": "سلامة"} {"name": "طارق عبد العزيز", "given": "طارق", "family": "عبد العزيز"} {"name": "طارق فتح", "given": "طارق", "family": "فتح"} {"name": "طاہر داوڑ", "given": "طاہر", "family": "داوڑ"} {"name": "طلعت زكريا", "given": "طلعت", "family": "زكريا"} -{"name": "عائشة ذو الغنى", "given": "عائشة", "middle": "ذو", "family": "الغنى"} +{"name": "عائشة ذو الغنى", "given": "عائشة", "family": "ذو الغنى"} {"name": "عادل التويجري", "given": "عادل", "family": "التويجري"} {"name": "عارف علوی", "given": "عارف", "family": "علوی"} {"name": "عارف وزیر", "given": "عارف", "family": "وزیر"} @@ -6199,6 +6207,11 @@ {"name": "عدنان مصطفى", "given": "عدنان", "family": "مصطفى"} {"name": "عرفان خان", "given": "عرفان", "family": "خان"} {"name": "عرفان صدیقی", "given": "عرفان", "family": "صدیقی"} +{"name": "عز الدين", "given": "عز", "family": "الدين"} +{"name": "عز الدين Jr.", "given": "عز", "family": "الدين", "suffix": "Jr.", "generation": "Jr."} +{"name": "عز الدين PhD الحاج", "title": "الحاج", "given": "عز", "family": "الدين", "suffix": "PhD"} +{"name": "عز الدين الابن حداد", "given": "عز الدين", "middle": "الابن", "family": "حداد"} +{"name": "عز الدين الحاج", "given": "عز الدين", "family": "الحاج"} {"name": "عزت‌الله انتظامی", "given": "عزت‌الله", "family": "انتظامی"} {"name": "علي الرواس", "given": "علي", "family": "الرواس"} {"name": "علي القرني", "given": "علي", "family": "القرني"} @@ -6211,7 +6224,7 @@ {"name": "عمران خان", "given": "عمران", "family": "خان"} {"name": "غادة السمان", "given": "غادة", "family": "السمان"} {"name": "غسان جبري", "given": "غسان", "family": "جبري"} -{"name": "غلام اللہ خان", "given": "غلام", "middle": "اللہ", "family": "خان"} +{"name": "غلام اللہ خان", "given": "غلام اللہ", "family": "خان"} {"name": "فائق عرقسُوسي", "given": "فائق", "family": "عرقسُوسي"} {"name": "فاروق خورشيد", "given": "فاروق", "family": "خورشيد"} {"name": "فاروق عطية", "given": "فاروق", "family": "عطية"} @@ -6233,6 +6246,7 @@ {"name": "كەيت مۇللەر", "given": "كەيت", "family": "مۇللەر"} {"name": "لطفي لبيب", "given": "لطفي", "family": "لبيب"} {"name": "لويس جريس", "given": "لويس", "family": "جريس"} +{"name": "ليلى شكر الله", "given": "ليلى", "family": "شكر الله"} {"name": "مازن المبارك", "given": "مازن", "family": "المبارك"} {"name": "ماقسات بالقىباي", "given": "ماقسات", "family": "بالقىباي"} {"name": "مانی شرما", "given": "مانی", "family": "شرما"} @@ -6293,12 +6307,14 @@ {"name": "ندیم رضا یاسمین راشد سدرہ منیر ایم ڈی ڈی ڈی ایس", "order": "FAMILY_FIRST", "given": "رضا", "middle": "یاسمین راشد سدرہ منیر ایم ڈی ڈی ڈی ایس", "family": "ندیم"} {"name": "ندیم رضا، یاسمین راشد سدرہ منیر ایم ڈی ڈی ڈی ایس", "order": "FAMILY_FIRST", "given": "یاسمین", "middle": "راشد سدرہ منیر ایم ڈی ڈی ڈی ایس", "family": "ندیم رضا"} {"name": "نسرين طافش", "given": "نسرين", "family": "طافش"} +{"name": "نصر اله رضایی", "given": "نصر اله", "family": "رضایی"} {"name": "نعيم عيسى", "given": "نعيم", "family": "عيسى"} {"name": "نهلة القدسي", "given": "نهلة", "family": "القدسي"} {"name": "نوال عبد هاشم", "given": "نوال", "middle": "عبد", "family": "هاشم"} -{"name": "نور الدين عتر", "given": "نور", "middle": "الدين", "family": "عتر"} +{"name": "نور الدين سامر حداد", "given": "نور الدين", "middle": "سامر", "family": "حداد"} +{"name": "نور الدين عتر", "given": "نور الدين", "family": "عتر"} {"name": "نورس عبد الواحد", "given": "نورس", "family": "عبد الواحد"} -{"name": "هالة شكر الله", "given": "هالة", "middle": "شكر", "family": "الله"} +{"name": "هالة شكر الله", "given": "هالة", "family": "شكر الله"} {"name": "هدى شعراوي", "given": "هدى", "family": "شعراوي"} {"name": "هدى عابدين", "given": "هدى", "family": "عابدين"} {"name": "هشام حافظ", "given": "هشام", "family": "حافظ"} diff --git a/tools/differential/wikidata_native_agreement.json b/tools/differential/wikidata_native_agreement.json index 60ccef48d..58f0c8663 100644 --- a/tools/differential/wikidata_native_agreement.json +++ b/tools/differential/wikidata_native_agreement.json @@ -464,17 +464,6 @@ }, "text": "Степаненко Василиса Іллівна" }, - "Q121061159/ar-sy/givenFirst": { - "family": { - "expected": "ذو الغنى", - "got": "الغنى" - }, - "given_names": { - "expected": "عائشة", - "got": "عائشة ذو" - }, - "text": "عائشة ذو الغنى" - }, "Q12123956/uk-ua/surnameFirst": { "patronymic": { "expected": "Олексійович", @@ -507,17 +496,6 @@ }, "text": "朱霖" }, - "Q125699198/ar-eg/givenFirst": { - "family": { - "expected": "عز الدين", - "got": "الدين" - }, - "given_names": { - "expected": "جميل", - "got": "جميل عز" - }, - "text": "جميل عز الدين" - }, "Q127605824/zh-tw/surnameFirst": { "family": { "expected": "卫", @@ -635,17 +613,6 @@ }, "text": "Олексій Олексійович Гончаренко" }, - "Q16230492/ar-eg/givenFirst": { - "family": { - "expected": "شكر الله", - "got": "الله" - }, - "given_names": { - "expected": "هالة", - "got": "هالة شكر" - }, - "text": "هالة شكر الله" - }, "Q16262307/zh-cn/surnameFirst": { "family": { "expected": "柯", diff --git a/tools/vocab/build.py b/tools/vocab/build.py index 991316507..9646bef4f 100644 --- a/tools/vocab/build.py +++ b/tools/vocab/build.py @@ -1023,6 +1023,18 @@ def _check_reading(r: Reading, pool: Pool) -> None: raise VocabError(f"{where}: long_names_only narrows completes_any " f"to a name of four words or more, so it needs " f"completes_any = true beside it") + if "completes" in p: + # the first words a bound_second word completes, where it joins + # behind those alone (rules/P12, #1072): each one word, written + # as the fold leaves it, so the phrase test matches it + done = p["completes"] + if (not isinstance(done, list) or not done + or not all(isinstance(w, str) and w and " " not in w + and _normalize(w) == w for w in done) + or len(set(done)) != len(done)): + raise VocabError(f"{where}: completes must be a non-empty " + f"list of single words, each once and " + f"written folded") if "completed_by" in p: # the words that complete a bound given name into one given # name past the first name word (rules/P12): each one word, written @@ -1475,7 +1487,7 @@ def _behavior(r: Reading, prop: str) -> object: "capital_opening", "dotted", "completes_any", "long_names_only"): return r.flag(prop) - if prop in ("attaches", "completed_by"): + if prop in ("attaches", "completed_by", "completes"): att = r.props.get(prop) return None if att is None else frozenset(att) if prop == "default": @@ -1524,6 +1536,9 @@ def _behavior(r: Reading, prop: str) -> object: "BOUND_PHRASES", "BOUND_COMPLETES_ANY", "BOUND_LONG_NAMES_ONLY", + "BOUND_SECONDS", + "BOUND_SECOND_PHRASES", + "BOUND_SECONDS_LISTED", "SAME_AS", "SAME_AS_NAMED", "FAMILIAR",