我正在使用stanford CoreNLP页面here.
上描述的方法为了从命令行运行Stanford CoreNLP,使用以下命令:
java -cp "*" -Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file input.txt
我已从分发目录运行此命令。然而。我收到以下错误:
Exception in thread "main" edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl
at edu.stanford.nlp.util.ReflectionLoading.loadByReflection(ReflectionLoading.java:40)
at edu.stanford.nlp.time.TimeExpressionExtractorFactory.create(TimeExpressionExtractorFactory.java:57)
at edu.stanford.nlp.time.TimeExpressionExtractorFactory.createExtractor(TimeExpressionExtractorFactory.java:38)
at edu.stanford.nlp.ie.regexp.NumberSequenceClassifier.<init>(NumberSequenceClassifier.java:86)
at edu.stanford.nlp.ie.NERClassifierCombiner.<init>(NERClassifierCombiner.java:136)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.ner(AnnotatorImplementations.java:121)
at edu.stanford.nlp.pipeline.AnnotatorFactories$6.create(AnnotatorFactories.java:273)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:152)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:451)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:154)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:150)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:137)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.main(StanfordCoreNLP.java:1323)
Caused by: edu.stanford.nlp.util.MetaClass$ClassCreationException: MetaClass couldn't create public edu.stanford.nlp.time.TimeExpressionExtractorImpl(java.lang.String,java.util.Properties) with args [sutime, {}]
at edu.stanford.nlp.util.MetaClass$ClassFactory.createInstance(MetaClass.java:237)
at edu.stanford.nlp.util.MetaClass.createInstance(MetaClass.java:382)
at edu.stanford.nlp.util.ReflectionLoading.loadByReflection(ReflectionLoading.java:38)
... 12 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:466)
at edu.stanford.nlp.util.MetaClass$ClassFactory.createInstance(MetaClass.java:233)
... 14 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at de.jollyday.util.CalendarUtil.<init>(CalendarUtil.java:42)
at de.jollyday.HolidayManager.<init>(HolidayManager.java:66)
at de.jollyday.impl.DefaultHolidayManager.<init>(DefaultHolidayManager.java:46)
at edu.stanford.nlp.time.JollyDayHolidays$MyXMLManager.<init>(JollyDayHolidays.java:148)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:466)
at java.base/java.lang.Class.newInstance(Class.java:556)
at de.jollyday.caching.HolidayManagerValueHandler.instantiateManagerImpl(HolidayManagerValueHandler.java:60)
at de.jollyday.caching.HolidayManagerValueHandler.createValue(HolidayManagerValueHandler.java:41)
at de.jollyday.caching.HolidayManagerValueHandler.createValue(HolidayManagerValueHandler.java:13)
at de.jollyday.util.Cache.get(Cache.java:51)
at de.jollyday.HolidayManager.createManager(HolidayManager.java:168)
at de.jollyday.HolidayManager.getInstance(HolidayManager.java:148)
at edu.stanford.nlp.time.JollyDayHolidays.init(JollyDayHolidays.java:57)
at edu.stanford.nlp.time.Options.<init>(Options.java:90)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.init(TimeExpressionExtractorImpl.java:44)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.<init>(TimeExpressionExtractorImpl.java:39)
... 19 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:532)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:186)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:473)
... 38 more
我的java版本是1.9,我下载的CoreNLP是最新版本,即。 3.7.0。
另外,我没有安装多个版本的Stanford CoreNLP。这个版本有问题吗?我哪里可能出错?
答案 0 :(得分:2)
我从这里下载了分发文件夹:http://stanfordnlp.github.io/CoreNLP/download.html
我将它解压缩并插入stanford-corenlp-full-2016-10-31
我输入了这个命令:
import numpy as np
import pandas as pd
import seaborn as sns
sns.set(style="white")
# Generate a random correlated bivariate dataset
rs = np.random.RandomState(5)
mean = [0, 0]
cov = [(1, .5), (.5, 1)]
x1, x2 = rs.multivariate_normal(mean, cov, 500).T
x1 = pd.Series(x1, name="$X_1$")
x2 = pd.Series(x2, name="$X_2$")
# Show the joint distribution using kernel density estimation
g = sns.jointplot(x1, x2, kind="kde", size=7, space=0, xlim=(0.995, 1.005))
它运作正常。你有没有额外的罐子到文件夹?您在运行此类型的系统?
我正在运行Java 1.8,据我所知,Java 1.9还没有发布,所以这也可能是一个问题。
答案 1 :(得分:1)
如果您使用 Java 9 ,您应该可以使用此命令:
java -cp "*" -Xmx2g --add-modules java.xml.bind edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file input.txt -outputFormat text
注意使用--add-modules java.xml.bind
,此选项允许您解决错误NoClassDefFoundError:javax / xml / bind / JAXBException。
答案 2 :(得分:0)
这已为我修复,将其添加到道具中:
import os
directory = os.fsencode("mydir")
for folder in os.listdir(directory):
for file in os.listdir(folder):
filename = os.fsdecode(file)
if ((filename.endswith('.xlsx')) and (filename == 'Apples.xlsx')):
filenames.append(filename)
filenames.sort()
如此处所述:https://github.com/sergey-tihon/Stanford.NLP.NET/issues/11