1

我正在使用斯坦福命名实体识别器 (NER)的 python 接口。该代码可以在Pyner 代码中找到

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

假定的输出:

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

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

问题:我得到空集,为什么?


我尝试了以下解决方案-StackoverFlow,但它不起作用我收到以下异常:

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

1 回答 1

2

首先使用以下命令以套接字模式运行 stanford-ner 服务器:

java -mx256m -cp stanford-ner.jar edu.stanford.nlp.ie.NERServer \ -loadClassifier 分类器/english.muc.7class.dissim.crf.ser.gz \ -port 8081 -outputFormat inlineXML。

将代码保存在 Windows 批处理文件中并在命令提示符下运行。

您的端口 8080 有问题。这就是我将端口更改为 8081 的原因。在服务器运行后键入您的 python 代码-

>>>import ner
>>>tagger = ner.SocketNER(host='localhost', port=8081)
>>>tagger.get_entities("University of California is located in California, United States")
于 2015-05-16T08:50:35.913 回答