Skip to content

MSc in title makes for some strange behaviour. #41

Closed

Description

@lawli3t

I am currently trying to parse names with the nameparser which works perfectly fine, except i encounter some errors when trying to parse trailing titles such as MSc.

Here is a small example of what I am trying to do:

>>> from nameparser import HumanName
>>> HumanName("Dr. med. univ. Margit Popp")
<HumanName : [
    title: 'Dr. med. univ.' 
    first: 'Margit' 
    middle: '' 
    last: 'Popp' 
    suffix: ''
    nickname: ''
]>
>>> HumanName("Dr. med. univ. Margit Popp, MSc")
<HumanName : [
    title: 'MSc' 
    first: 'Dr. med. univ. Margit Popp' 
    middle: '' 
    last: '' 
    suffix: ''
    nickname: ''
]>

The first example works perfectly fine, but as soon as MSc is in the game it doesnt recognize the other titles nor split the name correctly. I have added MSc (as well as med. + univ.) to the CONSTANTS but it doesnt seem to help. It also acts strange when i just use default settings:

>>> HumanName("Dr. med. univ. Margit Popp, MSc")
<HumanName : [
    title: '' 
    first: 'MSc' 
    middle: '' 
    last: 'Dr. med. univ. Margit Popp' 
    suffix: ''
    nickname: ''
]>

What i would be expecting is:

>>> HumanName("Dr. med. univ. Margit Popp, MSc")
<HumanName : [
    title: 'MSc Dr. med. univ.' 
    first: 'Margit' 
    middle: '' 
    last: 'Popp' 
    suffix: ''
    nickname: ''
]>

I am running python 3.4 with the latest version of nameparser. Is there any possibility of making this work? Am i just missing some customizable setting?

thanks for your help

Activity

  1. derek73 commented on Feb 25, 2016

    @derek73
    Owner

    Hmm, it looks like a bug. Thanks for reporting it. I'll look into it.

    One probably minor thing, the MSc would go into the suffix property because it comes at the end of the name. In a future version I'm going to change those attribute names to prenominal and postnominal so people don't expect it to be semantic. It's based solely on position in the string.

  2. self-assigned this
    on Feb 25, 2016
  3. added this to the v0.3.12 milestone on Feb 25, 2016
  4. derek73 commented on Feb 25, 2016

    @derek73
    Owner

    Ahh, I see now. It's because "MSc" is not in a recognized suffix, so it assumes it's the "lastname, firstname" format. If you add "MSc" to your suffixes set it should work as expected.

        >>> from nameparser.config import CONSTANTS
        >>> CONSTANTS.suffixes.add('msc')
    

    I'll go ahead and add that to the suffix/post-nominal constants in the next release.

  5. lawli3t commented on Feb 26, 2016

    @lawli3t
    Author

    Ah I see thanks, that fixes that problem.

    Another one i have though is that if i add MSc to both suffixes and titles it doesnt work. It works fine for MSc in one of those two though. The data i have is very messy sadly so some rows have the MSc as a prefix others as a suffix. Is there any possibility of incorporating those two?

    Otherwise i'd have to get a bit dirty with multiple instances i guess.

    Thanks for your fast and thorough response though, appreciate it!

    edit:

    hm, doesnt seem the suffix is working sometimes, for instance i have added msc to titles as well as suffixes and get the following results:

    >>> HumanName("MSc Dr. Margit Popp MSc")
    <HumanName : [
        title: 'MSc Dr.' 
        first: 'Margit' 
        middle: 'Popp' 
        last: 'MSc' 
        suffix: ''
        nickname: ''
    ]>

    I would expect MSc to be in the suffix too, even if i omit the first MSc it doesnt get parsed even though it is in the suffix set.

    >>> HumanName("Dr. Margit Popp MSc")
    <HumanName : [
        title: 'Dr.' 
        first: 'Margit' 
        middle: 'Popp' 
        last: 'MSc' 
        suffix: ''
        nickname: ''
    ]>
    >>> HumanName("Dr. Margit Popp, MSc")
    <HumanName : [
        title: 'MSc' 
        first: 'Dr. Margit Popp' 
        middle: '' 
        last: '' 
        suffix: ''
        nickname: ''
    ]>
  6. derek73 commented on Feb 27, 2016

    @derek73
    Owner

    Ok, I think I figured out what's going on. I recently separated suffixes into 2 groups, ones that are acronyms and could be separated by periods, and ones that are not. So I guess this means updating the suffixes set now has no effect. You'll need need to add your custom suffixes to CONSTANTS.suffix_acronyms in this case, or CONSTANTS.suffix_not_acronyms.

    >>> from nameparser import HumanName
    >>> from nameparser.config import CONSTANTS
    >>> CONSTANTS.suffix_acronyms.add('msc')
    >>> HumanName("Dr. Margit Popp MSc")
    <HumanName : [
       title: 'Dr.' 
       first: 'Margit' 
       middle: '' 
       last: 'Popp' 
       suffix: 'MSc'
       nickname: ''
    ]>
    
  7. added 2 commits that reference this issue on Mar 15, 2016
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