繁体   English   中英

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

[英]Python NLTK: Stanford NER tagger error message: NLTK was unable to find the java file

试图让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)

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

  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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM