Python PyNER 库没有给出任何输出

Python PyNER library doesn't give any output

我想使用 pyNER 库从句子中提取名字。

我在我的ubuntu机器上安装了ner,然后我写了下面的脚本来测试

>>> import ner
>>> tagger = ner.HttpNER(host='localhost', port=80)
>>> tagger.json_entities("Alice went to the Museum of Natural History.")

通常,我必须得到这个输出:

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

但我什么也没得到:

{}

我该如何解决这个问题?

谢谢,

看起来有问题 (https://github.com/dat/pyner/issues/2)

要使其正常工作,您必须指定输出格式 (slashTags):

tagger = ner.SocketNER(host='localhost',port=80, output_format='slashTags')

此外,我会考虑使用除 80 之外的另一个端口,因为该端口通常保留用于网络流量。

此外,如果这不起作用,请使用 SocketNER 而不是 HttpNER 并按照 NER 常见问题解答

中的说明进行操作

http://nlp.stanford.edu/software/crf-faq.shtml#cc

cp stanford-ner.jar stanford-ner-with-classifier.jar 
jar -uf stanford-ner-with-classifier.jar classifiers/english.all.3class.distsim.crf.ser.gz 
java -mx500m -cp stanford-ner-with-classifier.jar edu.stanford.nlp.ie.NERServer -port 9191 -loadClassifier classifiers/english.all.3class.distsim.crf.ser.gz &

然后在您的 python 脚本中

import ner
tagger = ner.SocketNER(host='localhost',port=9191, output_format='slashTags')
print tagger.get_entities("University of California is located in California, United States")