nltk StanfordNERTagger : NoClassDefFoundError: org/slf4j/LoggerFactory (In Windows)

后端 未结 9 2080
轮回少年
轮回少年 2020-12-15 09:43

NOTE: I am using Python 2.7 as part of Anaconda distribution. I hope this is not a problem for nltk 3.1.

I am trying to use nltk for NER as

import nl         


        
9条回答
  •  猫巷女王i
    2020-12-15 10:29

    I encountered exactly the same problem as you described yesterday.

    There are 3 things you need to do.

    1) Update your NLTK.

    pip install -U nltk
    

    Your version should be >3.1 and I see you are using

    from nltk.tag.stanford import StanfordNERTagger
    

    However, you gotta use the new module:

    from nltk.tag import StanfordNERTagger
    

    2) Download slf4j and update your CLASSPATH.

    Here is how you update your CLASSPATH.

    javapath = "/Users/aerin/Downloads/stanford-ner-2014-06-16/stanford-ner.jar:/Users/aerin/java/slf4j-1.7.13/slf4j-log4j12-1.7.13.jar"
    os.environ['CLASSPATH'] = javapath 
    

    As you see above, the javapath contains 2 paths, one is where stanford-ner.jar is, the other is where you downloaded slf4j-log4j12-1.7.13.jar (It can be downloaded here: http://www.slf4j.org/download.html)

    3) Don't forget to specify where you downloaded 'english.all.3class.distsim.crf.ser.gz' & 'stanford-ner.jar'

    st = StanfordNERTagger('/Users/aerin/Downloads/stanford-ner-2014-06-16/classifiers/english.all.3class.distsim.crf.ser.gz','/Users/aerin/Downloads/stanford-ner-2014-06-16/stanford-ner.jar') 
    
    st.tag("Doneyo lab did such an awesome job!".split())
    

提交回复
热议问题