我正在使用 Spacy 并尝试检测文本中的名称。例如,text = 'Keras 是一个很好的包。亚当斯密使用黑色汽车。我希望卡特里娜飓风在她的工作中表现出色。'
答案应该是这样的:亚当·斯密和卡特里娜飓风。
谁能推荐一下
spacy 有一个名为 person 的标签。模型有多种选择:小型、中型或大型。 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
尝试 nltk 查找名词,然后对有效名称的名词进行模式匹配:
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