我在python教程网站上找到了以下代码:
test_pic[pic1-1]
test_pic[pic1-2]
test_pic[pic1-3]
test_pic[pic2-14]
test_pic[pic2-15]
test_pic[pic3-100]
test_pic[pic3-200]
test_pic[pic3-300]
错误如下:
from nltk.tag import StanfordNERTagger
from nltk.tokenize import word_tokenize
stanford_classifier = open(r"C:\Users\DELL7810\AppData\Local\Programs\Python\Python37\stanford-ner-2018-02-27\classifiers\english.all.3class.distsim.crf.ser.gz")
stanford_ner_path = open(r"C:\Users\DELL7810\AppData\Local\Programs\Python\Python37\stanford-ner-2018-02-27\stanford-ner.jar")
st = StanfordNERTagger(stanford_classifier, stanford_ner_path)
text = 'While in France, Christine Lagarde discussed short-term stimulus efforts in a recent interview with the Wall Street Journal.'
tokenized_text = word_tokenize(text)
classified_text = st.tag(tokenized_text)
print (classified_text)
答案 0 :(得分:0)
在此documentation page中可以看到,StanfordNERTagger
将文件路径作为参数:
StanfordNERTagger(path_to_model, path_to_jar)
您的代码崩溃是因为open()
将为您提供文件对象,而这并不是StanfordNERTagger
期望的参数。
将路径直接作为StanfordNERTagger
的参数,如下所示:
st = StanfordNERTagger("C:\Users\DELL7810\AppData\Local\Programs\Python\Python37\stanford-ner-2018-02-27\classifiers\english.all.3class.distsim.crf.ser.gz", "C:\Users\DELL7810\AppData\Local\Programs\Python\Python37\stanford-ner-2018-02-27\stanford-ner.jar")