【问题标题】:How do I use python interface of Stanford NER(named entity recogniser)?如何使用斯坦福 NER(命名实体识别器)的 python 接口?
【发布时间】:2013-03-30 19:48:35
【问题描述】:

我想通过 pyner 库在 python 中使用斯坦福 NER。这是一个基本的代码sn-p。

import ner 
tagger = ner.HttpNER(host='localhost', port=80)
tagger.get_entities("University of California is located in California, United States")

当我在本地 python 控制台 (IDLE) 上运行它时。它应该给我这样的输出

  {'LOCATION': ['California', 'United States'],
 'ORGANIZATION': ['University of California']}

但是当我执行这个时,它显示了空括号。我实际上对这一切都很陌生。

【问题讨论】:

  • 您使用什么方法将 stanford-ner 服务器作为 http 服务器运行?我可以成功地将它作为套接字服务器运行,并使用带有 tagger = ner.SocketNER(host='localhost', port=8080) 的 pyner 客户端并获得您希望收到的答案。
  • 你能发布你的代码吗? ...我希望 NER 在我的 IDLE 控制台上输出 @Ryan O'Neill

标签: python-2.7 nlp stanford-nlp named-entity-recognition


【解决方案1】:

我可以使用套接字模式运行 stanford-ner 服务器:

java -mx1000m -cp stanford-ner.jar edu.stanford.nlp.ie.NERServer \
    -loadClassifier classifiers/english.muc.7class.distsim.crf.ser.gz \
    -port 8080 -outputFormat inlineXML

并从命令行接收以下输出:

Loading classifier from 
/Users/roneill/stanford-ner-2012-11-11/classifiers/english.muc.7class.distsim.crf.ser.gz 
... done [1.7 sec].

然后在python repl中:

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ner
>>> tagger = ner.SocketNER(host='localhost', port=8080)
>>> tagger.get_entities("University of California is located in California, United States")
{'ORGANIZATION': ['University of California'], 'LOCATION': ['California', 'United States']}

【讨论】:

  • 在这之前你下载了什么? ...如何准确启动服务器?...我现在已经下载了斯坦福命名实体识别器 1.2.7 版?
  • Bingo ...谢谢大佬...基本理解有问题
  • 如果我想让 NER 识别不同于 'ORGANISATION','LOCATION' 的类型怎么办.....
  • 对我来说,问题不在于 -outputFormat inlineXML(我在 pyner README 示例中的任何地方都没有看到)。真的非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-25
  • 1970-01-01
  • 2015-02-22
  • 1970-01-01
  • 2019-03-17
相关资源
最近更新 更多