gpt4 book ai didi

java - 为什么使用 Spark 和斯坦福 NLP 运行 java 代码时会发生此异常?

转载 作者:行者123 更新时间:2023-12-02 03:00:49 25 4
gpt4 key购买 nike

这是我的代码:

try
{
Dataset<Row> df = spark.sql("select answer from health where limit 1");

nameAndCity = df.toJavaRDD().map(new Function<Row, String>() {

// @Override
public String call(Row row) {
return row.getString(0);
}
}).collect();
}

catch (Exception AnalysisException)
{
System.out.print("\nTable is not found\n");
}
spark.close();
System.out.println("Spark Done....!");
for (String name : nameAndCity)
{
Annotation document = new Annotation(name);
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,sentiment");
//props.setProperty("parse.binaryTrees","true");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
pipeline.annotate(document);
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
System.out.println("---");
System.out.println("Sentence Analyzed: " + " " + sentence.get(CoreAnnotations.TextAnnotation.class));
System.out.println("Reflected sentiment: " + " " + sentence.get(SentimentCoreAnnotations.SentimentClass.class));
}
}

运行此代码后,出现以下异常:

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 spark.sparkhive.queryhive.main(queryhive.java:64)
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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at edu.stanford.nlp.util.MetaClass$ClassFactory.createInstance(MetaClass.java:233)
... 14 more
Caused by: java.lang.NoClassDefFoundError: de/jollyday/ManagerParameter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at edu.stanford.nlp.time.Options.<init>(Options.java:87)
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: de.jollyday.ManagerParameter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
17/02/22 18:26:39 INFO ShutdownHookManager: Shutdown hook called
17/02/22 18:26:39 INFO ShutdownHookManager: Deleting directory /tmp/spark-23b5fac2-27ec-44a6-9ff7-cb2b8bfd8753

为什么我会遇到此异常以及我应该采取什么措施来解决它?

最佳答案

这就是你麻烦的根源:

java.lang.NoClassDefFoundError: de/jollyday/ManagerParameter

您的程序正在寻找此类,但找不到。检查您的类路径。

您可以忽略输出中的前面的异常,因为它们只是对原始异常的 react 。

  • ReflectionLoadingException 是由名为 loadByReflection 的方法引发的,因此它似乎是某种包装异常,不太可能告诉您太多信息。
  • 然后我们有 createInstance 抛出的 ClassCreationException,类似的情况。一般来说,如果您有一个名为 doSomething 的方法抛出 DoSomethingException,则该异常要么会准确地告诉您问题是什么(“x 必须 >= 100”),要么会包装实际的异常。
  • IncationTargetException 只是当您尝试使用反射调用方法并且该方法抛出异常时 JVM 抛出的异常。同样,它只是实际异常的包装。
  • 最后我们看到了实际的异常,NoClassDefFoundError。

关于java - 为什么使用 Spark 和斯坦福 NLP 运行 java 代码时会发生此异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42392322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com