gpt4 book ai didi

java - 情绪评分 Stanford Core NLP

转载 作者:行者123 更新时间:2023-12-01 14:36:21 30 4
gpt4 key购买 nike

我们如何使用 Stanford 核心 NLP 获得完整句子的情感分数?

它将完整的句子分为积极情绪和消极情绪,但我们能否通过斯坦福 NLP 工具获得总情绪得分?

最佳答案

我所做的是根据句子的长度来平均每个句子的分数。其背后的逻辑是,较长的句子应该比较短的句子更有分量。

代码如下所示:

String line = "Great item! HDMI and decent wifi required as with all streaming devices.\n" +
"The flow on the homepage is very good and responsive. Watching a series is a doddle, flow is great, no action required.\n" +
"The remote and controller app both work a treat.\n" +
"I really like this device.\n" +
"I'd like to see an Amazon-written mirroring app available for non-Amazon products but no-one likes talking to each other in this field!";

Long textLength = 0L;
int sumOfValues = 0;

Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
int mainSentiment = 0;
if (line != null && line.length() > 0) {
int longest = 0;
Annotation annotation = pipeline.process(line);
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) {
textLength += partText.length();
sumOfValues = sumOfValues + sentiment * partText.length();

System.out.println(sentiment + " " + partText);
}
}
}

System.out.println("Overall: " + (double)sumOfValues/textLength);

下载整个项目here

关于java - 情绪评分 Stanford Core NLP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22434081/

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