Stanford Pos Tagger出错

时间:2016-02-27 22:12:00

标签: eclipse python-3.x nltk stanford-nlp pos-tagger

您好我正在尝试使用Stanford Pos Tagger为某个句子做POS标签。我在windows7上使用Python 3.4 nltk 3.1 以下是我使用的代码:

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))

然而,我收到以下错误:

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)

引起: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!

请有人帮我解决错误吗?

1 个答案:

答案 0 :(得分:0)

尝试在构建路径中添加两个jar文件。您将在下载的包slf4j-api.jarslf4j-simple.jar的lib文件夹中找到这些文件。 请查看the docs