Python NLTK:Stanford NER标记器错误消息:NLTK无法找到Java文件

时间:2018-10-18 04:21:37

标签: python nltk stanford-nlp ner

试图让Stanford NER使用Python。按照网上的一些说明进行操作,但收到错误消息:“ NLTK无法找到Java文件! 使用软件特定的配置参数或设置JAVAHOME环境变量。”出了什么问题?谢谢!

from nltk.tag.stanford import StanfordNERTagger
from nltk.tokenize import word_tokenize

model = r'C:\Stanford\NER\classifiers\english.muc.7class.distsim.crf.ser.gz'
jar = r'C:\Stanford\NER\stanford-ner-3.9.1.jar'

ner_tagger = StanfordNERTagger(model, jar, encoding = 'utf-8')

text = 'While in France, Christine Lagarde discussed short-term stimulus ' \
       'efforts in a recent interview with the Wall Street Journal.'

words = word_tokenize(text)
classified_words = ner_tagger.tag(words)

1 个答案:

答案 0 :(得分:0)

在网络上找到了解决方案。用您自己的路径替换。

 import os

 java_path = "C:/../../jdk1.8.0_101/bin/java.exe"   
 os.environ['JAVAHOME'] = java_path

或:

import nltk

nltk.internals.config_java('C:/../../jdk1.8.0_101/bin/java.exe')

来源:https://tianyouhu.wordpress.com/2016/09/01/problem-of-nltk-with-stanfordtokenizer/