gpt4 book ai didi

java - SentimentCoreAnnotations.AnnotatedTree 无法解析为类型

转载 作者:行者123 更新时间:2023-12-01 16:52:40 26 4
gpt4 key购买 nike

我正在尝试使用斯坦福核心 NLP 获得实时推文的情感分数。目前我正在收到实时推文。但是当我将其输入斯坦福核心 NLP 程序时,我收到了一个错误。

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;

public class NLP {
static StanfordCoreNLP pipeline;

public static void init() {
pipeline = new StanfordCoreNLP("MyPropFile.properties");
}

public static int findSentiment(String tweet) {

int mainSentiment = 0;
if (tweet != null && tweet.length() > 0) {
int longest = 0;
Annotation annotation = pipeline.process(tweet);
for (CoreMap sentence : annotation
.get(CoreAnnotations.SentencesAnnotation.class)) {
Tree tree = sentence
.get(SentimentCoreAnnotations.AnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
String partText = sentence.toString();
if (partText.length() > longest) {
mainSentiment = sentiment;
longest = partText.length();
}

}
}
return mainSentiment;
}
}

我从 NLP 类外部调用这个 init() 和 findSentiment() 函数。

NLP.init();
System.out.println(status.getText() + " : " + NLP.findSentiment(status.getText()));

我的错误是:SentimentCoreAnnotations.AnnotatedTree 无法解析为类型

最佳答案

尝试改变

Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);

Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);

关于java - SentimentCoreAnnotations.AnnotatedTree 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36813383/

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