python - Python NLTK:斯坦福 NER 标记器错误消息:NLTK 无法找到 java 文件
问题描述
试图让斯坦福 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/
推荐阅读
- android - 如何在 Retrofit 2.0 中处理分页/加载更多?
- c++ - 在 Debug 配置中编译工作正常,但 Release 给出链接错误
- rust - 为什么不能调用 trait 对象上的函数时与 `Self: Sized` 绑定?
- ruby-on-rails - Ruby on rails 在限制之前反转
- javascript - 为单击事件的每一行添加带有下拉列表和输入字段的jQuery DataTables行?
- javascript - 检查引号和括号是否平衡
- drupal - 如果 XML 中没有状态字段,则默认使用 Feed 模块节点发布节点导入
- python - 在 CLI 命令中访问 Flask 应用程序上下文
- python - 我的 TensorFlow 代码在输入的维度上产生错误
- json - 如何将JSON文件转换为更深一步