python - 在 python 中使用 stanford 标记器时出错

标签 python stanford-nlp pos-tagger

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

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

这应该有效。

关于python - 在 python 中使用 stanford 标记器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13478779/

相关文章:

java - java中如何从字符串中提取子字符串

python - 在 python 3.4 上使用 nltk 3.0 进行 pos 标记时出现编码错误

python - 确定 POS-Tagger 的 HMM 模型的准确性

python - 如何仅 .replace() 单词的一部分?并从字符串中提取整数?

python - 如何将日期列表转换为字符串列表

java - 如何在java中使用stanford nlp从文本中获取有意义的单词

python - 使用 Stanford coreNLP 在 python nltk 中进行共指解析

python - 以对数刻度计算值

python - Bjoern v/s Gunicorn POST 请求

java - 如何使用 stanford 获取复合词的 POS 标签