【发布时间】:2016-09-12 16:41:02
【问题描述】:
我正在使用带有 Python 的斯坦福命名实体识别器来查找小说“一百年的孤独”中的专有名称。其中有许多由名字和姓氏组成,例如“奥雷里亚诺布恩迪亚”或“圣索非亚德拉彼达”。这些令牌总是分开的,例如“Aureliano”“Buendia”,因为我正在使用标记器。 我想将它们作为令牌放在一起,这样它们就可以与斯坦福 NER 一起标记为“PERSON”。
我写的代码:
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), ...
有人有解决办法吗?我会很感激的
【问题讨论】:
标签: python stanford-nlp named-entity-recognition