gpt4 book ai didi

java - 使用 StanfordCoreNLP 时出错

转载 作者:搜寻专家 更新时间:2023-10-31 19:32:48 25 4
gpt4 key购买 nike

我正在尝试将 Stanford CoreNLP 用作我的 Java 程序中的库。我使用 IntelliJ 作为 IDE。我试图测试这个库,所以我写了这段代码:

import edu.stanford.nlp.pipeline.StanfordCoreNLP;

import java.util.Properties;

/**
* Created by Benjamin on 15/5/4.
*/
public class SentimentAnaTest {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
}
}

它显示如下错误:

Adding annotator tokenize
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:292)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:289)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122)
at SentimentAnaTest.main(SentimentAnaTest.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:770)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:298)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:263)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:59)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:290)
... 10 more
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:481)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765)
... 16 more

我读了一个解决方案 here但无法弄清楚问题出在哪里,因为我从 Maven 中央存储库添加了库,其中已经包含“stanford-corenlp-3.5.2-models.jar”。

从错误消息来看,程序似乎正在尝试从 edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger 加载文件,所以我从 here 下载标记器文件并将其放入 /edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger。但是还是不行。

谁能告诉我这个错误是怎么回事并帮助我解决它?谢谢!

最佳答案

我遇到了同样的问题。固定使用:

<dependencies>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models</classifier>
</dependency>
</dependencies>

或者对于 SBT:

"edu.stanford.nlp" % "stanford-corenlp" % "3.5.2",
"edu.stanford.nlp" % "stanford-corenlp" % "3.5.2" classifier "models",

关于java - 使用 StanfordCoreNLP 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30044579/

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