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 ad6d126..ea844b3 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 @@ -68,8 +68,8 @@ public class HtmlSpeech { List namedEntitiesDocs = nlpDoc.get("namedEntities", MongoDBHandler.DOC_LIST_CLASS); nlp.setNamedEntities(NamedEntity.readNamedEntitiesFromMongo(namedEntitiesDocs)); - List sentimentsDocs = nlpDoc.get("sentiments", MongoDBHandler.DOC_LIST_CLASS); - nlp.setSentiments(Sentiment.readSentimentsFromMongo(sentimentsDocs)); + 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 ce29182..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 @@ -99,24 +99,14 @@ public class Sentiment { .toString(); } - /** - * - * @param sentimentDocs Die Sentiment-Dokumente (Speech --> analysisResults --> sentiment) aus der MongoDB lesen. - * Das erste Dokument ist für die gesamte Rede, Sentiments 1..n entsprechen Sentences 0..n-1 - * @return - */ - public static List readSentimentsFromMongo(List sentimentDocs) { - List sentiments = new ArrayList<>(); - for (Document doc : sentimentDocs) { - sentiments.add(new Sentiment( - doc.getInteger("begin"), - doc.getInteger("end"), - doc.getDouble("score"), - doc.getDouble("pos"), - doc.getDouble("neu"), - doc.getDouble("neg") - )); - } - return sentiments; + 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 e859fc0..4593a8d 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 @@ -8,6 +8,7 @@ import org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils; import org.texttechnologylab.project.gruppe_05_1.domain.html.HtmlSpeech; import org.texttechnologylab.project.gruppe_05_1.domain.html.Parlamentarier; import org.texttechnologylab.project.gruppe_05_1.domain.html.ParlamentarierDetails; +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; @@ -151,6 +152,7 @@ public class FrontEndController { @OpenApiResponse(status = "200", content = {@OpenApiContent(from = Speech.class)}) }) public static void showSpeech(Context ctx) { + String parlamentarierId = ctx.pathParam("id"); String redeId = ctx.pathParam("redeId"); Map attributes = new HashMap<>(); @@ -158,6 +160,10 @@ public class FrontEndController { HtmlSpeech speech = MongoPprUtils.getSpeechByKey(redeId); attributes.put("s", speech); + // Foto des Abgeordnetes + String picture = MongoPprUtils.getParlamentarierPictureByID(parlamentarierId); + attributes.put("picture", picture); + // NLP: Topic if ((speech.getNlp() != null) && (speech.getNlp().getTopics() != null)) { Map topics = Topic.condenseTopicInformation(speech.getNlp().getTopics()); // Daten "verdichten"... @@ -187,9 +193,27 @@ public class FrontEndController { speech.getNlp().setPosList((List) new ArrayList()); // Ensure it's never null } - // TODO: Token wird momentan etwas komisch abgespeichert, da im Attribut text die POS art steht, und in pos die Anzahl dieser POS arten. Umstrukturieren damit keine Verwirrung herrscht + // NLP: Sentiments + Sentiment sentimentObj = null; + if (speech.getNlp() != null && speech.getNlp().getSentiments() != null && !speech.getNlp().getSentiments().isEmpty()) { + 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 - " + sentimentObj); + attributes.put("sentiment", sentimentObj); + ctx.render("speech.ftl", attributes); } } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/RESTHandler.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/RESTHandler.java index a33dd16..3d6e066 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/RESTHandler.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/RESTHandler.java @@ -62,7 +62,7 @@ public class RESTHandler { // Reden app.get("/reden/{id}", FrontEndController::listSpeeches); // zeige Reden eines Parlamentariers an - app.get("/reden/{id}/{redeId}", SpeechController::showSpeech); // zeige eine bestimmte Rede des Parlamentariers an + app.get("/reden/{id}/{redeId}", FrontEndController::showSpeech); // zeige eine bestimmte Rede des Parlamentariers an app.get("/reden", SpeechController::listAllSpeeches); // zeige alle Reden an (Filtern möglich) } diff --git a/src/main/resources/templates/nlp.ftl b/src/main/resources/templates/nlp.ftl index e37399b..491c488 100644 --- a/src/main/resources/templates/nlp.ftl +++ b/src/main/resources/templates/nlp.ftl @@ -15,13 +15,9 @@ - <#if s.nlp.sentiments??> -

SentimentsInformation (als Radar Chart)

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

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..12938b5 100644 --- a/src/main/resources/templates/sentimentsRadarChart.ftl +++ b/src/main/resources/templates/sentimentsRadarChart.ftl @@ -0,0 +1,136 @@ + + +