6

这是我的代码和错误消息:

>>> 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 谢谢!

4

1 回答 1

0
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 >

这应该有效。

于 2013-03-01T02:37:12.907 回答