NLTK无法找到stanford-parser \ .jar!设置CLASSPATH环境变量

时间:2017-09-25 14:34:58

标签: nlp nltk stanford-nlp

nltk3.2.5中的nltk.parse.stanford。

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- packages / nltk / parse / stanford.py",第52行, init         key = lambda model_path:os.path.dirname(model_path)       文件" /home/fonttian/anaconda3/lib/python3.6/site- packages / nltk / internals.py",第716行,在find_jar_iter中         引发LookupError(' \ n \ n%s \ n%s \ n%s'%(div,msg,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>
===============================

2 个答案:

答案 0 :(得分:1)

您需要将Stanford解析器和模型的jar添加到CLASSPATH中:

  1. 下载斯坦福CoreNLP 3.8.0(和中国模特jar):https://stanfordnlp.github.io/CoreNLP/download.html

  2. 将中国模型jar放入Stanford CoreNLP文件夹

  3. 将此添加到您的Python:

    os.environ['CLASSPATH'] = "/path/to/stanford-corenlp-full-2017-06-09/*"
    
  4. 我认为应该解决你的问题。

答案 1 :(得分:0)

从以下位置下载它们:

stanford / stanford-parser.jar.zip

http://www.java2s.com/Code/Jar/s/Downloadstanfordparserjar.htm

stanford-parser-3.5.2-models.jar

http://central.maven.org/maven2/edu/stanford/nlp/stanford-parser/3.5.2/

并在代码中指向文件路径。