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

1

14

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.

Neustria answered 30/3, 2013 at 19:48 Comment(2)
What method are you using to run the stanford-ner server as an http server? I can successfully run it as a socket server and use the pyner client with tagger = ner.SocketNER(host='localhost', port=8080) and get the answer you are looking to receive.Gangrene
Can you post ur code? ... I want NER's output on my IDLE console @Ryan O'NeillNeustria
P
27

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']}
Pontifical answered 30/3, 2013 at 20:44 Comment(8)
What did u download before all this? ... how to start the server exactly?... I have downloaded Stanford Named Entity Recognizer version 1.2.7 as of now?Neustria
I download the zip file located on the Stanford Named Entity Recognizer (NER) website. The one that says Download Stanford Named Entity Recognizer version 1.2.7Gangrene
Bingo ... Thanks man... there was a problem with basic understandingNeustria
and What if I want NER to recognize a different type than 'ORGANISATION','LOCATION' .....Neustria
I recommend asking a separate question and providing an example of what you are looking to receive as an answer.Gangrene
#15747195Neustria
For me, the problem was not including -outputFormat inlineXML (which I do not see anywhere in the pyner README example). Thank you very much indeed.Scarlett
Getting error "Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory". Downloaded sl4j.zip but not sure where to include it.Oppression

© 2022 - 2024 — McMap. All rights reserved.