NLTK 中的斯坦福 NER 标注器

Stanford NER Tagger in NLTK

我正在尝试在 Python 中导入 Stanford 命名实体识别器。这已经内置在 NLTK 包中。但是,我的以下代码不起作用:

 from nltk.tag.stanford import NERTagger
 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
 ImportError: cannot import name NERTagger

可能是什么原因?在我阅读的所有文章中,它都默认工作。谢谢。

那个 class 已经 renamed to StanfordNERTagger in version 3.0.3 (commit 190673c7).

因此,对于 nltk >= 3.0.3,您需要改用此导入:

from nltk.tag import StanfordNERTagger

(你也可以做 from nltk.tag.stanford import StanfordNERTagger,但是因为他们现在也在 nltk.tag 模块中提供了一个方便的导入,这可能是他们想要使用的,那个导入位置应该不会像这样在未来发生变化。)