I am trying to follow this tutorial: https://medium.com/@varun85gupta/harnessing-sentiment-analysis-with-java-a-step-by-step-guide-using-nlp-f464398bb664
I have installed Maven, configured the POM to this:
<?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>
and my Java class looks like this:
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;
}
}
But these are the errors I am recieving:
Errors
I have tried invalidating the cache, rebuilding the project and checking file versions which are:
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
I have also tried to setup the project in Amazon Coretto JDK 17, like the tutorial but still no luck
Please help.