diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/HtmlSpeech.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/HtmlSpeech.java index c002048..0d86893 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/HtmlSpeech.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/HtmlSpeech.java @@ -4,6 +4,7 @@ import org.bson.Document; import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; import org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils; import org.texttechnologylab.project.gruppe_05_1.domain.nlp.NlpInfo; +import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Sentiment; import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Token; import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Topic; import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData; @@ -69,7 +70,8 @@ public class HtmlSpeech { List namedEntitiesDocs = nlpDoc.get("namedEntities", MongoDBHandler.DOC_LIST_CLASS); - List sentimentsDocs = nlpDoc.get("sentiments", MongoDBHandler.DOC_LIST_CLASS); + List sentimentDocs = nlpDoc.get("sentiments", MongoDBHandler.DOC_LIST_CLASS); + nlp.setSentiments(List.of(Sentiment.readFirstSentimentFromMongo(sentimentDocs))); List topicsDocs = nlpDoc.get("topics", MongoDBHandler.DOC_LIST_CLASS); nlp.setTopics(Topic.readTopicsFromMongo(topicsDocs)); diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Sentiment.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Sentiment.java index a2f04e3..c63abdf 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Sentiment.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Sentiment.java @@ -1,5 +1,9 @@ package org.texttechnologylab.project.gruppe_05_1.domain.nlp; +import org.bson.Document; + +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.StringJoiner; @@ -94,4 +98,15 @@ public class Sentiment { .add("positive=" + positive) .toString(); } + + public static Sentiment readFirstSentimentFromMongo(List sentimentDocs) { + Document doc = sentimentDocs.get(0); + return new Sentiment(doc.getInteger("begin"), + doc.getInteger("end"), + doc.getDouble("score"), + doc.getDouble("pos"), + doc.getDouble("neu"), + doc.getDouble("neg") + ); + } } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/FrontEndController.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/FrontEndController.java index 2649549..c72570d 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/FrontEndController.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/FrontEndController.java @@ -194,15 +194,25 @@ public class FrontEndController { } // NLP: Sentiments - Sentiment speechSentiment = null; + Sentiment sentimentObj = null; if (speech.getNlp() != null && speech.getNlp().getSentiments() != null && !speech.getNlp().getSentiments().isEmpty()) { - speechSentiment = speech.getNlp().getSentiments().get(0); // Get the first sentiment + Sentiment first = speech.getNlp().getSentiments().get(0); + sentimentObj = new Sentiment( + first.getBegin(), + first.getEnd(), + first.getSentiment(), + first.getNegative(), + first.getNeutral(), + first.getPositive() + ); + + + } else { + // No sentiment found: use a default sentiment with zero values + sentimentObj = new Sentiment(0, 0, 0.0, 0.0, 0.0, 0.0); } - - System.out.println("DEBUG: Speech Sentiment - " + speechSentiment); - - // ✅ Pass sentiment data to FreeMarker - attributes.put("sentiment", speechSentiment); + System.out.println("DEBUG: Speech Sentiment - " + sentimentObj); + attributes.put("sentiment", sentimentObj); ctx.render("speech.ftl", attributes); } diff --git a/src/main/resources/templates/nlp.ftl b/src/main/resources/templates/nlp.ftl index 4dfeb43..c835277 100644 --- a/src/main/resources/templates/nlp.ftl +++ b/src/main/resources/templates/nlp.ftl @@ -15,11 +15,10 @@ - <#if s.nlp.sentiments??> -

SentimentsInformation (als Radar Chart)

- <#assign overallSentiment = s.nlp.overallSentiment> - <#assign sentiments = s.nlp.sentiments> - <#include "sentimentsRadarChart.ftl"> + <#if s.nlp.sentiment??> + <#assign sentiment = s.nlp.sentiment?first> +

Sentiments Information (als Radar Chart)

+ <#include "sentimentsRadarChart.ftl"> <#else>

Keine Sentiments Information für diese Rede verfügbar

diff --git a/src/main/resources/templates/sentimentsRadarChart.ftl b/src/main/resources/templates/sentimentsRadarChart.ftl index e69de29..fbb01a4 100644 --- a/src/main/resources/templates/sentimentsRadarChart.ftl +++ b/src/main/resources/templates/sentimentsRadarChart.ftl @@ -0,0 +1,91 @@ + + + \ No newline at end of file