设置:Anaconda上的Python 3.4,Windows 10 IPEC 64位VM NLTK 版本3.0.2,stanford-parser-3.5.2
我昨天成功实施了一项功能并使其正常运行。这是代码:
def parnow(temp_in):
import os
from nltk.parse import stanford
java_path = "/Program Files (x86)/Java/jdk1.8.0_05/bin/java.exe"
os.environ['STANFORD_PARSER'] = '/stanford'
os.environ['STANFORD_MODELS'] = '/stanford'
os.environ['JAVAHOME'] = java_path
parser = stanford.StanfordParser(model_path="/stanford/parser/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
sentences = parser.raw_parse_sents((temp_in))
for myListiterator in sentences:
for t in myListiterator:
return(t)
昨天工作正常,我进行了几次测试。今天早上,当我运行相同的功能时,例如parnow("This is a test.")
我收到一条错误消息说" NLTK无法找到gs文件!" 。
这是我尝试过的:
C:\\stanford\\parser\\edu\\stanford\\nlp\\models\\lexparser\\englishPCFG.ser.gz
作为路径。[编辑]错误讯息:
parnow("This is my last resort")
Out[3]: Tree('ROOT', [Tree('NP', [Tree('NNP', ['T'])])])Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 339, in __call__
return method()
File "C:\Anaconda3\lib\nltk\tree.py", line 726, in _repr_png_
subprocess.call([find_binary('gs', binary_names=['gswin32c.exe', 'gswin64c.exe'], env_vars=['PATH'], verbose=False)] +
File "C:\Anaconda3\lib\nltk\internals.py", line 546, in find_binary
binary_names, url, verbose))
File "C:\Anaconda3\lib\nltk\internals.py", line 540, in find_binary_iter
url, verbose):
File "C:\Anaconda3\lib\nltk\internals.py", line 519, in find_file_iter
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find the gs file!
Use software specific configuration paramaters or set the PATH environment variable.
===========================================================================