2016-08-29 83 views
0

我正嘗試使用NLTK中的StanfordPOSTagger。我下載了斯坦福POS全標籤。我已經設置NLTK無法找到斯坦福POS標記模型文件

CLASSPATH=/home/waheeb/Stanford_Tools/stanford-postagger-full-2015-12-09 /stanford-postagger.jar 
STANFORD_MODELS=home/waheeb/Stanford_Tools/stanford-postagger-full-2015-12-09/models 

當我鍵入蟒蛇如下:

>>> from nltk.tag import StanfordPOSTagger 
>>> st = StanfordPOSTagger('english-bidirectional-distsim.tagger') 

我收到以下錯誤:

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/tag /stanford.py", line 136, in __init__ 
super(StanfordPOSTagger, self).__init__(*args, **kwargs) 
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/tag/stanford.py", line 56, in __init__ 
env_vars=('STANFORD_MODELS',), verbose=verbose) 
File "/home/waheeb/anaconda2/lib/python2.7/site-packages /nltk/internals.py", line 573, in find_file 
file_names, url, verbose)) 
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/internals.py", line 567, in find_file_iter 
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div)) 

LookupError:

========================================================================= 
NLTK was unable to find the english-bidirectional-distsim.tagger file! 
Use software specific configuration paramaters or set the TANFORD_MODELS environment variable. 
========================================================================== 

這是爲什麼??

+1

見https://gist.github.com/alvations/e1df0ba227e542955a8a – alvas

回答

1

在調用python腳本之前,您忘記在命令行中使用export。即

[email protected]:~$ export STANFORDTOOLSDIR=$HOME 
[email protected]:~$ export CLASSPATH=$STANFORDTOOLSDIR/stanford-postagger-full-2015-12-09/stanford-postagger.jar 
[email protected]:~$ export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-postagger-full-2015-12-09/models 
[email protected]:~$ python 

欲瞭解更多詳情,請參閱https://gist.github.com/alvations/e1df0ba227e542955a8a


類似的問題包括:

+0

@alvas ....我出口他們了。我忘了在問題中提到這一點。但錯誤仍然存​​在。 –

+1

您是否仔細按照https://gist.github.com/alvations/e1df0ba227e542955a8a上的說明操作? – alvas

+0

完美...謝謝。如果您還注意到我忘記在STANFORD_MODELS =/home之前添加'/' –

相關問題