Error in Stanford Pos Tagger

和自甴很熟 提交于 2019-12-25 07:10:06

问题


Hello i am trying to do POS tag for a certain sentence using Stanford Pos Tagger. I am using Python 3.4 nltk 3.1 on windows7 Following is the code i used:

import nltk
from nltk.tag.stanford import POSTagger
import os
java_path = r"C:\Program Files\Java\jre1.8.0_66\bin\java.exe"
os.environ['JAVAHOME'] = java_path

St=POSTagger(r"C:\Python34\Scripts\stanford-postagger-2015-12-09\models\english-bidirectional-distsim.tagger",r"C:\Python34\Scripts\stanford-postagger-2015-12-09\stanford-postagger.jar")

tokens = nltk.tokenize.word_tokenize("Sample for tagging a sentence.")
print(St.tag(tokens))

Yet, i am getting the following error:

Traceback (most recent call last):
Loading default properties from tagger C:\Python34\Scripts\stanford-postagger-2015-12-09\models\english-bidirectional-distsim.tagger

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

at edu.stanford.nlp.io.IOUtils.<clinit>(IOUtils.java:42)

at edu.stanford.nlp.tagger.maxent.TaggerConfig.<init>(TaggerConfig.java:146)

at edu.stanford.nlp.tagger.maxent.TaggerConfig.<init>(TaggerConfig.java:128)

at edu.stanford.nlp.tagger.maxent.MaxentTagger.main(MaxentTagger.java:1836)

Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 4 more

File "C:\Users\workspace\src\chunking.py", line 15, in <module>
print(St.tag(tokens))
File "C:\Python34\lib\site-packages\nltk\tag\stanford.py", line 59, in tag
return self.tag_sents([tokens])[0]
File "C:\Python34\lib\site-packages\nltk\tag\stanford.py", line 81, in tag_sents stdout=PIPE, stderr=PIPE)
File "C:\Python34\lib\site-packages\nltk\internals.py", line 160, in java     raise OSError('Java command failed!')
OSError: Java command failed!

Please can anyone help me solve the error?


回答1:


Try adding two more jar files two your build path. You will find these files in the lib folder of the downloaded package slf4j-api.jar and slf4j-simple.jar. Have a look into this tutorial



来源:https://stackoverflow.com/questions/35676079/error-in-stanford-pos-tagger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!