运行斯坦福大学 NER 和斯坦福大学 POS 标记器时出现不兼容的类更改错误

发布于 2024-11-07 03:54:16 字数 3620 浏览 3 评论 0原文

我正在尝试在一个应用程序中使用斯坦福 NER 和斯坦福 POS 标记器。当我尝试运行 POS 标记器方法时,出现 IncompleteClassChangeError

我的类路径中有 NER 和 POS 标记器的 jar 文件。如果我从类路径中删除 NER 的 jar,则不会出现此错误。我猜想 NER jar 和 POS jar 中有一些常见的类,而 java 无法确定在运行时使用哪个类。

以下是堆栈跟踪:

java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    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)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.init(MaxentTagger.java:407)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:699)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:673)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:280)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:260)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.runTagger(MaxentTagger.java:1305)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.main(MaxentTagger.java:1499)
    at com.tcs.srl.stanford.POSWrapper.executePOSTagger(POSWrapper.java:39)
    at com.tcs.srl.stanford.test.POSWrapperTester.ExecutePOSTagger(POSWrapperTester.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

我不知道为什么会出现此错误。

I am trying to use Stanford NER and Stanford POS tagger in one application. I am getting IncompatibleClassChangeError when I try to run POS tagger method.

I have jar files of both NER and POS tagger in the class path. If I remove jar of NER from my classpath then this error is not coming. I guess there are some classes common in NER jar and POS jar and java is not able to determine which class to be used at runtime.

Following is the stacktrace :

java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    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)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.init(MaxentTagger.java:407)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:699)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:673)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:280)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:260)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.runTagger(MaxentTagger.java:1305)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.main(MaxentTagger.java:1499)
    at com.tcs.srl.stanford.POSWrapper.executePOSTagger(POSWrapper.java:39)
    at com.tcs.srl.stanford.test.POSWrapperTester.ExecutePOSTagger(POSWrapperTester.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I have no clue why this error is coming.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有你我更好 2024-11-14 03:54:16

我认为你的诊断很接近,但不太正确。 Java 将始终使用类路径中类的第一个实例。但是,如果您有一个类加载器的层次结构,并且子类加载器尝试定义父级已经定义的类,您将收到类似这样的错误。

我不熟悉斯坦福 NER 或 POS 代码。不过,我可以提供一些建议。

如果您确信两个 jar 中具有相同名称的类是相同的,那么只需将这两个 jar 合并到一个 jar 中 - 这将删除任何重复项。

如果您担心 NER 和 POS 代码可能不兼容,我会将两者的源代码移至一个项目中,然后重新编译,仔细检查重复项。

另一种方法是从一个项目中获取源代码并将其移至不同的包中,以便类名保持不变,但包不再冲突。一个好的 IDE 应该能够相当轻松地完成此任务。

然而,对于像这样的问题,邮件列表通常是获取建议的最佳地点:http: //www-nlp.stanford.edu/software/CRF-NER.shtml。我确信您不会是唯一一起使用这些软件的人。我上面提到的解决方案都不是必要的,因此从使用它们的其他人那里获得建议可能是最好的。

I think you are close but not quite right in your diagnosis. Java will always use the first instance of a class in your classpath. However, if you have a heirarchy of classloaders, and a child classloader tries to define a class that a parent has already defined you will get an error like this.

I'm not familiar with the Stanford NER or POS code. However, I can offer some advice.

If you are convinced the classes with the same names are identical in the two jars, then just combine the two jars into a single jar - this will remove any duplicates.

If you are worried the NER and POS code might be incompatible, I'd move the source code for the two into a single project, and recompile, carefully inspecting the duplicates.

The alternative is to take the source code from one project and move it into a different package so the class names stay the same, but the packages no longer clash. A good IDE should be able to do this fairly painlessly.

However, for issues like this mailing lists are often the best place to get advice: http://www-nlp.stanford.edu/software/CRF-NER.shtml. I'm sure you won't be the only person to be using these pieces of software together. None of the solutions I mention above should be necessary, so getting advice from someone else who uses them is probably the best.

自此以后,行同陌路 2024-11-14 03:54:16

这似乎是众所周知的问题,斯坦福大学的人们也意识到了这个问题。我已经在 NER 解析器的邮件列表上发送了邮件,我收到了来自名为 John 的人的以下回复

这是一个已知问题,将
一周左右修复。在
与此同时,所有必要的课程
因为这两个库位于
斯坦福核心自然语言处理 (StanfordCoreNLP),

约翰

看来他们正在尝试从 API 中删除这个错误,在下一个版本的解析器和标记器中,我们将获得干净的 API。

目前我正在使用 此处 提供的 CoreNLP 包。这个 CoreNLP 包包含解析器、标记器、ner 和其他一些东西的所有内容。

It seems like well known problem and people at Stanford are aware of this problem. I had sent mail on mailing list of NER parser, I got following reply from person called John

This is a known problem that will be
fixed in a week or so. In the
meantime, all of the necessary classes
for those two libraries are in
StanfordCoreNLP,

John

It seems like they are trying to remove this bug from their API and in the next release of parser and tagger we will get clean API.

Currently I am using CoreNLP package available here. This CoreNLP package contains everything from parser, tagger, ner and few other things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文