我正在尝试使用stanford自然语言工具包NLTK.安装完所需文件后,我开始执行演示代码:http: //www.nltk.org/index.html
>>> import nltk
>>> sentence = """At eight o'clock on Thursday morning
... Arthur didn't feel very good."""
>>> tokens = nltk.word_tokenize(sentence)
>>> tokens
['At', 'eight', "o'clock", 'on', 'Thursday', 'morning',
Run Code Online (Sandbox Code Playgroud)
'亚瑟','做','不','感觉','非常','好','.']
>>> tagged = nltk.pos_tag(tokens)
>>> tagged[0:6]
[('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'),
Run Code Online (Sandbox Code Playgroud)
('星期四','NNP'),('早上','NN')]
>>> entities = nltk.chunk.ne_chunk(tagged)
>>> entities
Run Code Online (Sandbox Code Playgroud)
然后我收到消息:
LookupError:
===========================================================================
NLTK was unable to find the gs file!
Use software specific configuration paramaters or set the PATH environment variable.
Run Code Online (Sandbox Code Playgroud)
我试过谷歌,但是没有人告诉你遗漏的gs文件是什么.
Jas*_*rth 12
我也遇到了这个错误.
gs
代表鬼魂.你得到错误,因为你的chunker试图使用ghostscript绘制句子的解析树,如下所示:
我在使用IPython; 调试问题我verbose
使用命令设置回溯详细程度,该命令%xmode verbose
打印每个堆栈帧的局部变量.(参见下面的完整追溯)文件名是:
file_names=['gs', 'gswin32c.exe', 'gswin64c.exe']
一点谷歌搜索gswin32c.exe
告诉我这是ghostscript.
/Users/jasonwirth/anaconda/lib/python3.4/site-packages/nltk/__init__.py in find_file_iter(filename='gs', env_vars=['PATH'], searchpath=(), file_names=['gs', 'gswin32c.exe', 'gswin64c.exe'], url=None, verbose=False)
517 (filename, url))
518 div = '='*75
--> 519 raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
520
521 def find_file(filename, env_vars=(), searchpath=(),
LookupError:
===========================================================================
NLTK was unable to find the gs file!
Use software specific configuration paramaters or set the PATH environment variable.
===========================================================================
Run Code Online (Sandbox Code Playgroud)
只是为了添加到先前的答案,如果您将 'entities' 替换为 'print(entities)',您将不会收到错误消息。
没有 print() 控制台/笔记本不知道如何“绘制”树对象。
小智 5
对 Jason Wirth 的回答有一点补充。在 Windows 下,这行代码将在环境变量 PATH 中搜索“gswin64c.exe”,但是,ghostscript 安装程序不会将二进制文件添加到 PATH,因此要使其正常工作,您需要找到 ghostscript 的安装位置并将 /bin 子文件夹添加到 PATH。
例如,在我的情况下,我将C:\Program Files\gs\gs9.19\bin 添加到 PATH。
归档时间: |
|
查看次数: |
6958 次 |
最近记录: |