NLTK StanfordPOSTagger无法运行 - Windows

时间:2016-02-28 08:16:09

标签: windows python-2.7 nltk stanford-nlp pos-tagger

操作系统:Windows 10 x64

Python:2.7.3

NLTK:3.1

我想在python中使用Stanford Pos tagger所以基于here中的文档,我做了这些:

我已从here下载stanford-postagger-2015-04-20.zip并将其解压缩到D:\Downloads\stanford-postagger-2015-04-20\stanford-postagger-2015-04-20

contents of stanford-postagger-2015-04-20 enter image description here

我创建了两个环境变量:

CLASSPATH >>> D:\Downloads\stanford-postagger-2015-04-20\stanford-postagger-2015-04-20\stanford-postagger.jar
STANFORD_MODELS >>> D:\Downloads\stanford-postagger-2015-04-20\stanford-postagger-2015-04-20\models\

使用此代码使用标记器:

import os
java_path = "C:/Program Files (x86)/Java/jdk1.7.0_71/bin/java.exe"
os.environ['JAVAHOME'] = java_path

from nltk.tag import StanfordPOSTagger

st = StanfordPOSTagger('english-bidirectional-distsim.tagger')

st.tag('What is the airspeed of an unladen swallow ?'.split())

引发了这个错误:

java.lang.UnsupportedClassVersionError: edu/stanford/nlp/tagger/maxent/MaxentTagger : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Exception in thread "main" 
Traceback (most recent call last):
  File "<tmp 1>", line 9, in <module>
    st.tag('What is the airspeed of an unladen swallow ?'.split())
  File "c:\python27\lib\site-packages\nltk\tag\stanford.py", line 66, in tag
    return sum(self.tag_sents([tokens]), [])
  File "c:\python27\lib\site-packages\nltk\tag\stanford.py", line 89, in tag_sents
    stdout=PIPE, stderr=PIPE)
  File "c:\python27\lib\site-packages\nltk\internals.py", line 134, in java
    raise OSError('Java command failed : ' + str(cmd))
OSError: Java command failed : ['C:/Program Files (x86)/Java/jdk1.7.0_71/bin/java.exe', '-mx1000m', '-cp', 'D:\\Downloads\\stanford-postagger-2015-04-20\\stanford-postagger-2015-04-20\\stanford-postagger.jar', 'edu.stanford.nlp.tagger.maxent.MaxentTagger', '-model', 'D:\\Downloads\\stanford-postagger-2015-04-20\\stanford-postagger-2015-04-20\\models\\english-bidirectional-distsim.tagger', '-textFile', 'c:\\users\\wiki\\appdata\\local\\temp\\tmp0ruajz', '-tokenize', 'false', '-outputFormatOptions', 'keepEmptySentences', '-encoding', 'utf8']

我该怎么办?

0 个答案:

没有答案