nameparser 2.1.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nameparser-2.1.0/nameparser.egg-info → nameparser-2.3.0}/PKG-INFO +3 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/README.rst +2 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/__main__.py +1 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_config_shim.py +41 -41
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_facade.py +85 -27
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_lexicon.py +250 -76
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_parser.py +84 -27
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_assemble.py +4 -0
- nameparser-2.3.0/nameparser/_pipeline/_assign.py +718 -0
- nameparser-2.3.0/nameparser/_pipeline/_classify.py +230 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_extract.py +81 -27
- nameparser-2.3.0/nameparser/_pipeline/_group.py +978 -0
- nameparser-2.3.0/nameparser/_pipeline/_pieces.py +503 -0
- nameparser-2.3.0/nameparser/_pipeline/_post_rules.py +838 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_script_segment.py +120 -138
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_segment.py +22 -25
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_state.py +56 -8
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_tokenize.py +16 -27
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/_vocab.py +209 -21
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_policy.py +19 -4
- nameparser-2.3.0/nameparser/_render.py +316 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_types.py +188 -29
- nameparser-2.3.0/nameparser/_version.py +19 -0
- nameparser-2.3.0/nameparser/config/__init__.py +41 -0
- nameparser-2.3.0/nameparser/config/_deprecated.py +141 -0
- nameparser-2.3.0/nameparser/config/_invariants.py +54 -0
- nameparser-2.3.0/nameparser/config/bound_first_names.py +23 -0
- nameparser-2.3.0/nameparser/config/bound_given_names.py +60 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/config/conjunctions.py +2 -2
- nameparser-2.3.0/nameparser/config/maiden_markers.py +111 -0
- nameparser-2.3.0/nameparser/config/particles.py +275 -0
- nameparser-2.3.0/nameparser/config/prefixes.py +38 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/config/suffixes.py +206 -50
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/config/surnames.py +3 -4
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/config/titles.py +190 -25
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/locales/__init__.py +4 -3
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/locales/ja.py +6 -3
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/locales/ru.py +5 -3
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/locales/tr_az.py +3 -2
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/locales/zh.py +2 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/parser.py +2 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/util.py +3 -2
- {nameparser-2.1.0 → nameparser-2.3.0/nameparser.egg-info}/PKG-INFO +3 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser.egg-info/SOURCES.txt +16 -2
- nameparser-2.1.0/tests/test_bound_first_names.py → nameparser-2.3.0/tests/test_bound_given_names.py +58 -1
- nameparser-2.3.0/tests/test_capitalization.py +370 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_conjunctions.py +2 -3
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_first_name.py +24 -4
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_initials.py +63 -6
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_nicknames.py +0 -1
- nameparser-2.1.0/tests/test_prefixes.py → nameparser-2.3.0/tests/test_particles.py +29 -25
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_python_api.py +1 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_suffixes.py +68 -17
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_titles.py +29 -9
- nameparser-2.3.0/tests/v2/_differential_fixtures.py +120 -0
- nameparser-2.3.0/tests/v2/cases.py +5529 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/conftest.py +3 -1
- nameparser-2.3.0/tests/v2/pipeline/test_assign.py +585 -0
- nameparser-2.3.0/tests/v2/pipeline/test_group.py +1136 -0
- nameparser-2.3.0/tests/v2/pipeline/test_pieces.py +252 -0
- nameparser-2.3.0/tests/v2/pipeline/test_post_rules.py +1123 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_script_segment.py +125 -4
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_state.py +14 -5
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_vocab.py +141 -2
- nameparser-2.3.0/tests/v2/rules_doc.py +248 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_benchmark.py +154 -14
- nameparser-2.3.0/tests/v2/test_cases.py +235 -0
- nameparser-2.3.0/tests/v2/test_config_aliases.py +404 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_config_shim.py +9 -6
- nameparser-2.3.0/tests/v2/test_contracts.py +243 -0
- nameparser-2.3.0/tests/v2/test_differential.py +4792 -0
- nameparser-2.3.0/tests/v2/test_doc_citations.py +176 -0
- nameparser-2.3.0/tests/v2/test_doc_spellings.py +30 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_facade.py +52 -2
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_facade_cases.py +32 -1
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_layering.py +63 -5
- nameparser-2.3.0/tests/v2/test_ledger_guards.py +5077 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_lexicon.py +157 -4
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_locales.py +192 -12
- nameparser-2.3.0/tests/v2/test_order_correspondence.py +206 -0
- nameparser-2.3.0/tests/v2/test_parser.py +1695 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_properties.py +19 -6
- nameparser-2.3.0/tests/v2/test_regex_sync.py +211 -0
- nameparser-2.3.0/tests/v2/test_render.py +660 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_reprs.py +15 -1
- nameparser-2.3.0/tests/v2/test_rules_doc.py +145 -0
- nameparser-2.3.0/tests/v2/test_rules_doc_grammar.py +172 -0
- nameparser-2.1.0/nameparser/_pipeline/_assign.py +0 -354
- nameparser-2.1.0/nameparser/_pipeline/_classify.py +0 -97
- nameparser-2.1.0/nameparser/_pipeline/_group.py +0 -408
- nameparser-2.1.0/nameparser/_pipeline/_post_rules.py +0 -130
- nameparser-2.1.0/nameparser/_render.py +0 -177
- nameparser-2.1.0/nameparser/_version.py +0 -9
- nameparser-2.1.0/nameparser/config/__init__.py +0 -20
- nameparser-2.1.0/nameparser/config/_invariants.py +0 -27
- nameparser-2.1.0/nameparser/config/bound_first_names.py +0 -28
- nameparser-2.1.0/nameparser/config/maiden_markers.py +0 -70
- nameparser-2.1.0/nameparser/config/prefixes.py +0 -130
- nameparser-2.1.0/tests/test_capitalization.py +0 -144
- nameparser-2.1.0/tests/v2/cases.py +0 -1807
- nameparser-2.1.0/tests/v2/pipeline/test_assign.py +0 -238
- nameparser-2.1.0/tests/v2/pipeline/test_group.py +0 -252
- nameparser-2.1.0/tests/v2/pipeline/test_post_rules.py +0 -122
- nameparser-2.1.0/tests/v2/test_cases.py +0 -26
- nameparser-2.1.0/tests/v2/test_contracts.py +0 -104
- nameparser-2.1.0/tests/v2/test_differential.py +0 -696
- nameparser-2.1.0/tests/v2/test_parser.py +0 -813
- nameparser-2.1.0/tests/v2/test_regex_sync.py +0 -366
- nameparser-2.1.0/tests/v2/test_render.py +0 -290
- {nameparser-2.1.0 → nameparser-2.3.0}/AUTHORS +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/LICENSE +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/MANIFEST.in +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/__init__.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_locale.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/_pipeline/__init__.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/config/capitalization.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/config/regexes.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser/py.typed +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser.egg-info/dependency_links.txt +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser.egg-info/requires.txt +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/nameparser.egg-info/top_level.txt +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/pyproject.toml +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/setup.cfg +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/__init__.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/base.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/conftest.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_brute_force.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_comma_variants.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_constants.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_east_slavic_patronymic_order.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_middle_name_as_last.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_output_format.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_turkic_patronymic_order.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/test_variations.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/__init__.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/__init__.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_assemble.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_classify.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_extract.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_segment.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/pipeline/test_tokenize.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_cli.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_locale.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_policy.py +0 -0
- {nameparser-2.1.0 → nameparser-2.3.0}/tests/v2/test_types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nameparser
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: A simple Python module for parsing human names into their individual components.
|
|
5
5
|
Author-email: Derek Gulbranson <derek73@gmail.com>
|
|
6
6
|
License: LGPL
|
|
@@ -75,6 +75,8 @@ Quick Start Example
|
|
|
75
75
|
]>
|
|
76
76
|
>>> name.family_base, name.family_particles
|
|
77
77
|
('Vega', 'de la')
|
|
78
|
+
>>> name.given_names, name.surnames
|
|
79
|
+
('Juan Q. Xavier', 'Q. Xavier de la Vega')
|
|
78
80
|
>>> name.render("{family}, {given}")
|
|
79
81
|
'de la Vega, Juan'
|
|
80
82
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
"""v1 ``Constants`` compatibility shim over Lexicon/Policy
|
|
2
|
-
|
|
1
|
+
"""v1 ``Constants`` compatibility shim over Lexicon/Policy
|
|
2
|
+
(mechanisms.md#CONFIG-SHIM-SNAPSHOT). ``nameparser.config``
|
|
3
|
+
re-exports these names from the swap
|
|
3
4
|
commit onward; the whole module is deleted in 3.0 with the facade.
|
|
4
5
|
|
|
5
6
|
Layering: facade layer -- may import anything public; here that's
|
|
@@ -99,7 +100,7 @@ def _normalize_iterable_of_strings(
|
|
|
99
100
|
class SetManager:
|
|
100
101
|
"""v1 ``SetManager`` surface over a plain set of ``lc()``-normalized
|
|
101
102
|
strings. Mutations call ``_on_change`` (the owning Constants'
|
|
102
|
-
generation bump, wired by
|
|
103
|
+
generation bump, wired by the facade). ``__call__`` and the
|
|
103
104
|
missing-member-tolerant ``remove()`` are gone per the #243 schedule
|
|
104
105
|
(warned 1.3.0, removed 2.0): ``remove()`` of a missing member raises
|
|
105
106
|
``KeyError``, matching ``set.remove``.
|
|
@@ -316,7 +317,7 @@ class TupleManager(dict[str, object]):
|
|
|
316
317
|
``AttributeError`` naming the key (#256, warned 1.4, enforced 2.0 --
|
|
317
318
|
the v1 ``DeprecationWarning`` is gone, this shim only speaks 2.0).
|
|
318
319
|
Mutations call ``_on_change`` (the owning Constants' generation
|
|
319
|
-
bump, wired by
|
|
320
|
+
bump, wired by the facade).
|
|
320
321
|
"""
|
|
321
322
|
|
|
322
323
|
_on_change: Callable[[], None] | None
|
|
@@ -431,7 +432,7 @@ class TupleManager(dict[str, object]):
|
|
|
431
432
|
|
|
432
433
|
|
|
433
434
|
#: The named delimiter buckets, translated to the ``Policy``
|
|
434
|
-
#: (open, close) pairs they stand for
|
|
435
|
+
#: (open, close) pairs they stand for. The first three are
|
|
435
436
|
#: v1's; the rest are the #273 typographic conventions, named so the
|
|
436
437
|
#: v1 keyed idioms (pop/move/del) work on them like the originals.
|
|
437
438
|
#: Keep in sync with DEFAULT_NICKNAME_DELIMITERS in _policy.py (pinned
|
|
@@ -472,8 +473,8 @@ class RegexTupleManager(TupleManager): # pickle-compat: do NOT delete
|
|
|
472
473
|
|
|
473
474
|
class _DelimiterManager(TupleManager):
|
|
474
475
|
"""v1 ``nickname_delimiters``/``maiden_delimiters`` bucket. In 2.0
|
|
475
|
-
only the named sentinels in ``_DELIMITER_SENTINELS`` exist (
|
|
476
|
-
|
|
476
|
+
only the named sentinels in ``_DELIMITER_SENTINELS`` exist (the v1
|
|
477
|
+
trio plus the #273 typographic pairs) -- assigning any
|
|
477
478
|
other key raises so a caller reaches for a custom-delimiter Policy
|
|
478
479
|
kwarg instead of a dict entry that silently does nothing. ``pop()``/
|
|
479
480
|
``__setitem__``/``__delitem__`` stay open (inherited) for the
|
|
@@ -517,7 +518,7 @@ class _RegexesProxy:
|
|
|
517
518
|
``CONSTANTS.regexes.word`` stays informational -- but 2.0 configures
|
|
518
519
|
parsing behavior through named ``Policy`` flags, not by mutating a
|
|
519
520
|
regex, so any attribute *or* item assignment raises ``TypeError``
|
|
520
|
-
(
|
|
521
|
+
(the shim's uniform read-only rule).
|
|
521
522
|
"""
|
|
522
523
|
|
|
523
524
|
@staticmethod
|
|
@@ -664,36 +665,38 @@ _SHARED_MUTATION_MESSAGE = (
|
|
|
664
665
|
)
|
|
665
666
|
|
|
666
667
|
|
|
667
|
-
def _default_vocab() -> dict[str,
|
|
668
|
+
def _default_vocab() -> dict[str, frozenset[str]]:
|
|
668
669
|
# v1 data modules stay the single vocabulary source through 2.x
|
|
669
670
|
# (same rule as Lexicon.default()).
|
|
670
|
-
from nameparser.config.
|
|
671
|
+
from nameparser.config.bound_given_names import BOUND_GIVEN_NAMES
|
|
671
672
|
from nameparser.config.conjunctions import CONJUNCTIONS
|
|
672
|
-
from nameparser.config.
|
|
673
|
-
|
|
673
|
+
from nameparser.config.particles import (
|
|
674
|
+
NON_GIVEN_NAME_PARTICLES, PARTICLES,
|
|
674
675
|
)
|
|
675
676
|
from nameparser.config.suffixes import (
|
|
676
|
-
SUFFIX_ACRONYMS, SUFFIX_ACRONYMS_AMBIGUOUS,
|
|
677
|
+
SUFFIX_ACRONYMS, SUFFIX_ACRONYMS_AMBIGUOUS, SUFFIX_WORDS,
|
|
677
678
|
)
|
|
678
|
-
from nameparser.config.titles import
|
|
679
|
+
from nameparser.config.titles import GIVEN_NAME_TITLES, TITLES
|
|
679
680
|
return {
|
|
680
|
-
"prefixes":
|
|
681
|
+
"prefixes": PARTICLES,
|
|
681
682
|
"suffix_acronyms": SUFFIX_ACRONYMS,
|
|
682
|
-
"suffix_not_acronyms":
|
|
683
|
+
"suffix_not_acronyms": SUFFIX_WORDS,
|
|
683
684
|
"suffix_acronyms_ambiguous": SUFFIX_ACRONYMS_AMBIGUOUS,
|
|
684
685
|
"titles": TITLES,
|
|
685
|
-
"first_name_titles":
|
|
686
|
+
"first_name_titles": GIVEN_NAME_TITLES,
|
|
686
687
|
"conjunctions": CONJUNCTIONS,
|
|
687
|
-
"bound_first_names":
|
|
688
|
-
"non_first_name_prefixes":
|
|
688
|
+
"bound_first_names": BOUND_GIVEN_NAMES,
|
|
689
|
+
"non_first_name_prefixes": NON_GIVEN_NAME_PARTICLES,
|
|
689
690
|
}
|
|
690
691
|
|
|
691
692
|
|
|
692
693
|
class _RenderDefaults(NamedTuple):
|
|
693
694
|
"""v1 scalar rendering knobs that have no home on ``Policy``
|
|
694
|
-
(
|
|
695
|
+
(mechanisms.md#CONFIG-SHIM-SNAPSHOT): ``__str__``/initials
|
|
696
|
+
formatting and capitalization stay
|
|
695
697
|
per-Constants defaults, layered onto a shared ``Parser`` by the
|
|
696
|
-
facade (
|
|
698
|
+
facade (nameparser/_facade.py) rather than folded into the cache
|
|
699
|
+
key."""
|
|
697
700
|
|
|
698
701
|
string_format: str | None
|
|
699
702
|
initials_format: str
|
|
@@ -707,7 +710,8 @@ class _RenderDefaults(NamedTuple):
|
|
|
707
710
|
@functools.lru_cache(maxsize=64)
|
|
708
711
|
def _cached_parser(lexicon: Lexicon, policy: Policy) -> Parser:
|
|
709
712
|
# keyed on hashable value objects: shared across every facade whose
|
|
710
|
-
# Constants resolve to the same snapshot
|
|
713
|
+
# Constants resolve to the same snapshot
|
|
714
|
+
# (mechanisms.md#CONFIG-SHIM-SNAPSHOT)
|
|
711
715
|
return Parser(lexicon=lexicon, policy=policy)
|
|
712
716
|
|
|
713
717
|
|
|
@@ -716,8 +720,8 @@ class Constants:
|
|
|
716
720
|
a frozen ``(Lexicon, Policy, _RenderDefaults)`` snapshot via
|
|
717
721
|
``_snapshot()``. ``_generation`` increments on every mutation;
|
|
718
722
|
facades compare it against a cached value to decide whether their
|
|
719
|
-
snapshot is stale (dirty-tracking
|
|
720
|
-
|
|
723
|
+
snapshot is stale (dirty-tracking -- the facade side lives in
|
|
724
|
+
nameparser/_facade.py).
|
|
721
725
|
|
|
722
726
|
The module-level ``CONSTANTS`` singleton (below) has ``_shared``
|
|
723
727
|
flipped to ``True``: any mutation reached through it emits
|
|
@@ -980,7 +984,7 @@ class Constants:
|
|
|
980
984
|
|
|
981
985
|
def _build_snapshot(self) -> tuple[Lexicon, Policy, _RenderDefaults]:
|
|
982
986
|
"""Resolve this v1-shaped, mutable Constants into the frozen
|
|
983
|
-
2.0 value objects it corresponds to
|
|
987
|
+
2.0 value objects it corresponds to. A pure read: no
|
|
984
988
|
generation bump, no deprecation warning even on the shared
|
|
985
989
|
singleton -- only direct attribute mutation is on the 3.0
|
|
986
990
|
removal path.
|
|
@@ -1038,9 +1042,9 @@ class Constants:
|
|
|
1038
1042
|
particles=particles,
|
|
1039
1043
|
# complement translation: v1 marks the never-given subset;
|
|
1040
1044
|
# v2 marks the may-be-given subset. The trailing union keeps
|
|
1041
|
-
# a config v1 accepted:
|
|
1042
|
-
# no word in both
|
|
1043
|
-
#
|
|
1045
|
+
# a config v1 accepted: particles.py asserts its own data has
|
|
1046
|
+
# no word in both NON_GIVEN_NAME_PARTICLES and
|
|
1047
|
+
# BOUND_GIVEN_NAMES, but nothing stops a caller adding one at
|
|
1044
1048
|
# runtime, and v1 then lets the bound rule win (leading "dos
|
|
1045
1049
|
# Santos Silva" parses first="dos Santos"). Treating such a
|
|
1046
1050
|
# word as may-be-given reproduces that rather than raising.
|
|
@@ -1062,23 +1066,19 @@ class Constants:
|
|
|
1062
1066
|
bound_given_names=bound,
|
|
1063
1067
|
# v1 Constants has no manager for these (#274 is 2.0
|
|
1064
1068
|
# behavior); the data module is the only source
|
|
1065
|
-
maiden_markers=
|
|
1069
|
+
maiden_markers=MAIDEN_MARKERS,
|
|
1066
1070
|
# likewise no v1 manager: the unspaced-name segmentation
|
|
1067
1071
|
# vocabulary is 2.0 behavior (#271), so it rides in the
|
|
1068
1072
|
# snapshot only -- v1's Constants surface stays frozen.
|
|
1069
|
-
# Unwrapped where maiden_markers above is wrapped: this
|
|
1070
|
-
# module is born frozen (#293), so no wrap
|
|
1071
1073
|
surnames=KOREAN_SURNAMES,
|
|
1072
1074
|
# likewise no v1 manager: the glued-honorific tail set is
|
|
1073
1075
|
# 2.1 behavior (#308), so it rides in the snapshot only.
|
|
1074
|
-
#
|
|
1075
|
-
#
|
|
1076
|
-
#
|
|
1077
|
-
#
|
|
1078
|
-
#
|
|
1079
|
-
|
|
1080
|
-
# gets against suffix_acronyms above.
|
|
1081
|
-
honorific_tails=frozenset(GLUED_HONORIFICS) & suffix_words,
|
|
1076
|
+
# Intersect with the word set: Lexicon enforces tails <=
|
|
1077
|
+
# suffix_words, and v1 semantics are that deleting a suffix
|
|
1078
|
+
# word turns the behavior off -- a lingering tail simply
|
|
1079
|
+
# stops mattering, the same rule ambiguous_acronyms gets
|
|
1080
|
+
# against suffix_acronyms above.
|
|
1081
|
+
honorific_tails=GLUED_HONORIFICS & suffix_words,
|
|
1082
1082
|
# TupleManager is dict[str, object] (v1 parity: values were
|
|
1083
1083
|
# never statically str-typed); every real entry is a str,
|
|
1084
1084
|
# same assumption _DelimiterManager's sentinel lookup makes
|
|
@@ -1099,8 +1099,8 @@ class Constants:
|
|
|
1099
1099
|
_SENTINEL_PAIRS[k] for k in self.maiden_delimiters
|
|
1100
1100
|
if k not in self.nickname_delimiters),
|
|
1101
1101
|
# suffix_delimiter is a _RenderDefaults-only field here; the
|
|
1102
|
-
# facade layers it onto extra_suffix_delimiters per
|
|
1103
|
-
#
|
|
1102
|
+
# facade layers it onto extra_suffix_delimiters per
|
|
1103
|
+
# instance -- _snapshot() itself stays pure translation
|
|
1104
1104
|
)
|
|
1105
1105
|
defaults = _RenderDefaults(
|
|
1106
1106
|
self.string_format, self.initials_format, self.initials_delimiter,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""The 2.0 ``HumanName`` facade (
|
|
1
|
+
"""The 2.0 ``HumanName`` facade (mechanisms.md#FACADE-CONTRACT): a
|
|
2
|
+
mutable wrapper
|
|
2
3
|
over a frozen ParsedName, delegating parsing to the core Parser resolved
|
|
3
4
|
from the bound Constants shim. Keeps every v1 spelling. Deleted in 3.0.
|
|
4
5
|
|
|
@@ -31,7 +32,8 @@ import nameparser._render as _render
|
|
|
31
32
|
from nameparser._config_shim import CONSTANTS, Constants, _cached_parser
|
|
32
33
|
from nameparser._lexicon import _normalize
|
|
33
34
|
from nameparser._parser import Parser
|
|
34
|
-
from nameparser._types import FOLDED_TAG,
|
|
35
|
+
from nameparser._types import (FOLDED_TAG, UNCLASSIFIED_TAG, ParsedName,
|
|
36
|
+
Role, Token)
|
|
35
37
|
|
|
36
38
|
_V2_FIELD = {"first": "given", "last": "family"} # v1 name -> v2 name
|
|
37
39
|
_V1_SPELLING = {v2: v1 for v1, v2 in _V2_FIELD.items()}
|
|
@@ -41,7 +43,8 @@ _MEMBERS = tuple(_V1_SPELLING.get(r.value, r.value) for r in Role)
|
|
|
41
43
|
|
|
42
44
|
|
|
43
45
|
|
|
44
|
-
#: v1 parsing hooks the facade never calls
|
|
46
|
+
#: v1 parsing hooks the facade never calls
|
|
47
|
+
#: (mechanisms.md#FACADE-CONTRACT / #280).
|
|
45
48
|
_V1_HOOKS = (
|
|
46
49
|
"pre_process", "post_process", "parse_full_name", "parse_pieces",
|
|
47
50
|
"parse_nicknames", "join_on_conjunctions", "squash_emoji",
|
|
@@ -152,7 +155,8 @@ class HumanName:
|
|
|
152
155
|
DeprecationWarning, stacklevel=3)
|
|
153
156
|
|
|
154
157
|
# -- render defaults -----------------------------------------------------
|
|
155
|
-
# One-line validating setters (
|
|
158
|
+
# One-line validating setters (mechanisms.md#FACADE-CONTRACT):
|
|
159
|
+
# assigning a non-str (or, for
|
|
156
160
|
# the two fields that allow it, non-str-non-None) raises TypeError at
|
|
157
161
|
# assignment time instead of failing later inside .format().
|
|
158
162
|
|
|
@@ -218,7 +222,8 @@ class HumanName:
|
|
|
218
222
|
# -- config / parsing ---------------------------------------------------
|
|
219
223
|
|
|
220
224
|
def _resolve(self) -> Parser:
|
|
221
|
-
"""Dirty-tracked parser resolution
|
|
225
|
+
"""Dirty-tracked parser resolution
|
|
226
|
+
(mechanisms.md#CONFIG-SHIM-SNAPSHOT): rebuild the
|
|
222
227
|
snapshot only when the bound Constants' generation moved."""
|
|
223
228
|
gen = self._C._generation
|
|
224
229
|
if self._snapshot_gen != gen:
|
|
@@ -472,10 +477,14 @@ class HumanName:
|
|
|
472
477
|
return _normalize(text) in self._lexicon.conjunctions
|
|
473
478
|
|
|
474
479
|
def _split_last(self) -> tuple[list[str], list[str]]:
|
|
475
|
-
#
|
|
476
|
-
#
|
|
477
|
-
#
|
|
478
|
-
#
|
|
480
|
+
# rules.md#R2: "a name part whose every word is particle
|
|
481
|
+
# vocabulary is a part where none of them is doing a
|
|
482
|
+
# particle's work" -- the all-particle guard
|
|
483
|
+
# below is this rule, and predates its statement: v1 assumed a
|
|
484
|
+
# family name does not consist entirely of particles, e.g. the
|
|
485
|
+
# surname "Do" which also appears in PARTICLES. v1
|
|
486
|
+
# parser.py _split_last otherwise verbatim, vocabulary lookup
|
|
487
|
+
# at ACCESS time so assigned last names split too.
|
|
479
488
|
words = " ".join(self.last_list).split()
|
|
480
489
|
i = 0
|
|
481
490
|
while i < len(words) and self._is_particle(words[i]):
|
|
@@ -503,34 +512,73 @@ class HumanName:
|
|
|
503
512
|
# -- initials -------------------------------------------------------------
|
|
504
513
|
|
|
505
514
|
def _process_initial(self, name_part: str, firstname: bool = False) -> str:
|
|
506
|
-
# v1 parser.py:427 verbatim: particles
|
|
507
|
-
# from initials unless the part is a
|
|
508
|
-
# than split(" ")
|
|
509
|
-
#
|
|
510
|
-
#
|
|
515
|
+
# after v1 parser.py:427, not verbatim: particles and
|
|
516
|
+
# conjunctions are filtered from initials unless the part is a
|
|
517
|
+
# first name. split() rather than split(" ") because split(" ")
|
|
518
|
+
# yields '' between repeated spaces and `part[0]` below would
|
|
519
|
+
# raise IndexError on it (#232). v1 stated the reason as
|
|
520
|
+
# `*_list` attributes bypassing whitespace normalization, which
|
|
521
|
+
# no longer holds -- the `*_list` properties are read-only in
|
|
522
|
+
# 2.x, and assignment through `hn.middle = ...` normalizes --
|
|
523
|
+
# but a doubled space anywhere in a part still reaches here.
|
|
511
524
|
parts = name_part.split()
|
|
512
525
|
initials = []
|
|
513
526
|
for part in parts:
|
|
514
|
-
|
|
515
|
-
|
|
527
|
+
# v1 parser.py:771 (1.4.0): is_conjunction was "in the
|
|
528
|
+
# conjunctions set AND NOT is_an_initial", so a dotted or
|
|
529
|
+
# bare-capital E/Y is the initial it looks like rather
|
|
530
|
+
# than the connective. The 2.0 facade dropped that half
|
|
531
|
+
# and lost the middle initial of 'Scott E. Werner' (#462).
|
|
532
|
+
# _render._INITIAL is v1's `initial` shape, kept in step
|
|
533
|
+
# with the pipeline's copy by tests/v2/test_regex_sync.py;
|
|
534
|
+
# the facade may import _render but not _pipeline
|
|
535
|
+
# (tests/v2/test_layering.py). Scoped here rather than in
|
|
536
|
+
# _is_conjunction: this is the only caller, and a future
|
|
537
|
+
# one should not inherit a decision made for initials.
|
|
538
|
+
conjunction = (self._is_conjunction(part)
|
|
539
|
+
and not _render._INITIAL.fullmatch(part))
|
|
540
|
+
if not (self._is_particle(part) or conjunction) or firstname:
|
|
516
541
|
initials.append(part[0])
|
|
517
542
|
if len(initials) > 0:
|
|
518
543
|
return self.initials_separator.join(initials)
|
|
519
544
|
# Return '' (never empty_attribute_default, which may be None)
|
|
520
|
-
# when a part has no initialable words
|
|
521
|
-
#
|
|
522
|
-
#
|
|
545
|
+
# when a part has no initialable words. group_initials below
|
|
546
|
+
# decides what that means: one such element among others is
|
|
547
|
+
# dropped; a group that yields nothing AND is wholly particles
|
|
548
|
+
# initials its words; and a group that yields nothing for any
|
|
549
|
+
# other reason -- a conjunction, or particles mixed with one --
|
|
550
|
+
# is still dropped ("Vega, Santa de y" drops its middle).
|
|
523
551
|
return ""
|
|
524
552
|
|
|
525
553
|
def _initials_lists(self) -> tuple[list[str], list[str], list[str]]:
|
|
526
554
|
"""Initials for the first, middle and last name groups. Parts
|
|
527
|
-
that yield no initials
|
|
528
|
-
|
|
555
|
+
that yield no initials are dropped rather than kept as empty
|
|
556
|
+
strings -- except a part that is wholly PARTICLES, whose words
|
|
557
|
+
initial as ordinary name words since #404, so the prefix-only
|
|
558
|
+
middle name "de la" is no longer an example of the dropping.
|
|
529
559
|
"""
|
|
530
560
|
def group_initials(names: list[str],
|
|
531
561
|
firstname: bool = False) -> list[str]:
|
|
532
|
-
|
|
533
|
-
|
|
562
|
+
got = [i for i in (self._process_initial(n, firstname)
|
|
563
|
+
for n in names if n) if i]
|
|
564
|
+
words = [w for n in names if n for w in n.split()]
|
|
565
|
+
if got or not words or not all(self._is_particle(w)
|
|
566
|
+
for w in words):
|
|
567
|
+
return got
|
|
568
|
+
# rules.md#R3: "except the particles of a part whose every
|
|
569
|
+
# word is one, which are not acting as particles there"
|
|
570
|
+
# -- nothing survived
|
|
571
|
+
# the filter, so the whole group is particles. The
|
|
572
|
+
# facade's twin of the core's
|
|
573
|
+
# UNJOINED_TAG. NOT pinned against it by the case runners,
|
|
574
|
+
# which compare the seven role fields only (Case carries
|
|
575
|
+
# no initials column); the covering test is
|
|
576
|
+
# tests/test_initials.py::test_initials_middle_name_all_prefixes,
|
|
577
|
+
# and since #484 the differential compares initials() on
|
|
578
|
+
# both surfaces for names whose roles agree. _split_last
|
|
579
|
+
# already applies the same guard to the base, which is why
|
|
580
|
+
# last_base was never empty here.
|
|
581
|
+
return [w[0] for w in words]
|
|
534
582
|
return (group_initials(self.first_list, True),
|
|
535
583
|
group_initials(self.middle_list),
|
|
536
584
|
group_initials(self.last_list))
|
|
@@ -685,7 +733,8 @@ class HumanName:
|
|
|
685
733
|
self._suffix_delimiter = state.get("suffix_delimiter",
|
|
686
734
|
defaults.suffix_delimiter)
|
|
687
735
|
self._full_name = state.get("_full_name", "")
|
|
688
|
-
# Components come back exactly as pickled
|
|
736
|
+
# Components come back exactly as pickled
|
|
737
|
+
# (mechanisms.md#FACADE-CONTRACT): synthetic
|
|
689
738
|
# tokens, never a re-parse. Build them per *_list ENTRY rather
|
|
690
739
|
# than from one joined string -- an entry may hold several words
|
|
691
740
|
# ("Ph. D.", "Q.C. M.P."), and re-splitting the joined string on
|
|
@@ -717,8 +766,17 @@ class HumanName:
|
|
|
717
766
|
f"nameparser"
|
|
718
767
|
)
|
|
719
768
|
for position, word in enumerate(entry.split()):
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
769
|
+
# UNCLASSIFIED_TAG for the same reason replace()
|
|
770
|
+
# stamps it: a pickle carries the *_list STRINGS
|
|
771
|
+
# and no tags, so nothing here was read by a parse
|
|
772
|
+
# and case repair must ask the vocabulary rather
|
|
773
|
+
# than read an absent conjunction tag. Without it a
|
|
774
|
+
# restored "juan ortega y gasset" repairs to
|
|
775
|
+
# "Ortega Y Gasset", which is neither v1's answer
|
|
776
|
+
# nor the same name's unpickled one.
|
|
777
|
+
tags = {UNCLASSIFIED_TAG}
|
|
778
|
+
if position:
|
|
779
|
+
tags.add("joined")
|
|
780
|
+
tokens.append(Token(word, None, role, frozenset(tags)))
|
|
723
781
|
self._parsed = ParsedName(
|
|
724
782
|
original=str(state.get("original", "")), tokens=tuple(tokens))
|