[英]Error when using stanford tagger in python
This is my code and the error message: 这是我的代码和错误消息:
>>> from nltk.tag.stanford import StanfordTagger
>>> st = StanfordTagger('bidirection-distsim-wsj-0-18.tagger')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/tag/stanford.py", line 42, in __init__
verbose=verbose)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/internals.py", line 597, in find_jar
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find ! Set the CLASSPATH environment variable.
For more information, on , see:
<http://nlp.stanford.edu/software>
===========================================================================
How can I fix that? 我该如何解决这个问题? I really want to use stanford tagger in Python Thank you! 我真的想在Python中使用stanford tagger谢谢!
from nltk.tag.stanford import POSTagger
st = POSTagger( < path to tagger >, < path to stanford NLP package/stanford-postagger.jar >)
Include the complete path for both parameters. 包括两个参数的完整路径。
If that works, then try a sample sentence 如果有效,那么试试一个例句
st.tag('What is the airspeed of an unladen swallow ?'.split())
Check if you have added the Stanford Parser path to CLASSPATH
environment variable 检查是否已将Stanford Parser路径添加到CLASSPATH
环境变量
export CLASSPATH = {CLASSPATH}: < path to stanford NLP package >
This should work. 这应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.