1

I am using the python interface of Stanford Named Entity Recognizer (NER). The code can be found at Pyner Code

import ner


if __name__ == "__main__": 
  tagger = ner.HttpNER(host='localhost', port=8080)
  print tagger.get_entities("University of California is located in California, United States")
  print tagger.json_entities("Alice went to the Museum of Natural History.")

The supposed outputs:

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

'{"ORGANIZATION": ["Museum of Natural History"], "PERSON": ["Alice"]}'

Problem: I am getting empty sets why?


I tried the following solution-StackoverFlow but it didn't work I received the following exception:

Exception in thread "main" java.net.BindException: Address already in use
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
        at java.net.ServerSocket.bind(ServerSocket.java:376)
        at java.net.ServerSocket.<init>(ServerSocket.java:237)
        at java.net.ServerSocket.<init>(ServerSocket.java:128)
        at edu.stanford.nlp.ie.NERServer.<init>(NERServer.java:71)
        at edu.stanford.nlp.ie.NERServer.main(NERServer.java:331)
Cœur
  • 37,241
  • 25
  • 195
  • 267
Hani Goc
  • 2,371
  • 5
  • 45
  • 89

1 Answers1

2

First Run the stanford-ner server in socket mode using:

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

Save the code in a windows batch file and run it in command prompt.

There is a problem with your port 8080. That's why I have changed the port to 8081. After the server gets running type your python code-

>>>import ner
>>>tagger = ner.SocketNER(host='localhost', port=8081)
>>>tagger.get_entities("University of California is located in California, United States")
noobcoder
  • 151
  • 2
  • 2
  • 13