Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use python interface of Stanford NER(named entity recogniser)?

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

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.

like image 725
Vinit Gaikwad Avatar asked Mar 30 '13 19:03

Vinit Gaikwad


1 Answers

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

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']}
like image 145
Ryan O'Neill Avatar answered Oct 17 '22 08:10

Ryan O'Neill