【发布时间】:2015-01-26 02:07:08
【问题描述】:
我正在尝试使用 nltk.tag.stanford module 标记一个句子(首先像 wiki 的示例),但我不断收到以下错误:
Traceback (most recent call last):
File "test.py", line 28, in <module>
print st.tag(word_tokenize('What is the airspeed of an unladen swallow ?'))
File "/usr/local/lib/python2.7/dist-packages/nltk/tag/stanford.py", line 59, in tag
return self.tag_sents([tokens])[0]
File "/usr/local/lib/python2.7/dist-packages/nltk/tag/stanford.py", line 81, in tag_sents
stdout=PIPE, stderr=PIPE)
File "/usr/local/lib/python2.7/dist-packages/nltk/internals.py", line 160, in java
raise OSError('Java command failed!')
OSError: Java command failed!
或关注LookupError 错误:
LookupError:
===========================================================================
NLTK was unable to find the java file!
Use software specific configuration paramaters or set the JAVAHOME environment variable.
===========================================================================
这是示例代码:
>>> from nltk.tag.stanford import POSTagger
>>> st = POSTagger('/usr/share/stanford-postagger/models/english-bidirectional-distsim.tagger',
... '/usr/share/stanford-postagger/stanford-postagger.jar')
>>> st.tag('What is the airspeed of an unladen swallow ?'.split())
我也使用了word_tokenize 而不是split,但没有任何区别。
我也重新安装了java或者jdk!我的所有搜索都不成功!类似nltknltk.internals.config_java() 或...!
注意:我使用的是 linux (Xubuntu)!
【问题讨论】:
标签: python nlp nltk stanford-nlp python-textprocessing