pythonpython-3.12

The name "Maj Kmetic" has an emtpy first name when using the nameparser library in python


I already made an issue about this on the nameparser github page but it looked kind of "Inactive", so I wanted to try and ask this question here.
When I parse the name "Maj Kmetic" and I want to retrieve the first name and the surnames, the first name is empty.

Code:

from nameparser import HumanName

name = HumanName('Maj Kmetic')
print(f"First: {name.first}")
print(f"Last: {name.surnames}")

Output:

First: 
Last: Kmetic

But when I use the names: "Ma Kmetic" and "Maji Kmetic" the first name isn't empty: Outputs:

First: Ma
Last: Kmetic

--- AND ---

First: Maji
Last: Kmetic

In general the first name "Maj" seems to be the problem, changing the last name doesn't seem to have any affect on the general outcome.


Solution

  • The library in question treats the string Maj as a formal title (ostensibly “Major”); see nameparser/config/titles.py:L383.

    According to the documentation, you can remove this string from consideration as a title (and instead parse it as part of the name) by calling:

    from nameparser.config import CONSTANTS
    
    CONSTANTS.titles.remove('Maj')