From e4d7be5a88270a8559d4efa7ff371b53f86f9c6d Mon Sep 17 00:00:00 2001 From: vysitor Date: Tue, 11 Mar 2025 00:06:55 +0100 Subject: [PATCH] Speeches and Comments are displayed (without NLP information) --- .../gruppe_05_1/database/MongoPprUtils.java | 17 +++- .../gruppe_05_1/domain/html/HtmlSpeech.java | 92 +++++++++++++++++++ .../domain/html/SpeechContent.java | 69 ++++++++++++++ .../rest/ParlamentarierController.java | 2 - .../gruppe_05_1/rest/SpeechController.java | 41 +-------- .../gruppe_05_1/website/templates/speech.ftl | 33 +++++++ .../website/templates/speechContent.ftl | 7 ++ 7 files changed, 220 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/HtmlSpeech.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/SpeechContent.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speech.ftl create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speechContent.ftl diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java index 6199798..068de2c 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java @@ -5,18 +5,17 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import org.bson.Document; import org.texttechnologylab.project.gruppe_05_1.database.domainimp.speeches.Speech_MongoDB_Impl; +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.speaker.Membership; import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData; import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; -import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.Speech_File_Impl; import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; -import java.time.format.DateTimeFormatter; import java.util.*; /** @@ -277,6 +276,11 @@ public class MongoPprUtils { return m; } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + // Speech + // TODO: kopiere die Speech-Sachen von Übung 4 hierher! /** @@ -313,7 +317,7 @@ public class MongoPprUtils { * @param speakerId * @return */ - public static List getSpeechesMetadataForSeaker(String speakerId) { + public static List getSpeechesMetadataForSpeaker(String speakerId) { List speechMetaDataList = new ArrayList<>(); List speeches = MongoPprUtils.getSpeechesOfSpeaker(speakerId); @@ -388,4 +392,11 @@ public class MongoPprUtils { return (String) iter.first().get("title"); } } + + public static HtmlSpeech getSpeechByKey(String key) { + Document filter = new Document("speechKey", key); + Document speechDoc = getSpeechCollection().find(filter).first(); + + return new HtmlSpeech(speechDoc); + } } 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 new file mode 100644 index 0000000..3b4080e --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/HtmlSpeech.java @@ -0,0 +1,92 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.html; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public class HtmlSpeech { + String speechKey; + String speakerName; + String fraction; + List content = new ArrayList<>(); + + public HtmlSpeech() { + } + + public HtmlSpeech(Document doc) { + setSpeechKey(doc.getString("speechKey")); + setSpeakerName(doc.getString("speakerName")); + setFraction(doc.getString("fraction")); + + List contentDocList = doc.get("speechContents", MongoDBHandler.DOC_LIST_CLASS); + if (contentDocList == null) { + setContent(new ArrayList<>()); + } else { + for (Document contentDoc : contentDocList) { + addContent(new SpeechContent(contentDoc)); + } + } + } + + public String getSpeechKey() { + return speechKey; + } + + public void setSpeechKey(String speechKey) { + this.speechKey = speechKey; + } + + public String getSpeakerName() { + return speakerName; + } + + public void setSpeakerName(String speakerName) { + this.speakerName = speakerName; + } + + public String getFraction() { + return fraction; + } + + public void setFraction(String fraction) { + this.fraction = fraction; + } + + public List getContent() { + return content; + } + + public void setContent(List content) { + this.content = content; + } + + public void addContent(SpeechContent contentLine) { + content.add(contentLine); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof HtmlSpeech that)) return false; + return Objects.equals(speechKey, that.speechKey) && Objects.equals(speakerName, that.speakerName) && Objects.equals(fraction, that.fraction) && Objects.equals(content, that.content); + } + + @Override + public int hashCode() { + return Objects.hash(speechKey, speakerName, fraction, content); + } + + @Override + public String toString() { + return new StringJoiner(", ", HtmlSpeech.class.getSimpleName() + "[", "]") + .add("speechKey='" + speechKey + "'") + .add("speakerName='" + speakerName + "'") + .add("fraction='" + fraction + "'") + .add("content=" + content) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/SpeechContent.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/SpeechContent.java new file mode 100644 index 0000000..0bc6f03 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/SpeechContent.java @@ -0,0 +1,69 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.html; + +import org.bson.Document; + +import java.util.Objects; +import java.util.StringJoiner; + +public class SpeechContent { + + public enum SpeechContentType {SPEAKER, LINE, COMMENT} + + SpeechContentType type; + String content; // name und Fraktion für SPEAKER / content für LINE / comment für COMMENT + + public SpeechContent() { + } + + public SpeechContent(Document doc) { + String type = (String) doc.get("type"); + if (type.equalsIgnoreCase("speaker")) { + setType(SpeechContentType.SPEAKER); + setContent(doc.getString("speakerName") + " / " + doc.getString("fraction")); + } else if (type.equalsIgnoreCase("line")) { + setType(SpeechContentType.LINE); + setContent(doc.getString("content")); + } else if (type.equalsIgnoreCase("comment")) { + setType(SpeechContentType.COMMENT); + setContent(doc.getString("comment")); + } + } + + public SpeechContentType getType() { + return type; + } + + public void setType(SpeechContentType type) { + this.type = type; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SpeechContent that)) return false; + return type == that.type && Objects.equals(content, that.content); + } + + @Override + public int hashCode() { + return Objects.hash(type, content); + } + + @Override + public String toString() { + return new StringJoiner(", ", SpeechContent.class.getSimpleName() + "[", "]") + .add("type=" + type) + .add("content='" + content + "'") + .toString(); + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/ParlamentarierController.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/ParlamentarierController.java index 6a63a9a..369ef35 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/ParlamentarierController.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/ParlamentarierController.java @@ -100,8 +100,6 @@ public class ParlamentarierController { attributes.put("speechesPlaceholder", emptyList); } - - List speeches = MongoPprUtils.getSpeechesOfSpeaker(pd.getId()); ctx.render("parlamentarierDetails.ftl", attributes); } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java index 999c258..df6e5cb 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java @@ -3,15 +3,11 @@ package org.texttechnologylab.project.gruppe_05_1.rest; import io.javalin.http.Context; import io.javalin.openapi.*; 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.ParlamentarierDetails; -import org.texttechnologylab.project.gruppe_05_1.domain.speech.Protocol; import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData; -import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; -import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Comment; import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech; -import java.time.LocalDate; -import java.time.LocalTime; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,7 +34,7 @@ public class SpeechController { String parlamentarierId = ctx.pathParam("id"); ParlamentarierDetails p = MongoPprUtils.getParlamentarierDetailsByID(parlamentarierId); - List speechMetaDataList = MongoPprUtils.getSpeechesMetadataForSeaker(parlamentarierId); + List speechMetaDataList = MongoPprUtils.getSpeechesMetadataForSpeaker(parlamentarierId); Map attributes = new HashMap<>(); attributes.put("p", p); @@ -65,41 +61,14 @@ public class SpeechController { @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<>(); - /* - Speech rede = MongoPprUtils.getSpeechesById(redeId); - List comments = MongoPprUtils.getCommentsForSpeech(redeId); - ParlamentarierDetails p = MongoPprUtils.getParlamentarierDetailsByID(parlamentarierId); + HtmlSpeech speech = MongoPprUtils.getSpeechByKey(redeId); + attributes.put("s", speech); - - attributes.put("p", p); - attributes.put("rede", rede); - attributes.put("comments", comments.size() > 0 ? comments : null); - Protocol protocol = rede.getProtocol(); - if (protocol == null) { - attributes.put("date", "(keine Angaben)"); - attributes.put("time", "(keine Angaben)"); - } else { - LocalDate date = protocol.getDate(); - LocalTime time = protocol.getStarttime(); - if (date == null) { - attributes.put("date", "(keine Angaben)"); - } else { - attributes.put("date", GeneralUtils.formatDate(date)); - } - if (time == null) { - attributes.put("time", "(keine Angaben)"); - } else { - attributes.put("time", GeneralUtils.formatTime(time)); - } - } - - */ - ctx.render("speechWithComments.ftl", attributes); + ctx.render("speech.ftl", attributes); } } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speech.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speech.ftl new file mode 100644 index 0000000..8012ad4 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speech.ftl @@ -0,0 +1,33 @@ + + + + + + Rede von ${s.speakerName} <#if s.fraction??> (${s.fraction}) </#if> + + + + +
+

Rede von ${s.speakerName} <#if s.fraction??> (${s.fraction})

+
+ +
+ +

Rede ${s.speechKey}

+ +
+ <#list s.content as c> + <#include "speechContent.ftl"> + +
+ + + + \ No newline at end of file diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speechContent.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speechContent.ftl new file mode 100644 index 0000000..752d416 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/speechContent.ftl @@ -0,0 +1,7 @@ +<#if c.type == 'SPEAKER'> +<#elseif c.type == 'LINE'> +${c.content} +<#elseif c.type == 'COMMENT'> +Kommentar: ${c.content} + +