Tôi đang làm việc trên phân tích tình cảm bằng cách sử dụng thư viện tình cảm stanford nlp với java. Nhưng khi tôi thực thi mã tôi nhận được lỗi. Không thể hình dung ra.Nhận được lỗi trong khi tích hợp phân tích tình cảm stanford với java
Mã của tôi là như sau:
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 "";
}
}
Nhưng khi tôi đang chạy mã tôi đang nhận được lỗi sau.
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)
Bạn có thêm tất cả các thư viện vào classpath của bạn chứa? – markusw