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.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Vinit Gaikwad
  • 329
  • 9
  • 21
  • 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. – Ryan O'Neill Mar 30 '13 at 20:23
  • Can you post ur code? ... I want NER's output on my IDLE console @Ryan O'Neill – Vinit Gaikwad Mar 30 '13 at 20:39

1 Answers1

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']}
Mark E. Haase
  • 25,965
  • 11
  • 66
  • 72
Ryan O'Neill
  • 3,727
  • 22
  • 27
  • 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? – Vinit Gaikwad Mar 30 '13 at 20:51
  • 1
    I download the zip file located on the [Stanford Named Entity Recognizer (NER)](http://nlp.stanford.edu/software/CRF-NER.shtml) website. The one that says [Download Stanford Named Entity Recognizer version 1.2.7](http://nlp.stanford.edu/software/stanford-ner-2012-11-11.zip) – Ryan O'Neill Mar 30 '13 at 20:58
  • Bingo ... Thanks man... there was a problem with basic understanding – Vinit Gaikwad Mar 30 '13 at 21:29
  • and What if I want NER to recognize a different type than 'ORGANISATION','LOCATION' ..... – Vinit Gaikwad Mar 30 '13 at 21:36
  • I recommend asking a separate question and providing an example of what you are looking to receive as an answer. – Ryan O'Neill Mar 30 '13 at 21:40
  • http://stackoverflow.com/questions/15746695/how-do-i-include-more-than-one-classifiers-when-using-stanford-named-entity-reco – Vinit Gaikwad Apr 01 '13 at 15:58
  • 4
    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. – scharfmn Oct 17 '14 at 07:58
  • Getting error "Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory". Downloaded sl4j.zip but not sure where to include it. – Anish Nov 06 '16 at 04:47