2016-02-27 85 views
0

您好,我正在嘗試使用Stanford Pos Tagger爲某個句子做POS標籤。我使用Python 3.4 NLTK 3.1 windows7的 以下是我使用的代碼:斯坦福Posger Tagger中的錯誤

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:組織.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

見https://github.com/nltk/nltk/issues/1304 – alvas

+0

[NLTK StanfordNERTagger:NoClassDefFoundError的:組織/ SLF4J /的LoggerFactory(在Windows)的可能的複製(HTTP:// stackoverflow.com/questions/34361725/nltk-stanfordnertagger-noclassdeffounderror-org-slf4j-loggerfactory-in-windo) – alvas

回答

0

嘗試添加兩個更多的jar文件兩個你的構建路徑。您將在下載的軟件包slf4j-api.jarslf4j-simple.jar的lib文件夾中找到這些文件。 看一看到this tutorial

+0

我無法解決問題,所以我下載了另一個版本的POS tagger stanford-postagger-full-2014-08 -27。它正在工作。 – Shany