如何使用Stanford NER(命名为实体识别器)的python接口? [英] How do I use python interface of Stanford NER(named entity recogniser)?

查看:414
本文介绍了如何使用Stanford NER(命名为实体识别器)的python接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用pyner库在python中使用Stanford NER.这是一个基本代码段.

I want to use Stanford NER in python using pyner library. Here is one basic code snippet.

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

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

When I run this on my local python console(IDLE). It should have given me an output like this

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

但是当我执行此操作时,它显示为空括号.我实际上是新手.

but when I execut this, it showed empty brackets. I am actually new to all this.

推荐答案

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

I am able to run the stanford-ner server in socket mode using:

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

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

and receive the following output from the command line:

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

然后使用python repl:

Then in 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']}

这篇关于如何使用Stanford NER(命名为实体识别器)的python接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆