我使用斯坦福命名实体识别器和Python来查找小说《百年孤独》中的专有名称。有许多是由名字和姓氏组成的,例如“奥雷利亚诺·布恩迪亚”或“圣索菲亚·德拉皮耶达”。这些标记总是分开的,例如“Aureliano”“Buendia”,因为我使用的是标记器。
我想把他们放在一起作为象征,这样他们就可以和斯坦福·内尔一起被标记为“人”。在
我写的代码:import nltk
from nltk.tag import StanfordNERTagger
from nltk import word_tokenize
from nltk import FreqDist
sentence1 = open('book1.txt').read()
sentence = sentence1.split()
path_to_model = "C:\Python34\stanford-ner-2015-04-20\classifiers\english.muc.7class.distsim.crf.ser"
path_to_jar = "C:\Python34\stanford-ner-2015-04-20\stanford-ner.jar"
st = StanfordNERTagger(model_filename=path_to_model, path_to_jar=path_to_jar)
taggedSentence = st.tag(sentence)
def findtags (tagged_text,tag_prefix):
cfd = nltk.ConditionalFreqDist((tag, word) for (word, tag) in taggedSentence
if tag.endswith(tag_prefix))
return dict((tag, cfd[tag].most_common(1000)) for tag in cfd.conditions())
print (findtags('_','PERSON'))
结果如下:{'PERSON': [('Aureliano', 397), ('José', 294), ('Arcadio', 286), ('Buendía', 251), ...
有人有办法吗?我会非常感激的