Parse human names into title, given, middle, family, suffix, nickname and maiden name. Typed, zero-dependency, CJK-aware.
Repo derek73/python-nameparser, read from GitHub 19 min ago. derek73 has not joined Take My Repo.
nameparser 3.1 introduces two new tools for working with lists of names: one for configuration and one for matching. Parser.suggest() suggests the Policy settings for the list of names you give it, and Parser.matching() provides tools for joining records from different sources. It also reads family names written in capitals (DUPONT Jean), Thai titles, and a given name written as a run of initials, and adds Mongolian, Arabic and Hebrew packs. Highlights:
Parser.suggest() the names from one source and it works out how they are written: family name first or last, with patronymics, with the family name in capitals or as trailing letters. It returns a parser set up that way, shows what it saw in each name, and leaves the base parser alone where the list gives no clear answer. It never guesses a language, so choosing a pack is still yours. (#1308)J. Smith in one source, John Smith in another and Smith, John Q. in a third. Parser.matching() says whether two names are consistent and why, role by role, and you choose how much difference to accept: an initial for a full name by default, Bill for William if you ask. For a long list it gives each name keys to group on, so you never compare every pair. (#1006)DUPONT Jean). A new setting has the parser take the capitals at their word, so a list that mixes DUPONT Jean with Jean DUPONT reads the same way throughout. A second setting does the same for a family name written as trailing letters. (#659, #1254)parse("นายสมชาย ใจดี") gives title นาย, given สมชาย, family ใจดี, the salutation split from the given name it is written joined to. (#317)locales.MN, locales.AR and locales.HE, for Mongolian, Arabic and Hebrew names. (#1237, #1248)Upgrading from 3.0
parse("J.R.R. Tolkien") gives given J., middle R.R., where 3.0 gave given J.R.R.. (#1296)Md. opening a name is the given name, Muhammad written short, where 3.0 read a title. (#1383)Lexicon, Parser or locale pack pickled by 2.x no longer loads; re-pickle it under 3.0 first. One pickled by 3.1 does not load under 3.0.x. (#1003)The migration guide lists every name whose reading moved, each with the releases that read it the old way.
Full list of changes: https://nameparser.readthedocs.io/en/latest/release_log.html
A packaging fix: the test suite now passes when run against the installed package, as Debian's autopkgtest runs it, where 3.0.0's stopped during collection. The library is unchanged from 3.0.0. See #1184.
nameparser 3.0 removes HumanName, Constants and the rest of the 1.x compatibility layer, which 2.8 deprecates, and rebuilds the vocabulary as readings of words, kept in files by language. A parser can be built for a choice of languages, the suffix splits by kind and the family name into two surnames, and every parsed word records the reading it took. Highlights:
parser_for(locales.ES).parse("Gabriel García Márquez") gives family García Márquez, where the default gives middle García, family Márquez. Spanish, Portuguese, Vietnamese, Czech, Slovak, Irish, Scottish Gaelic, Nepali and other packs are new, and strict=True reads only the chosen languages' words and those every language shares. (#753)parse("John Smith Jr., MD") gives generation Jr. and credentials MD, and surname1 and surname2 give the two family names two_family_names finds. (#754)parse("Dr. Juan de la Vega III").tokens[2].reading says de was read as a particle in the family name, from the vocabulary of the files that list it. (#754)Upgrading from 2.x
from nameparser import HumanName raises ImportError; parse() reads the same names. A pickled HumanName or Constants no longer loads. (#357)Lexicon is configured by reading: Lexicon.default().remove("dean", kind="given") replaces 2.8's add(titles={"dean"}), which now raises TypeError naming the new call.str(parse("김민준")) gives '김민준', where 2.1 through 2.8 gave '민준 김'. Pass 2.x's spec to render() to keep given-first output.Lexicon, Parser or locale pack pickled by 2.8 still loads, with a DeprecationWarning; 3.1 will refuse it, so re-pickle it under 3.0.The migration guide gives the 3.0 call for each 1.x and 2.x one.
Full list of changes: https://nameparser.readthedocs.io/en/latest/release_log.html
nameparser 2.8.2 adds one warning for a 3.0 change 2.8.1 did not announce: importing nameparser.config.surnames, which 3.0 makes private. Code that runs with warnings as errors (-W error, or pytest's filterwarnings = error) will fail where it imports it.
Deprecations
from nameparser.config.surnames import KOREAN_SURNAMES now emits a DeprecationWarning naming Lexicon.default().surnames, which holds the same words in 2.8.2 and 3.0. #1007Full release log: https://nameparser.readthedocs.io/en/latest/release_log.html
nameparser 2.8.1 adds warnings for three 3.0 changes 2.8.0 did not announce: writing a Lexicon set field, reading a vocabulary constant in nameparser.config, and reading nameparser.config.regexes. Reading a Lexicon field (lexicon.titles) does not warn, though 3.0 refuses that too. Code that runs with warnings as errors (-W error, or pytest's filterwarnings = error) will fail where it does any of the three.
Deprecations
Lexicon.default().add(titles={"dean"}) now emits a DeprecationWarning naming the field and the migration guide's row for it; 3.0 refuses the call with a TypeError naming the readings that replace it. remove(), Lexicon(...) and dataclasses.replace() with a set field warn too, and add() or remove() with surnames. #754from nameparser.config.titles import TITLES now emits a DeprecationWarning naming Lexicon.default().words(kind="title"), which lists every title in 3.0. nameparser.config.surnames stays. #1007REGEXES now emits a DeprecationWarning; the parser has not read it since 2.0. #1008Full release log: https://nameparser.readthedocs.io/en/latest/release_log.html
nameparser 2.8 is the last 2.x feature release. It warns about everything 3.0 removes, chiefly HumanName and the rest of the 1.x compatibility layer, so that code can move to parse() while 2.x still runs it. It also carries on 2.7's reading of titles that are also given names: a title only inside a title phrase. After 2.8 the 2.x line takes fixes only, and new work goes into 3.0. Highlights:
HumanName("Dr. Juan de la Vega") emits a DeprecationWarning; parse("Dr. Juan de la Vega") reads the same name, with given Juan and family de la Vega. (#925)Queen Latifah and Marquis Johnson give given Queen and Marquis, where 2.7 read both as titles; Her Majesty Queen Elizabeth and Marquis of Queensberry keep the title. (#913)Prince Consort Albert gives title Prince Consort, given Albert, and Lord Justice Leveson title Lord Justice, where 2.7 gave given Prince and given Justice; Prince Fielder keeps the given name Prince. (#913)Some default words changed role: Queen, Marquis, Marquise, Deacon, Burgess, Ranger and Chancellor are titles only inside a title phrase or behind a style (Chancellor Smith gives given Chancellor). Lexicon.default().add(titles={"queen"}) makes a word a title everywhere again. (#913)
To find every use 3.0 removes, run your tests under python -W error::DeprecationWarning. The migration guide maps each use to its replacement. Pickles from 2.7 still load.
Full list of changes: https://nameparser.readthedocs.io/en/latest/release_log.html