NLTK无法找到stanford-parser \ .jar!在nltk3.2.5中设置CLASSPATH环境变量
问题描述:
nltk.parse.stanford。NLTK无法找到stanford-parser .jar!在nltk3.2.5中设置CLASSPATH环境变量
from nltk.parse.stanford import *
# CoreNLPServer = CoreNLPServer(path_to_jar="/home/fonttian/NLP/stanford/")
# dep_parser=StanfordDependencyParser(model_path="/home/fonttian/NLP/stanford/stanford-chinese-corenlp-2017-06-09-models/edu/stanford/nlp/models/lexparser/chinesePCFG.ser.gz")
====>
dep_parser=StanfordDependencyParser(model_path="edu/stanford/nlp/models
/lexparser/chinesePCFG.ser.gz “) 文件” /home/fonttian/anaconda3/lib/python3.6/site- 包/ NLTK /解析/ stanford.py “线路52,在初始化 键=拉姆达model_path:os.path.dirname(model_path) 文件” /home/fonttian/anaconda3/lib/python3.6/site- 包/nltk/internals.py“,第716行,在find_jar_iter中 raise Looku PERROR( '\ n \ n%S \ n%S \ n%s' 的%(DIV,味精,DIV)) LookupError:
============================
NLTK was unable to find stanford-parser\.jar! Set the CLASSPATH
environment variable.
For more information, on stanford-parser\.jar, see:
<https://nlp.stanford.edu/software/lex-parser.shtml>
===============================
答
您需要添加罐子斯坦福解析器和模型到CLASSPATH:
下载斯坦福CoreNLP 3.8.0(和中国模特JAR)可以在这里找到:https://stanfordnlp.github.io/CoreNLP/download.html
发生在斯坦福CoreNLP文件夹中的中国模特罐子
-
添加到您的Python:
os.environ['CLASSPATH'] = "/path/to/stanford-corenlp-full-2017-06-09/*"
我认为应该解决您的问题。
请参阅https://stackoverflow.com/q/46734119/610569 – alvas