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.

4

1 回答 1

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']}
于 2013-03-30T20:44:58.610 回答