gpt4 book ai didi

java - 将斯坦福情绪分析与 java 集成时出现错误

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

我正在使用 stanford sentiment nlp 库和 java 进行情绪分析。但是当我执行代码时,我收到了错误。想不通。

我的代码如下:

package com.nlp;

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

public class SemanticAnalysis {
public static void main(String args[]) {
sentimentAnalysis sentiment = new sentimentAnalysis();
sentiment.findSentiment("france is a good city");
}
}

class sentimentAnalysis {
public String findSentiment(String line) {

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) {
mainSentiment = sentiment;
longest = partText.length();
}
}
}
if (mainSentiment == 2 || mainSentiment > 4 || mainSentiment < 0) {
return null;
}
return "";
}
}

但是当我运行代码时出现以下错误。

   Exception in thread "main" java.lang.NoClassDefFoundError: org/ejml/simple/SimpleBase
at edu.stanford.nlp.pipeline.SentimentAnnotator.<init>(SentimentAnnotator.java:45)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$14.create(StanfordCoreNLP.java:845)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:81)

最佳答案

您缺少 ejml-0.23.jar,将它添加到您的类路径中,它应该可以工作。

关于java - 将斯坦福情绪分析与 java 集成时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23492268/

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