Skip to content

Should a bare 'И' parse as an initial or the conjunction 'and'? (e.g. 'Хосе И Мария Сантос') #267

Description

@derek73

The initial regex is ^(\w\.|[A-Z])?$ (nameparser/config/regexes.py). The dotted branch is Unicode-aware (\w), so И. is recognized as an initial — but the bare-letter branch is ASCII [A-Z], so bare E is an initial while bare И is not.

With default constants this has no visible effect. It surfaces as soon as non-Latin conjunctions are configured (see the non-Latin constants proposal), because is_an_initial() is the veto that stops a single capital letter from being treated as a conjunction:

>>> from nameparser import HumanName
>>> from nameparser.config import Constants

>>> HumanName("Jose E Maria Santos").first   # 'e' is a built-in conjunction;
'Jose'                                        # bare 'E' vetoed as initial -> middle 'E Maria'

>>> C = Constants()
>>> C.conjunctions.add('и')                   # Cyrillic 'and'
>>> HumanName("Хосе И Мария Сантос", constants=C).first
'Хосе И Мария'                                # bare 'И' NOT an initial -> conjunction joins

The open question is which behavior is right. The bare-capital-initial convention ("John F Kennedy") is largely an English/Latin habit; Russian typography virtually always writes initials with periods (И. С. Петров), so treating a bare И as a conjunction is arguably correct for Cyrillic. Options:

  1. Change the default: make the bare-letter branch Unicode-uppercase-aware so the initial veto is consistent across scripts. Downside: blocks single-letter non-Latin conjunctions by default, and bare initials without periods are rare outside English anyway.

  2. Keep the default and document the override. regexes.initial is editable config like everything else; users who want Latin-style veto behavior for Cyrillic can use:

    C.regexes.initial = re.compile(r'^(\w\.|[A-ZА-ЯЁ])?$')

    Note the override must be script-targeted — widening the bare branch to any Unicode letter would also match lowercase e and silently disable the built-in Latin conjunction.

Verified on v1.3.0. Related: the non-Latin constants proposal #269, #265, #266.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions