3
$\begingroup$

I was testing the StanfordNERTagger using the NLTK wrapper and this warning appeared:

DeprecationWarning: The StanfordTokenizer will be deprecated in version 
3.2.5. Please use nltk.tag.corenlp.CoreNLPPOSTagger or 
nltk.tag.corenlp.CoreNLPNERTagger instead.
super(StanfordNERTagger, self).__init__(*args, **kwargs)

My code looks like this:

from nltk import word_tokenize, pos_tag, ne_chunk
from nltk.tag import StanfordNERTagger

sentence = "Today George went to school and met his friend Peter."

# stanford's NER tagger 3 entity classification
st = StanfordNERTagger('/home/hercules/Desktop/PhD/Tools/stanford-ner-
     2017-06-09/classifiers/english.all.3class.distsim.crf.ser.gz',
     '/home/hercules/Desktop/PhD/Tools/stanford-ner-2017-06-09/stanford-
     ner.jar',
     encoding='utf-8')

tokenized_text = word_tokenize(sentence)
classified_text = st.tag(tokenized_text)

print("Stanford NER tagger:")
print(classified_text)

I tried to use CoreNLPNERTagger but I could not find any examples or documentation. I only found this link: where it gives something like an example in the comments of the class CoreNLPNERTagger(CoreNLPTagger) (I found it by searching the keyword "CoreNLPNERTagge")

I tried to follow that example with no use. I think I should start (if that is the correct term) the coreNLP server first but if is that the case I don't know how.

If anyone got any idea or advice I would be grateful.

$\endgroup$
1
  • $\begingroup$ I upgraded to NLTK 3.3 and the message disappeared. $\endgroup$
    – tmsss
    Jul 25, 2018 at 15:31

2 Answers 2

2
$\begingroup$

@imoutidi, I also encountered the same deprecation warning.

After digging around a bit, it looks like the new/replacement package can be imported with the following:

from nltk.tag.stanford import CoreNLPNERTagger

However, when trying to run the tag() method I end up getting an unexpected HTTP connection refused error. I haven't figured out if this is an environment configuration issue (missing .jar path) or an issue with the NLTK codebase. I tried temporarily turning off my local firewall and that didn't help, so I'm guessing it is one of the other two possibilities.

I hope the python import statement is at least some help.

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Yea I tried to import CoreNLPNERTagger with no luck. Maybe when version 3.2.5 will come out there will be a working example. Thanks for your effort. $\endgroup$
    – Anoroah
    Jan 29, 2018 at 13:58
  • $\begingroup$ It looks like there should a server listening at port 9000? Anyone found how to use the Stanford tagger? $\endgroup$
    – Nathan B
    Mar 22, 2018 at 11:20
0
$\begingroup$

Continuing on tokyodusk's answer. You should download the stanford Core NLP from here

Then do the following:

  • open the terminal
  • navigate to where you extracted the package
  • type in the following command:
    java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000 -annotators 'tokenize,ssplit,pos,ner'

Then do what tokyodusk suggested.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.