diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..149065c Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..585eeaa Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000..a5b09d3 Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000..5d85c26 Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/org/.DS_Store b/src/main/java/org/.DS_Store new file mode 100644 index 0000000..7b8c702 Binary files /dev/null and b/src/main/java/org/.DS_Store differ diff --git a/src/main/java/org/texttechnologylab/.DS_Store b/src/main/java/org/texttechnologylab/.DS_Store new file mode 100644 index 0000000..deb3b5d Binary files /dev/null and b/src/main/java/org/texttechnologylab/.DS_Store differ diff --git a/src/main/java/org/texttechnologylab/project/.DS_Store b/src/main/java/org/texttechnologylab/project/.DS_Store new file mode 100644 index 0000000..a021884 Binary files /dev/null and b/src/main/java/org/texttechnologylab/project/.DS_Store differ diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/.DS_Store b/src/main/java/org/texttechnologylab/project/gruppe_05_1/.DS_Store new file mode 100644 index 0000000..e768681 Binary files /dev/null and b/src/main/java/org/texttechnologylab/project/gruppe_05_1/.DS_Store differ diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/.DS_Store b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/.DS_Store new file mode 100644 index 0000000..0185c25 Binary files /dev/null and b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/.DS_Store differ 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 d3c7036..41b85ae 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 @@ -8,6 +8,7 @@ import org.texttechnologylab.project.gruppe_05_1.database.domainimp.speeches.Spe 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.*; 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; @@ -417,10 +418,19 @@ public class MongoPprUtils { } } + /** + * Liefert die Rede-Informationen für die Anzeige einer Rede: + * - die Rede-ID + * - Name und Fraktion des Redners + * - Die Inhalte der Rede + * @param key: Rede ID + * @return + */ 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/database/domainimp/.DS_Store b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimp/.DS_Store new file mode 100644 index 0000000..5069ad4 Binary files /dev/null and b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimp/.DS_Store differ diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/.DS_Store b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/.DS_Store new file mode 100644 index 0000000..b62441a Binary files /dev/null and b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/.DS_Store differ 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 3b4080e..1e61039 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 @@ -2,6 +2,8 @@ package org.texttechnologylab.project.gruppe_05_1.domain.html; import org.bson.Document; import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.domain.nlp.NlpInfo; +import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Topic; import java.util.ArrayList; import java.util.List; @@ -13,6 +15,7 @@ public class HtmlSpeech { String speakerName; String fraction; List content = new ArrayList<>(); + NlpInfo nlp = null; public HtmlSpeech() { } @@ -30,6 +33,32 @@ public class HtmlSpeech { addContent(new SpeechContent(contentDoc)); } } + + Document nlpDoc = (Document) doc.get("analysisResults"); + nlp = readNlpInfo(nlpDoc); + } + + private NlpInfo readNlpInfo(Document nlpDoc) { + if (nlpDoc == null) return null; + NlpInfo nlp = new NlpInfo(); + + // TODO: HERE + List tokensDocs = nlpDoc.get("tokens", MongoDBHandler.DOC_LIST_CLASS); + + List sentencesDocs = nlpDoc.get("sentences", MongoDBHandler.DOC_LIST_CLASS); + + List dependenciesDocs = nlpDoc.get("dependencies", MongoDBHandler.DOC_LIST_CLASS); + + List namedEntitiesDocs = nlpDoc.get("namedEntities", MongoDBHandler.DOC_LIST_CLASS); + + List sentimentsDocs = nlpDoc.get("sentiments", MongoDBHandler.DOC_LIST_CLASS); + + List topicsDocs = nlpDoc.get("topics", MongoDBHandler.DOC_LIST_CLASS); + nlp.setTopics(Topic.readTopicsFromMongo(topicsDocs)); + + // TODO: Video + + return nlp; } public String getSpeechKey() { @@ -68,16 +97,26 @@ public class HtmlSpeech { content.add(contentLine); } + public NlpInfo getNlp() { + return nlp; + } + + public void setNlp(NlpInfo nlp) { + this.nlp = nlp; + } + @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); + return Objects.equals(speechKey, that.speechKey) && Objects.equals(speakerName, that.speakerName) + && Objects.equals(fraction, that.fraction) && Objects.equals(content, that.content) + && Objects.equals(nlp, that.nlp); } @Override public int hashCode() { - return Objects.hash(speechKey, speakerName, fraction, content); + return Objects.hash(speechKey, speakerName, fraction, content, nlp); } @Override @@ -87,6 +126,7 @@ public class HtmlSpeech { .add("speakerName='" + speakerName + "'") .add("fraction='" + fraction + "'") .add("content=" + content) + .add("nlp=" + nlp) .toString(); } } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/NlpInfo.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/NlpInfo.java index 442bca8..de7ecd5 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/NlpInfo.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/NlpInfo.java @@ -1,7 +1,9 @@ package org.texttechnologylab.project.gruppe_05_1.domain.nlp; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.StringJoiner; public class NlpInfo { List tokens; @@ -10,7 +12,7 @@ public class NlpInfo { List namedEntities; Sentiment overallSentiment; // Sentiment for the whole text ; kann null sein! List sentiments; // sentiments for the respective sentences (eine Liste von 0..n Elementen) - List topic; + List topics; List posList; VideoInformation videoInformation; @@ -63,12 +65,12 @@ public class NlpInfo { this.sentiments = sentiments; } - public List getTopic() { - return topic; + public List getTopics() { + return topics; } - public void setTopic(List topic) { - this.topic = topic; + public void setTopics(List topics) { + this.topics = topics; } public List getPosList() { @@ -94,12 +96,28 @@ public class NlpInfo { return Objects.equals(tokens, nlpInfo.tokens) && Objects.equals(sentences, nlpInfo.sentences) && Objects.equals(dependencies, nlpInfo.dependencies) && Objects.equals(namedEntities, nlpInfo.namedEntities) && Objects.equals(overallSentiment, nlpInfo.overallSentiment) && Objects.equals(sentiments, nlpInfo.sentiments) - && Objects.equals(topic, nlpInfo.topic) && Objects.equals(posList, nlpInfo.posList) + && Objects.equals(topics, nlpInfo.topics) && Objects.equals(posList, nlpInfo.posList) && Objects.equals(videoInformation, nlpInfo.videoInformation); } @Override public int hashCode() { - return Objects.hash(tokens, sentences, dependencies, namedEntities, overallSentiment, sentiments, topic, posList, videoInformation); + return Objects.hash(tokens, sentences, dependencies, namedEntities, overallSentiment, sentiments, topics, posList, videoInformation); } + + @Override + public String toString() { + return new StringJoiner(", ", NlpInfo.class.getSimpleName() + "[", "]") + .add("tokens=" + tokens) + .add("sentences=" + sentences) + .add("dependencies=" + dependencies) + .add("namedEntities=" + namedEntities) + .add("overallSentiment=" + overallSentiment) + .add("sentiments=" + sentiments) + .add("topics=" + topics) + .add("posList=" + posList) + .add("videoInformation=" + videoInformation) + .toString(); + } + } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Topic.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Topic.java index 3a363e4..474f5aa 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Topic.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/nlp/Topic.java @@ -1,18 +1,19 @@ package org.texttechnologylab.project.gruppe_05_1.domain.nlp; -import java.util.Objects; -import java.util.StringJoiner; +import org.bson.Document; + +import java.util.*; +import java.util.stream.Collectors; public class Topic { String topic; - double score; - // tags TODO + Double score; String text; public Topic() { } - public Topic(String topic, double score, String text) { + public Topic(String topic, Double score, String text) { this.topic = topic; this.score = score; this.text = text; @@ -26,11 +27,11 @@ public class Topic { this.topic = topic; } - public double getScore() { + public Double getScore() { return score; } - public void setScore(double score) { + public void setScore(Double score) { this.score = score; } @@ -62,4 +63,45 @@ public class Topic { .add("text='" + text + "'") .toString(); } + + + /** + * Die Topics-Dokumente (Speech --> analysisResults --> topics) aus der MongoDB lesen + * @param topicsDocs Eine Liste von Mongo-Dokumenten + * @return Eine Liste der Topics + */ + public static List readTopicsFromMongo(List topicsDocs) { + List topics = new ArrayList<>(); + for (Document doc : topicsDocs) { + topics.add(new Topic(doc.getString("topic"), + doc.getDouble("score"), + doc.getString("text") + )); + } + return topics; + } + + + /** + * Topic-Informationen "verdichten": + * Ausgangssituation: eine Liste mit mehreren Topics. Ein Topic kann in dieser Liste mehrfach vorkommen. + * Man will wissen, welche Score hat jeden Topic. Hier werden die Werte der jeweiligen Topics summiert. + * + * @param topicsList + * @return Map + */ + public static Map condenseTopicInformation(List topicsList) { + Map condensedTopicInfo = new HashMap<>(); + + for (Topic t : topicsList) { + Double oldValue = condensedTopicInfo.get(t.getTopic()); + if (oldValue != null) { + condensedTopicInfo.replace(t.getTopic(), oldValue + t.getScore()); + } else { + condensedTopicInfo.put(t.getTopic(), t.getScore()); + } + } + + return condensedTopicInfo; + } } 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 df6e5cb..3d25851 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 @@ -5,12 +5,14 @@ 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.nlp.Topic; import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData; import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class SpeechController { /** @@ -68,6 +70,15 @@ public class SpeechController { HtmlSpeech speech = MongoPprUtils.getSpeechByKey(redeId); attributes.put("s", speech); + // NLP: Topic + if ((speech.getNlp() != null) && (speech.getNlp().getTopics() != null)) { + Map topics = Topic.condenseTopicInformation(speech.getNlp().getTopics()); // Daten "verdichten"... + speech.getNlp().setTopics( + topics.entrySet().stream() + .map(me -> new Topic(me.getKey(), me.getValue(), null)) + .collect(Collectors.toList())); + } + ctx.render("speech.ftl", attributes); } diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/namedEntitiesSunburstChart.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/namedEntitiesSunburstChart.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/nlp.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/nlp.ftl new file mode 100644 index 0000000..d5fc652 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/nlp.ftl @@ -0,0 +1,35 @@ + <#if s.nlp.topics??> +

Topics Information (als Bubble Chart)

+ <#assign condenseTopicInformation = s.nlp.topics> + <#include "topicsBubbleChart.ftl"> + <#else> +

Keine Topics Information für diese Rede verfügbar

+ + + + <#if s.nlp.posList??> +

POS Information (als Bar Chart)

+ <#assign posList = s.nlp.posList> + <#include "posBarChart.ftl"> + <#else> +

Keine POS Information verfügbar für diese Rede verfügbar

+ + + + <#if s.nlp.sentiments??> +

SentimentsInformation (als Radar Chart)

+ <#assign overallSentiment = s.nlp.overallSentiment> + <#assign sentiments = s.nlp.sentiments> + <#include "sentimentsRadarChart.ftl"> + <#else> +

Keine Sentiments Information für diese Rede verfügbar

+ + + + <#if s.nlp.namedEntities??> +

Named Entities Information (als Sunburst Chart)

+ <#assign nea = s.nlp.namedEntities> + <#include "namedEntitiesSunburstChart.ftl"> + <#else> +

Keine Named Entities Information für diese Rede verfügbar

+ \ No newline at end of file diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/posBarChart.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/posBarChart.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/sentimentsRadarChart.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/sentimentsRadarChart.ftl new file mode 100644 index 0000000..e69de29 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 index 8012ad4..9bf1058 100644 --- 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 @@ -22,11 +22,19 @@

Rede ${s.speechKey}

-
- <#list s.content as c> - <#include "speechContent.ftl"> - -
+ <#list s.content as c> + <#include "speechContent.ftl"> + + +

+ <#if s.nlp??> +

NLP Information

+ <#assign nlp = "${s.nlp}"> + <#include "nlp.ftl"> + <#else> +

Keine NLP Information verfügbar für diese Rede

+ +

diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/topicsBubbleChart.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/topicsBubbleChart.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/.DS_Store b/src/main/resources/.DS_Store new file mode 100644 index 0000000..41fcc30 Binary files /dev/null and b/src/main/resources/.DS_Store differ