gpt4 book ai didi

java - 在斯坦福 Corenlp 中使用情感管道

转载 作者:行者123 更新时间:2023-12-02 10:34:14 30 4
gpt4 key购买 nike

我已经在 Eclipse 中设置了一个 Maven 项目。

他们只是一个类,src/main/java/App.java 包 com.nlptools.corenlp;

import java.util.List;

import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.sentiment.SentimentPipeline;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;

class App
{
public static void main( String[] args )
{
List<Annotation> list = SentimentPipeline.getAnnotations(new StanfordCoreNLP(), null, "foo.txt", false);
for (Annotation item : list) {
System.out.println(item.toString());
}
System.out.println( "Hello World!" );
}
}

然后我添加这些依赖项并等待 Gradle 下载文件:

<dependency>
<groupId> edu.stanford.nlp </groupId>
<artifactId> stanford-corenlp </artifactId>
<version> 3.9.2</version>
</dependency>
<dependency>
<groupId> edu.stanford.nlp </groupId>
<artifactId> stanford-corenlp </artifactId>
<version> 3.9.2</version>
<classifier> models-english </classifier>
</dependency>

当我运行时出现此错误:

Couldn't read TokensRegexNER from edu/stanford/nlp/models/kbp/english/gazetteers/regexner_caseless.tab

我正在查看文档,但无法理解它: https://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/sentiment/SentimentPipeline.html

我错过了什么?

最佳答案

您的 Maven 依赖项中需要这个:

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

此外,您可能只想在代码中使用标准管道:

Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
CoreDocument exampleDocument = new CoreDocument("I loved the movie!");
pipeline.annotate(exampleDocument);
System.out.println(exampleDocument.sentences().get(0).sentiment());

关于java - 在斯坦福 Corenlp 中使用情感管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53405272/

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