How to install and invoke Stanford NERTagger?

2019-01-19 22:49发布

I am trying to use NLTK interface for Stanford NER in the python enviornment, nltk.tag.stanford.NERTagger.

from nltk.tag.stanford import NERTagger
st = NERTagger('/usr/share/stanford-ner/classifiers/all.3class.distsim.crf.ser.gz',
               '/usr/share/stanford-ner/stanford-ner.jar') 
st.tag('Rami Eid is studying at Stony Brook University in NY'.split()) 

I am supposed to get the output:

[('Rami', 'PERSON'), ('Eid', 'PERSON'), ('is', 'O'), ('studying', 'O'),
('at', 'O'), ('Stony', 'ORGANIZATION'), ('Brook', 'ORGANIZATION'),
('University', 'ORGANIZATION'), ('in', 'O'), ('NY', 'LOCATION')]

I have installed NLTK according the procedure described in the NLTK website. However, I can not find /usr/share/stanford-ner at all. Where and how do I find the whole package and install it in my directory.

5条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-19 23:02
from nltk.tag.stanford import StanfordNERTagger
st = StanfordNERTagger('/Users/mahendrabilagi/Desktop/stanford-ner-2017-06-09/classifiers/english.all.3class.distsim.crf.ser.gz',
           '/Users/mahendrabilagi/Desktop/stanford-ner-2017-06-09/stanford-ner.jar')
print st.tag('Rami Eid is studying at Stony Brook University in Bengaluru'.split())
查看更多
欢心
3楼-- · 2019-01-19 23:15

One has to download the Stanford package independent of the NLTK download, put it in the place the path indicates and change the directory name in the path described in the NLTK document to whatever name one wants to use for the directory. It would have been nice if the NLTK documentation would state this explicitly.

查看更多
冷血范
4楼-- · 2019-01-19 23:22

Although this is a link only answer, it will resolve the OP's question.

For Windows: https://gist.github.com/alvations/0ed8641d7d2e1941b9f9

For Linux: https://gist.github.com/alvations/e1df0ba227e542955a8a


EDITED

But do note that this is not an eternal solution and since Stanford NLP tools and NLTK changes more than 2-3 times a year, please check the https://github.com/nltk/nltk/wiki/Installing-Third-Party-Software for latest setup instructions for NLTK API to Stanford tools.

Solutions above are posted on 17.03.2016

查看更多
地球回转人心会变
5楼-- · 2019-01-19 23:24

It might be easier to look at the more recent interfaces to Stanford CoreNLP for python which are available here: http://nlp.stanford.edu/software/corenlp.shtml

查看更多
等我变得足够好
6楼-- · 2019-01-19 23:26

Just thought it would be worth mentioning that the import line is now:

from nltk.tag.stanford import StanfordNERTagger
查看更多
登录 后发表回答