spacy 有一个名为 person 的 label_。您有多种型号可供选择:小型、中型或大型。Large 使用更多资源来运行
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
Run Code Online (Sandbox Code Playgroud)
尝试 nltk 查找名词,然后对有效名称的名词进行模式匹配:
tokenized_sent = nltk.word_tokenize(sentence)
tagged_sent = nltk.pos_tag(tokenized_sent)
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)