Sped up All Speeches Call
This commit is contained in:
parent
c866162d31
commit
92c2d21b8f
5 changed files with 169 additions and 17 deletions
|
@ -1,10 +1,7 @@
|
|||
package org.texttechnologylab.project.gruppe_05_1.database;
|
||||
|
||||
import com.mongodb.client.*;
|
||||
import com.mongodb.client.model.Accumulators;
|
||||
import com.mongodb.client.model.Aggregates;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import com.mongodb.client.model.Projections;
|
||||
import com.mongodb.client.model.*;
|
||||
import io.javalin.http.Context;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
|
@ -13,6 +10,7 @@ import org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb.Speech_
|
|||
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.html.SpeechOverview;
|
||||
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;
|
||||
|
@ -295,6 +293,11 @@ public class MongoPprUtils {
|
|||
return readParlamentarierDetailsFromSpeaker(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt einen Speaker aus der Datenbank
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static Speaker_MongoDB_Impl getSpeakerById(String id) {
|
||||
Logger.debug("ID: " + id);
|
||||
Document doc = MongoDBHandler.findFirstDocumentInCollection(getSpeakerCollection(), "_id", id);
|
||||
|
@ -584,6 +587,43 @@ public class MongoPprUtils {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Holt die Redeinformationen aus der Datenbank, die wichtig sind, um eine Liste der Reden in HTML darzustellen
|
||||
* @return
|
||||
*/
|
||||
public static List<SpeechOverview> getSpeechOverview() {
|
||||
|
||||
List<SpeechOverview> result = new ArrayList<>();
|
||||
|
||||
MongoCollection<Document> collection = getSpeechCollection();
|
||||
|
||||
Document projection = new Document("speechKey", 1)
|
||||
.append("speakerId", 1)
|
||||
.append("dateTimeString", 1)
|
||||
.append("speakerName", 1)
|
||||
.append("fraction", 1)
|
||||
.append("agendaTitel", 1);
|
||||
|
||||
List<Document> docs = collection.find()
|
||||
.projection(projection)
|
||||
.sort(Sorts.descending("dateTime"))
|
||||
.into(new ArrayList<>());
|
||||
|
||||
for (Document doc : docs) {
|
||||
result.add(new SpeechOverview(
|
||||
doc.getString("speechKey"),
|
||||
doc.getInteger("speakerId"),
|
||||
doc.getString("dateTimeString"),
|
||||
doc.getString("speakerName"),
|
||||
doc.getString("fraction"),
|
||||
doc.getString("agendaTitel")
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Füge Rede-Metadaten (welche in der Session-Collection stehen) der Rede hinzu.
|
||||
* Achtung: Redezeit ist in der Datenbank in unterschiedlichen Formaten vorhanden.
|
||||
|
@ -648,7 +688,7 @@ public class MongoPprUtils {
|
|||
* @param key: Rede ID
|
||||
* @return
|
||||
*/
|
||||
public static HtmlSpeech getHTMLSpeechByKey(String key) {
|
||||
public static HtmlSpeech getHtmlSpeechByKey(String key) {
|
||||
Document filter = new Document("speechKey", key);
|
||||
Document speechDoc = getSpeechCollection().find(filter).first();
|
||||
if (speechDoc == null) {
|
||||
|
@ -773,6 +813,11 @@ public class MongoPprUtils {
|
|||
return speechIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert die Liste aller Parteien/Fraktionen, welche in der Liste der Parlamentarier stehen, zurück.
|
||||
* Diese Liste dient zur Filterung der Parlamentarier auf der entsprechenden Seite.
|
||||
* @return List<String> Liste aller Parteien/Fraktionen, welche in der Liste der Parlamentarier stehen
|
||||
*/
|
||||
public static List<String> getAllPartiesOfSpeakers() {
|
||||
Document doc = MongoDBHandler.findFirstDocumentInCollection(getMetadataCollection(), "type", "parties_of_speakers");
|
||||
if (doc == null) {return new ArrayList<>();}
|
||||
|
@ -870,4 +915,16 @@ public class MongoPprUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert die Liste aller Topics, zurück.
|
||||
* Diese Liste dient zur Filterung der Reden auf der entsprechenden Seite.
|
||||
* @return Liste aller Topics
|
||||
*/
|
||||
public static List<String> getAllTopics() {
|
||||
Document doc = MongoDBHandler.findFirstDocumentInCollection(getMetadataCollection(), "type", "topics");
|
||||
if (doc == null) {return new ArrayList<>();}
|
||||
else {
|
||||
return new ArrayList<>(doc.getList("value", String.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package org.texttechnologylab.project.gruppe_05_1.domain.html;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class SpeechOverview {
|
||||
String speechKey;
|
||||
Integer speakerId;
|
||||
String dateTimeString;
|
||||
String speakerName;
|
||||
String fraction;
|
||||
String agendaTitel;
|
||||
|
||||
public SpeechOverview() {}
|
||||
|
||||
public SpeechOverview(String speechKey, Integer speakerId, String dateTimeString, String speakerName, String fraction, String agendaTitel) {
|
||||
this.speechKey = speechKey;
|
||||
this.speakerId = speakerId;
|
||||
this.dateTimeString = dateTimeString;
|
||||
this.speakerName = speakerName;
|
||||
this.fraction = fraction;
|
||||
this.agendaTitel = agendaTitel;
|
||||
}
|
||||
|
||||
public String getSpeechKey() {
|
||||
return speechKey;
|
||||
}
|
||||
|
||||
public void setSpeechKey(String speechKey) {
|
||||
this.speechKey = speechKey;
|
||||
}
|
||||
|
||||
public Integer getSpeakerId() {
|
||||
return speakerId;
|
||||
}
|
||||
|
||||
public void setSpeakerId(Integer speakerId) {
|
||||
this.speakerId = speakerId;
|
||||
}
|
||||
|
||||
public String getDateTimeString() {
|
||||
return dateTimeString;
|
||||
}
|
||||
|
||||
public void setDateTimeString(String dateTimeString) {
|
||||
this.dateTimeString = dateTimeString;
|
||||
}
|
||||
|
||||
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 String getAgendaTitel() {
|
||||
return agendaTitel;
|
||||
}
|
||||
|
||||
public void setAgendaTitel(String agendaTitel) {
|
||||
this.agendaTitel = agendaTitel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SpeechOverview that)) return false;
|
||||
return Objects.equals(speechKey, that.speechKey) && Objects.equals(speakerId, that.speakerId)
|
||||
&& Objects.equals(dateTimeString, that.dateTimeString) && Objects.equals(speakerName, that.speakerName)
|
||||
&& Objects.equals(fraction, that.fraction) && Objects.equals(agendaTitel, that.agendaTitel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(speechKey, speakerId, dateTimeString, speakerName, fraction, agendaTitel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", SpeechOverview.class.getSimpleName() + "[", "]")
|
||||
.add("speechKey='" + speechKey + "'")
|
||||
.add("speakerId=" + speakerId)
|
||||
.add("dateTimeString='" + dateTimeString + "'")
|
||||
.add("speakerName='" + speakerName + "'")
|
||||
.add("fraction='" + fraction + "'")
|
||||
.add("agendaTitel='" + agendaTitel + "'")
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package org.texttechnologylab.project.gruppe_05_1.export;
|
||||
|
||||
import org.eclipse.jetty.xml.XmlParser;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Node;
|
||||
import org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb.Speaker_MongoDB_Impl;
|
||||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech;
|
||||
import javax.xml.transform.Transformer;
|
||||
|
|
|
@ -5,6 +5,7 @@ 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.html.SpeechOverview;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.nlp.NamedEntity;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Sentiment;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Token;
|
||||
|
@ -16,8 +17,6 @@ import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.texttechnologylab.project.gruppe_05_1.util.PPRUtils.listFractionsFromMembers;
|
||||
|
||||
public class SpeechController {
|
||||
/**
|
||||
* Liste alle Reden eines Parlamentariers an
|
||||
|
@ -72,7 +71,7 @@ public class SpeechController {
|
|||
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
|
||||
HtmlSpeech speech = MongoPprUtils.getHTMLSpeechByKey(redeId);
|
||||
HtmlSpeech speech = MongoPprUtils.getHtmlSpeechByKey(redeId);
|
||||
if (speech == null) {
|
||||
attributes.put("error", "Rede " + redeId + " nicht vorhanden");
|
||||
ctx.render("speech.ftl", attributes);
|
||||
|
@ -222,10 +221,10 @@ public class SpeechController {
|
|||
String filter = ctx.queryParam("filter");
|
||||
Logger.info("Filter: '" + filter + "'");
|
||||
|
||||
List<SpeechMetaData> speechMetaDataList = MongoPprUtils.getSpeechesMetadata(filter);
|
||||
List<SpeechOverview> speechOverviews = MongoPprUtils.getSpeechOverview();
|
||||
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("speechesMetaDataList", speechMetaDataList);
|
||||
attributes.put("speechesMetaDataList", speechOverviews);
|
||||
|
||||
// Filtern nach Text
|
||||
attributes.put("filter", filter == null || filter.isBlank() ? null : filter);
|
||||
|
@ -233,8 +232,8 @@ public class SpeechController {
|
|||
// Filtern nach Partei/Fraktion
|
||||
attributes.put("parties", MongoPprUtils.getAllPartiesFromSpeeches());
|
||||
|
||||
// Filtern nach Topics - TODO
|
||||
List<String> topics = Arrays.asList("International", "Government", "Labor", "Economy", "Public");
|
||||
// Filtern nach Topics
|
||||
List<String> topics = MongoPprUtils.getAllTopics();
|
||||
attributes.put("topics", topics);
|
||||
|
||||
ctx.render("showAllSpeechesList.ftl", attributes);
|
||||
|
|
|
@ -32,8 +32,9 @@
|
|||
<tr>
|
||||
<td>${redeMd.dateTimeString}</td>
|
||||
<td>${redeMd.speakerName}</td>
|
||||
<td>${redeMd.fraktion}</td>
|
||||
<td><a href="/reden/${redeMd.speakerId?string("0")}/${redeMd.speechKey}">${redeMd.agendaTitle}</a></td>
|
||||
<td><#if redeMd.fraction??> ${redeMd.fraction} <#else>Parteilos</#if></td>
|
||||
<td><a href="/reden/${redeMd.speakerId?string("0")}/${redeMd.speechKey}"><#if redeMd.agendaTitel??> ${redeMd.agendaTitel} <#else>Agendapunkt</#if></a></td>
|
||||
|
||||
</tr>
|
||||
</#list>
|
||||
</tbody>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue