John10 , michaelscott, James.white , Jr.Jones , James-Anderson ,WhiteWalter10 -- These are some of the different cases of usernames possible(there may be more ). I have about 200K such usernames . I need to extract the first name from all of them. If only first name not possible then atleast only the relevant names (for example - WhiteWalter10 should give only Walter or White and Walter ). I already have a dataset of surnames so I can filter the first name
I think your best bet is a gazetteer approach. If you go to this link, you will find plenty of datasets containing lists of existing first names. This should help you detect a big majority of first names using regular expressions.
Now, there are some preprocessing steps you could take:
- remove any digits, punctuation, etc.
- if you have upper cases, you could split the username such that "MichaelScott" becomes "Michael" and "Scott". Now, in this case, you end up with two things that could be the first name. You could use the assumption that the first one is the first name and the second one is the surname.
Once you've done this, look at usernames where no first names were detected. Now, it could very well be that the username doesn't contain any first names (i.e. user123213543), or the user is bit cheeky and could use special characters or digits to write their first name (i.e. $am, B0b, etc.). If these situations exist, you could create strategies to deal with them.