IntelliJ IDEA无法识别CoreNLP依赖问题求助
Stanford CoreNLP情感分析项目启动报错求助
我正在跟着一篇Java情感分析教程做项目,已安装Maven,POM配置如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.simplestcodings</groupId> <artifactId>nlp</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>edu.stanford.nlp</groupId> <artifactId>stanford-corenlp</artifactId> <version>4.5.6</version> </dependency> <dependency> <groupId>edu.stanford.nlp</groupId> <artifactId>stanford-corenlp</artifactId> <version>4.5.6</version> <classifier>models</classifier> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.32</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.30</version> <scope>provided</scope> </dependency> </dependencies> </project>
我的Java类代码如下:
package com.simplestcodings; import edu.stanford.nlp.ling.CoreAnnotations; import edu.stanford.nlp.pipeline.Annotation; import edu.stanford.nlp.pipeline.StanfordCoreNLP; import edu.stanford.nlp.sentiment.SentimentCoreAnnotations; import edu.stanford.nlp.util.CoreMap; import lombok.extern.slf4j.Slf4j; @Slf4j public class SentimentAnalysis { public static void main(String[] args) { // Initialize the Stanford NLP pipeline StanfordCoreNLP pipeline = new StanfordCoreNLP("application.properties"); // Sample text for sentiment analysis String text = "Simplest codings is the best place to learn and grow. I am glad to be here."; // Perform sentiment analysis String sentiment = getSentiment(text, pipeline); // Display the result log.info("Text: {}, Sentiment: {}",text, sentiment); // Another Sample text for sentiment analysis text = "I hate this place. I am not coming back here again. I am very disappointed."; // Perform sentiment analysis sentiment = getSentiment(text, pipeline); // Display the result log.info("Text: {}, Sentiment: {}",text, sentiment); } private static String getSentiment(String text, StanfordCoreNLP pipeline) { // Create an Annotation object with the input text Annotation annotation = new Annotation(text); // Run all the NLP annotators on the text pipeline.annotate(annotation); // Extract the sentiment from the annotation CoreMap sentence = annotation.get(CoreAnnotations.SentencesAnnotation.class).get(0); String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class); return sentiment; } }
运行时出现错误:找不到application.properties配置文件,同时伴随类加载相关异常。
我已尝试以下操作但问题仍未解决:
- 清除Maven缓存、重建项目
- 切换到Amazon Corretto JDK 17(原使用JDK 22)
- 确认版本信息:
- JAVA:
java version "22.0.1" 2024-04-16 Java(TM) SE Runtime Environment (build 22.0.1+8-16) Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing) - MAVEN:
Apache Maven 3.9.6
- JAVA:
恳请帮忙排查问题。
内容的提问来源于stack exchange,提问作者kotddl
相关产品推荐
相关产品推荐

