spacy has an label_ called person. you have several options for the model: small, medium or large. large uses more resources to run
def find_persons(text):
# Create Doc object
doc2 = nlp(text)
# Identify the persons
persons = [ent.text for ent in doc2.ents if ent.label_ == 'PERSON']
# Return persons
return persons
Try nltk to find the Nouns and then pattern match the nouns for valid names:
tokenized_sent = nltk.word_tokenize(sentence)
tagged_sent = nltk.pos_tag(tokenized_sent)
nouns
pronouns
adjectives
verbs
NNP - proper noun singular
PRP - proper noun
VB - verb
DT - determinant
NNP - proper noun singular
PRP - proper noun
VB - verb
DT - determinant