added JavaDoc to my classes and methods
This commit is contained in:
parent
8b4ff83cc6
commit
5650f1c63b
21 changed files with 146 additions and 26 deletions
|
@ -44,6 +44,13 @@ public class Main {
|
|||
public static final String MEMBER_IMAGES_DIR = "src/main/resources/membersOfParliamentImages/";
|
||||
public static final String TEMP_EXPORT_DIR = "src/main/resources/tempExport/";
|
||||
|
||||
/**
|
||||
* Main Methode zum Start des Multimodalen Parlament Explorers
|
||||
* Programm-Flag Implementierung und DIR Konstanten von Jonas
|
||||
*
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
UPLOAD_MEMBER_PHOTOS = Arrays.asList(args).contains("uploadMemberPhotos");
|
||||
FORCE_UPLOAD_MEMBERS = Arrays.asList(args).contains("forceUploadMembers");
|
||||
|
|
|
@ -538,10 +538,7 @@ public class MongoDBHandler {
|
|||
collection.deleteOne(deleteQuery);
|
||||
}
|
||||
|
||||
/*
|
||||
* Justus Jonas operations
|
||||
* =======================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fügt eine Session in die Datenbank ein.
|
||||
*
|
||||
|
@ -859,6 +856,12 @@ public class MongoDBHandler {
|
|||
return loadMemberImageFromFileByName(firstName, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Bild eines Mitglieds aus dem Ordner resources/membersOfParliamentImages anhand des Namens.
|
||||
* @param firstName Der Vorname des Mitglieds.
|
||||
* @return das Bild des Mitglieds als base64-String.
|
||||
* Implementiert von Jonas
|
||||
**/
|
||||
public String loadMemberImageFromFileByName(String firstName, String name) {
|
||||
// get the member photo from the resources/membersOfParliamentImages folder
|
||||
File photo = new File(MEMBER_IMAGES_DIR + name + "_" + firstName + ".jpg");
|
||||
|
@ -876,6 +879,12 @@ public class MongoDBHandler {
|
|||
return image_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Bild eines Mitglieds aus dem Ordner resources/membersOfParliamentImages anhand des Namens.
|
||||
* @param memberId Der Vorname des Mitglieds.
|
||||
* @param base64String Der base64-String des Bildes.
|
||||
* Implementiert von Jonas
|
||||
**/
|
||||
public void uploadMemberPhoto(String memberId, String base64String) {
|
||||
if (memberPhotoCollection.find(eq("memberId", memberId)).first() != null) {
|
||||
Logger.warn("Member photo for " + memberId + " already exists in the database. Overwriting...");
|
||||
|
@ -886,6 +895,10 @@ public class MongoDBHandler {
|
|||
memberPhotoCollection.insertOne(photoDocument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt die Bilder aller Mitglieder in die Datenbank.
|
||||
* Implementiert von Jonas
|
||||
**/
|
||||
public void uploadMemberPhotos() {
|
||||
// get a list of the string of first and last name of all members from the DB
|
||||
// only fetch the first and lastname
|
||||
|
@ -912,6 +925,10 @@ public class MongoDBHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt die Bilder aller Mitglieder aus dem Ordner resources/membersOfParliamentImages in die Datenbank.
|
||||
* Implementiert von Jonas
|
||||
**/
|
||||
public void uploadMemberPhotosFromResourceFolder() {
|
||||
Logger.info("Found " + PPRUtils.listFilesInDirectory(MEMBER_IMAGES_DIR).size() + " member photos to upload.");
|
||||
// loop over file names in the directory
|
||||
|
|
|
@ -176,6 +176,14 @@ public class MongoPprUtils {
|
|||
return plist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetched alle Parlamentarier, die einen Suchkriterium erfüllen.
|
||||
* Das Suchkriterium wird auf allen Feldern angewandt: Vorname, Nachname, Partei.
|
||||
* Ist das Suchkriterium leer, werden alle Parlamentarier zurückgeliefert
|
||||
* Implementiert von Jonas
|
||||
* @param ctx Session Context
|
||||
* @return List<Parlamentarier>
|
||||
*/
|
||||
public static List<Parlamentarier> getFilteredMembers(Context ctx) {
|
||||
// Get optional filter arguments
|
||||
String memberIdParam = ctx.queryParam("memberId");
|
||||
|
@ -244,6 +252,14 @@ public class MongoPprUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetched alle Parlamentarier aus der Datenbank, die einen Filter erfüllen
|
||||
* es wird nur die gegebene Projektion zurückgegeben
|
||||
* Implementiert von Jonas
|
||||
* @param filter Filter, der auf die Datenbank angewendet wird
|
||||
* @param projection Projektion, die auf die Datenbank angewendet wird
|
||||
* @return Liste von Parlamentariern
|
||||
**/
|
||||
public static List<Parlamentarier> retrieveAllMembersOfParliament(Bson filter, Bson projection) throws IOException {
|
||||
List<Document> speeches = getSpeakerCollection().find(filter).projection(projection).into(new ArrayList<>());
|
||||
List<Parlamentarier> result = new ArrayList<>();
|
||||
|
@ -370,8 +386,9 @@ public class MongoPprUtils {
|
|||
|
||||
/**
|
||||
* Holt einen Speaker aus der Datenbank
|
||||
* @param id
|
||||
* @return
|
||||
* Implementiert von Jonas
|
||||
* @param id ID des Parlamentariers
|
||||
* @return Speaker
|
||||
*/
|
||||
public static Speaker_MongoDB_Impl getSpeakerById(String id) {
|
||||
Logger.debug("ID: " + id);
|
||||
|
@ -823,6 +840,12 @@ public class MongoPprUtils {
|
|||
return new HtmlSpeech(speechDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementiert von Jonas
|
||||
* Liefert die Rede-Informationen für die Anzeige einer Rede
|
||||
* @param key: Rede ID
|
||||
* @return Speech
|
||||
*/
|
||||
public static Speech getSpeechByKey(String key) {
|
||||
Document filter = new Document("speechKey", key);
|
||||
Document speechDoc = getSpeechCollection().find(filter).first();
|
||||
|
@ -937,6 +960,12 @@ public class MongoPprUtils {
|
|||
return speechIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementiert von Jonas
|
||||
* Liefert alle Reden zurück, die ein bestimmtes Topic haben
|
||||
* @param topic Topic der Reden
|
||||
* @return Liste von Reden
|
||||
*/
|
||||
public static List<Speech> getAllSpeechesWithTopic(String topic) {
|
||||
List<Speech> speechIds = new ArrayList<>();
|
||||
Document filter = new Document("analysisResults.topics.topic", topic);
|
||||
|
@ -946,6 +975,13 @@ public class MongoPprUtils {
|
|||
}
|
||||
return speechIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementiert von Jonas
|
||||
* Liefert eine Map der POS Einträge und deren Häufigkeit für eine Rede
|
||||
* @param speechId ID der Rede
|
||||
* @return Map<String, Integer> POS Einträge und deren Häufigkeit
|
||||
*/
|
||||
public static Map<String, Integer> getPOSInformationCardinalitiesForSpeechById(String speechId) {
|
||||
List<Token> tokens = getHtmlSpeechByKey(speechId).getNlp().getTokens();
|
||||
Map<String, Integer> posCounts = Token.countPOS(tokens);
|
||||
|
@ -957,6 +993,12 @@ public class MongoPprUtils {
|
|||
return posCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementiert von Jonas
|
||||
* Liefert eine Map der Named Entities und deren Häufigkeit für eine Rede
|
||||
* @param speechId ID der Rede
|
||||
* @return Map<String, Integer> Named Entities und deren Häufigkeit
|
||||
*/
|
||||
public static Map<String, Integer> getNamedEntitiesInformationCardinalitiesForSpeechById(String speechId) {
|
||||
Map<String, Map<String, Integer>> namedEntitiesMapOfMaps = new HashMap<>();
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ import org.bson.Document;
|
|||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.AgendaItem_File_Impl;
|
||||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.AgendaItem;
|
||||
|
||||
|
||||
/**
|
||||
* Datei implementiert von Henry
|
||||
*/
|
||||
public class AgendaItem_MongoDB_Impl extends AgendaItem_File_Impl implements AgendaItem {
|
||||
public AgendaItem_MongoDB_Impl(Document mongoDocument) {
|
||||
super(
|
||||
|
|
|
@ -4,7 +4,9 @@ import org.bson.Document;
|
|||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.Session_File_Impl;
|
||||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Session;
|
||||
|
||||
|
||||
/**
|
||||
* Datei implementiert von Henry
|
||||
*/
|
||||
public class Session_MongoDB_Impl extends Session_File_Impl implements Session {
|
||||
|
||||
public Session_MongoDB_Impl(Document mongoDocument) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import static org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils.g
|
|||
/**
|
||||
* Datei implementiert von Valentin
|
||||
* Datei modifiziert von Jonas
|
||||
* toTeX() und toXML() hinzugefügt von Jonas
|
||||
*/
|
||||
public class Speaker_MongoDB_Impl extends Speaker implements MongoOperations<Speaker> {
|
||||
public Speaker_MongoDB_Impl createSpeakerMongoDBImpl(Document mongoDocument) {
|
||||
|
|
|
@ -19,6 +19,11 @@ import java.util.List;
|
|||
import static org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils.getAgendaTitle;
|
||||
import static org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils.getSessionDateTime;
|
||||
|
||||
/**
|
||||
* Datei implementiert von Henry
|
||||
* Modifiziert von Jonas
|
||||
* toTeX und toXML von Jonas
|
||||
*/
|
||||
public class Speech_MongoDB_Impl extends Speech_File_Impl implements Speech {
|
||||
public Speech_MongoDB_Impl(Document mongoDocument, boolean includeContent) {
|
||||
super(
|
||||
|
|
|
@ -5,7 +5,9 @@ import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.Comment_File
|
|||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Comment;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
||||
/*
|
||||
* Klassen-Implementieren von Jonas
|
||||
*/
|
||||
public class Comment_MongoDB_Impl extends Comment_File_Impl implements Comment {
|
||||
|
||||
public Comment_MongoDB_Impl(Document mongoDocument) {
|
||||
|
|
|
@ -5,7 +5,9 @@ import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.Line_File_Im
|
|||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Line;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
||||
/*
|
||||
* Klassen-Implementieren von Jonas
|
||||
*/
|
||||
public class Line_MongoDB_Impl extends Line_File_Impl implements Line {
|
||||
public Line_MongoDB_Impl(Document mongoDocument) {
|
||||
super(
|
||||
|
|
|
@ -5,6 +5,9 @@ import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Impls.Speaker_File
|
|||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speaker;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/*
|
||||
* Klassen-Implementieren von Jonas
|
||||
*/
|
||||
public class Speaker_MongoDB_Impl extends Speaker_File_Impl implements Speaker {
|
||||
public Speaker_MongoDB_Impl(Document mongoDocument) {
|
||||
super(
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Objects;
|
|||
import java.util.StringJoiner;
|
||||
/**
|
||||
* Datei implementiert von Valentin
|
||||
* toXML implementiert von Jonas
|
||||
*/
|
||||
public class NamedEntity {
|
||||
String type; // PER, LOC etc.
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Objects;
|
|||
import java.util.StringJoiner;
|
||||
/**
|
||||
* Datei implementiert von Valentin
|
||||
* toXML implementiert von Jonas
|
||||
*/
|
||||
public class Pos {
|
||||
String posValue; // ART, NN...
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Objects;
|
|||
import java.util.StringJoiner;
|
||||
/**
|
||||
* Datei implementiert von Valentin
|
||||
* toXML-Methode implementiert von Jonas
|
||||
*/
|
||||
public class Sentiment {
|
||||
int begin;
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
/**
|
||||
* Datei implementiert von Valentin
|
||||
* toXML-Methode implementiert von Jonas
|
||||
*/
|
||||
public class Topic {
|
||||
String topic;
|
||||
|
|
|
@ -24,6 +24,10 @@ import static org.texttechnologylab.project.gruppe_05_1.Main.RESOURCES_DIR;
|
|||
import static org.texttechnologylab.project.gruppe_05_1.Main.TEMP_EXPORT_DIR;
|
||||
import static org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils.*;
|
||||
|
||||
/**
|
||||
* Utility Klasse für die Erstellung von TeX-Dateien und Konvertierung in Base64-kodierte PDF-Dateien.
|
||||
* Implementiert von Jonas
|
||||
*/
|
||||
public class TeXUtil {
|
||||
private static final String PREAMBLE = readFileContentFromTeXDir();
|
||||
private static final String BEGIN_DOCUMENT = "\\begin{document}\n";
|
||||
|
|
|
@ -19,6 +19,10 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||
|
||||
import static org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils.*;
|
||||
|
||||
/**
|
||||
* Utility Klasse für die Erstellung von XML-Dateien und Konvertierung in Base64-kodierte PDF-Dateien.
|
||||
* Implementiert von Jonas
|
||||
*/
|
||||
public class XMLUtil {
|
||||
public static String documentToString(Document doc) {
|
||||
try {
|
||||
|
|
|
@ -23,7 +23,10 @@ import java.util.Map;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* Controller für die Frontend‑Routen.
|
||||
* Größtenteils implementiert von Jonas
|
||||
*/
|
||||
public class FrontEndController {
|
||||
@OpenApi(
|
||||
summary = "Get the homepage.",
|
||||
|
@ -138,19 +141,4 @@ public class FrontEndController {
|
|||
"aggregatedSentiments", aggregatedSentiments
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
TODO: Achtung: getParlamentarierDetails gibt es ab jetzt LEDIGLICH im ParlamentarierController!
|
||||
*/
|
||||
|
||||
/*
|
||||
TODO: Achtung: showSpeech gibt es ab jetzt LEDIGLICH im SpeechController!
|
||||
*/
|
||||
|
||||
/*
|
||||
TODO: Achtung: showSpeech gibt es ab jetzt LEDIGLICH im SpeechController!
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@ import java.util.List;
|
|||
|
||||
import static org.texttechnologylab.project.gruppe_05_1.export.TeXUtil.*;
|
||||
|
||||
/**
|
||||
* Controller für die Endpunkte zum Export von Reden als PDF.
|
||||
* Implementiert von Jonas
|
||||
*/
|
||||
public class SpeechesLatexExportController {
|
||||
@OpenApi(
|
||||
summary = "Get a speech as a PDF",
|
||||
|
|
|
@ -16,6 +16,10 @@ import java.util.List;
|
|||
import static org.texttechnologylab.project.gruppe_05_1.export.XMLUtil.*;
|
||||
import static org.texttechnologylab.project.gruppe_05_1.export.TeXUtil.*;
|
||||
|
||||
/**
|
||||
* Controller für die Endpunkte zum Export von Reden als XML.
|
||||
* Implementiert von Jonas
|
||||
*/
|
||||
public class SpeechesXMLExportController {
|
||||
@OpenApi(
|
||||
summary = "Get a speech as XML",
|
||||
|
|
|
@ -4,6 +4,10 @@ import java.time.LocalTime;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import static org.texttechnologylab.project.gruppe_05_1.Main.DEBUG_LOGGING;
|
||||
|
||||
/**
|
||||
* Logger Klasse für die Ausgabe von Lognachrichten
|
||||
* Implementiert von Jonas
|
||||
*/
|
||||
public class Logger {
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
// info, warn, error with message and colors and datetime
|
||||
|
|
|
@ -415,6 +415,12 @@ public abstract class PPRUtils {
|
|||
return doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listet die Dateien im gegebenen Verzeichnis auf.
|
||||
* Implementiert von Jonas
|
||||
* @param directory Verzeichnis
|
||||
* @return Liste der Dateinamen
|
||||
*/
|
||||
public static ArrayList<String> listFilesInDirectory(String directory) {
|
||||
File folder = new File(directory);
|
||||
File[] files = folder.listFiles();
|
||||
|
@ -507,6 +513,12 @@ public abstract class PPRUtils {
|
|||
return newProtocols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listet die Fraktionen von einer Liste an Membern auf
|
||||
* Implementiert von Jonas
|
||||
* @param mdbList Liste der Mitglieder
|
||||
* @return Liste der Fraktionen
|
||||
*/
|
||||
public static ArrayList<String> listFractionsFromMembers(List<Parlamentarier> mdbList) {
|
||||
ArrayList<String> fractions = new ArrayList<>();
|
||||
for (Parlamentarier parlamentarier : mdbList) {
|
||||
|
@ -523,6 +535,13 @@ public abstract class PPRUtils {
|
|||
return fractions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetched das Bild eines Mitglieds aus der Bundestagsdatenbank und gibt es als Base64-String zurück
|
||||
* Implementiert von Jonas
|
||||
* @param inputString Name des Mitglieds
|
||||
* @return Base64-String des Bildes
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String fetchMemberImageBase64FromNameString(String inputString) throws IOException {
|
||||
// Step 1: Send POST request
|
||||
String urlString = "https://bilddatenbank.bundestag.de/ajax/picture-result";
|
||||
|
@ -579,6 +598,12 @@ public abstract class PPRUtils {
|
|||
return "Error: Unable to retrieve image";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Session-Cookies zurück, die für die Requests der Bildersuche benötigt werden
|
||||
* Implementiert von Jonas
|
||||
* @return Session-Cookies
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getSessionCookies() throws IOException {
|
||||
String urlString = "https://bilddatenbank.bundestag.de/search/picture-result?query=Angela+Merkel&sortVal=2";
|
||||
URL url = new URL(urlString);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue