derek73 / python-nameparser

A simple Python module for parsing human names into their individual components
http://nameparser.readthedocs.org/en/latest/
Other
653 stars 104 forks source link

Duke as a first name not a title #125

Closed cas-- closed 2 years ago

cas-- commented 3 years ago

We recently had a new user sign-up and their first name Duke kept disappearing which was identified as a result of parsing the name since Duke was being marked a title.

I have applied the constants workaround for now but it seems that Duke as a first name is becoming more common these days and perhaps this package could consider a fix for this. One thought is that, unless I am mistaken, the title Duke is always followed by 'of' e.g. 'Duke of Edinburgh' so could this be used to distinguish between first name and title?

An example of a famous "first name" Duke was the jazz composer Duke Ellington, although it was a nickname it is still not a title here.

>>> from nameparser import HumanName
>>> HumanName("Duke Ellington")
<HumanName : [
    title: 'Duke' 
    first: '' 
    middle: '' 
    last: 'Ellington' 
    suffix: ''
    nickname: ''
]>

I can workaround the issue as explained in the documentation:

>>> from nameparser.config import CONSTANTS
>>> CONSTANTS.titles.remove('Duke')
>>> HumanName("Duke Ellington")
<HumanName : [
    title: '' 
    first: 'Duke' 
    middle: '' 
    last: 'Ellington' 
    suffix: ''
    nickname: ''
]>
derek73 commented 2 years ago

That sounds reasonable.

Anyone that would like "duke" to be parsed as a title can use:

>>> from nameparser.config import CONSTANTS
>>> CONSTANTS.titles.add('Duke')