2017-09-25 71 views
2

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> 
=============================== 
+0

请参阅https://stackoverflow.com/q/46734119/610569 – alvas

回答

1

您需要添加罐子斯坦福解析器和模型到CLASSPATH:

  1. 下载斯坦福CoreNLP 3.8.0(和中国模特JAR)可以在这里找到:https://stanfordnlp.github.io/CoreNLP/download.html

  2. 发生在斯坦福CoreNLP文件夹中的中国模特罐子

  3. 添加到您的Python:

    os.environ['CLASSPATH'] = "/path/to/stanford-corenlp-full-2017-06-09/*" 
    

我认为应该解决您的问题。

+0

我这样做“import os os.environ ['CLASSPATH'] =”fonttian/home/NLP/stanford-corenlp-full-2017- 06-09/*“ – FontTian

+0

但没有任何事情发生,”NLTK无法找到stanford-parser \ .jar!设置CLASSPATH 环境变量。 欲了解更多信息,斯坦福解析器\的.jar,请参阅: FontTian

+0

事实上,我无法找到斯坦福解析器\的.jar在“stanford-corenlp-full-2017-06-09” – FontTian