[英]Error when using stanford tagger in python
這是我的代碼和錯誤消息:
>>> 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>
===========================================================================
我該如何解決這個問題? 我真的想在Python中使用stanford tagger謝謝!
from nltk.tag.stanford import POSTagger
st = POSTagger( < path to tagger >, < path to stanford NLP package/stanford-postagger.jar >)
包括兩個參數的完整路徑。
如果有效,那么試試一個例句
st.tag('What is the airspeed of an unladen swallow ?'.split())
檢查是否已將Stanford Parser路徑添加到CLASSPATH
環境變量
export CLASSPATH = {CLASSPATH}: < path to stanford NLP package >
這應該工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.