From 9c1ae91afedc8cd4de235389163a2678f89751f6 Mon Sep 17 00:00:00 2001 From: vysitor Date: Fri, 28 Feb 2025 18:40:12 +0100 Subject: [PATCH] Initial Commit --- pom.xml | 154 ++++++++ src/.DS_Store | Bin 0 -> 6148 bytes src/main/.DS_Store | Bin 0 -> 6148 bytes src/main/java/.DS_Store | Bin 0 -> 6148 bytes .../project/gruppe_05_1/Main.java | 117 ++++++ .../gruppe_05_1/database/MongoDBHandler.java | 365 ++++++++++++++++++ .../database/MongoObjectFactory.java | 65 ++++ .../gruppe_05_1/database/MongoOperations.java | 12 + .../gruppe_05_1/database/MongoPprUtils.java | 254 ++++++++++++ .../mdb/BiografischeAngaben_Mongo_Impl.java | 41 ++ .../mdb/Institution_Mongo_Impl.java | 37 ++ .../domainimpl/mdb/MdbName_Mongo_Impl.java | 37 ++ .../domainimpl/mdb/Mdb_Mongo_Impl.java | 50 +++ .../domainimpl/mdb/Membership_Mongo_Impl.java | 40 ++ .../domainimpl/mdb/Speaker_Mongo_Impl.java | 51 +++ .../mdb/Wahlperiode_Mongo_Impl.java | 47 +++ .../project/gruppe_05_1/domain/Gender.java | 24 ++ .../domain/html/Parlamentarier.java | 65 ++++ .../domain/html/ParlamentarierDetails.java | 219 +++++++++++ .../domain/mdb/BiografischeAngaben.java | 140 +++++++ .../gruppe_05_1/domain/mdb/Institution.java | 98 +++++ .../gruppe_05_1/domain/mdb/Mandatsart.java | 22 ++ .../project/gruppe_05_1/domain/mdb/Mdb.java | 68 ++++ .../gruppe_05_1/domain/mdb/MdbDocument.java | 48 +++ .../gruppe_05_1/domain/mdb/MdbName.java | 119 ++++++ .../gruppe_05_1/domain/mdb/Wahlperiode.java | 119 ++++++ .../domain/speaker/Membership.java | 87 +++++ .../gruppe_05_1/domain/speaker/Speaker.java | 198 ++++++++++ .../gruppe_05_1/domain/speech/Agenda.java | 55 +++ .../gruppe_05_1/domain/speech/Protocol.java | 100 +++++ .../gruppe_05_1/domain/speech/Speech.java | 86 +++++ .../domain/speech/TextContent.java | 65 ++++ .../project/gruppe_05_1/nlp/NlpUtils.java | 313 +++++++++++++++ .../gruppe_05_1/rest/JavalinConfig.java | 57 +++ .../rest/ParlamentarierController.java | 94 +++++ .../project/gruppe_05_1/rest/RESTHandler.java | 72 ++++ .../project/gruppe_05_1/util/FileUtils.java | 134 +++++++ .../gruppe_05_1/util/GeneralUtils.java | 89 +++++ .../project/gruppe_05_1/util/PPRUtils.java | 357 +++++++++++++++++ .../gruppe_05_1/util/PropertiesUtils.java | 24 ++ .../project/gruppe_05_1/util/XmlUtils.java | 252 ++++++++++++ .../website/templates/memberships.ftl | 23 ++ .../website/templates/parlamentarier.ftl | 54 +++ .../templates/parlamentarierAttribut.ftl | 6 + .../templates/parlamentarierDetails.ftl | 101 +++++ .../website/templates/persoenlicheDaten.ftl | 64 +++ .../gruppe_05_1/xml/FileObjectFactory.java | 63 +++ .../gruppe_05_1/xml/XmlOperations.java | 8 + .../mdb/BiografischeAngaben_File_Impl.java | 74 ++++ .../xml/mdb/Institution_File_Impl.java | 58 +++ .../xml/mdb/MdbDocument_File_Impl.java | 30 ++ .../xml/mdb/MdbName_File_Impl.java | 66 ++++ .../gruppe_05_1/xml/mdb/Mdb_File_Impl.java | 44 +++ .../xml/mdb/Wahlperiode_File_Impl.java | 82 ++++ .../xml/speaker/Speaker_File_Impl.java | 89 +++++ src/main/resources/.DS_Store | Bin 0 -> 6148 bytes src/main/resources/javalin.properties | 1 + src/main/resources/mongoDB.properties | 7 + src/main/resources/mongoDB_Uebung2.properties | 7 + .../plenarprotokolle/dbtplenarprotokoll.dtd | 298 ++++++++++++++ src/main/resources/public/index.html | 9 + src/main/resources/xml.properties | 7 + 62 files changed, 5266 insertions(+) create mode 100644 pom.xml create mode 100644 src/.DS_Store create mode 100644 src/main/.DS_Store create mode 100644 src/main/java/.DS_Store create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/Main.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/BiografischeAngaben_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Institution_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/MdbName_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Mdb_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Membership_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Speaker_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Wahlperiode_Mongo_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/Gender.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/Parlamentarier.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/ParlamentarierDetails.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/BiografischeAngaben.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Institution.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mandatsart.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mdb.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbDocument.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbName.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Wahlperiode.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Membership.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Speaker.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Agenda.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Protocol.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Speech.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/TextContent.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/nlp/NlpUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/JavalinConfig.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/ParlamentarierController.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/RESTHandler.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/util/FileUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/util/GeneralUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PPRUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PropertiesUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/util/XmlUtils.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/memberships.ftl create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarier.ftl create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierAttribut.ftl create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierDetails.ftl create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/persoenlicheDaten.ftl create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/FileObjectFactory.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/XmlOperations.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/BiografischeAngaben_File_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Institution_File_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbDocument_File_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbName_File_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Mdb_File_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Wahlperiode_File_Impl.java create mode 100644 src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/speaker/Speaker_File_Impl.java create mode 100644 src/main/resources/.DS_Store create mode 100644 src/main/resources/javalin.properties create mode 100644 src/main/resources/mongoDB.properties create mode 100644 src/main/resources/mongoDB_Uebung2.properties create mode 100644 src/main/resources/plenarprotokolle/dbtplenarprotokoll.dtd create mode 100644 src/main/resources/public/index.html create mode 100644 src/main/resources/xml.properties diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a92556e --- /dev/null +++ b/pom.xml @@ -0,0 +1,154 @@ + + + 4.0.0 + + org.texttechnologylab.project.gruppe_05_1 + MultimodalParliamentExplorer + 1.0 + + + 17 + 17 + UTF-8 + + 6.3.0 + + 1.4 + 3.0.3 + + + + + + central + Maven Plugin Repository + https://repo1.maven.org/maven2 + + + jitpack.io + https://jitpack.io + + + + + + + + + io.javalin + javalin + ${javalin.version} + + + + io.javalin + javalin-rendering + ${javalin.version} + + + + io.javalin.community.openapi + javalin-openapi-plugin + ${javalin.version} + + + + io.javalin.community.openapi + javalin-redoc-plugin + ${javalin.version} + + + + org.freemarker + freemarker + 2.3.33 + + + + + org.mongodb + mongodb-driver-sync + 5.2.1 + + + + + org.apache.poi + poi + 5.2.0 + + + org.apache.poi + poi-ooxml + 5.2.0 + + + + + org.json + json + 20240303 + + + + org.slf4j + slf4j-simple + 2.0.16 + + + + com.github.texttechnologylab + UIMATypeSystem + ${typesystem.version} + + + + + com.github.texttechnologylab + DockerUnifiedUIMAInterface + ${duui.version} + + + org.eclipse.jetty.websocket + jetty-websocket-api + + + org.eclipse.jetty.websocket + jetty-websocket-server + + + + + + org.dkpro.core + dkpro-core-io-xmi-asl + 2.4.0 + + + + + + src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 17 + 17 + + + io.javalin.community.openapi + openapi-annotation-processor + ${javalin.version} + + + + + + + + diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7cbb9350a57ec1469c8047c4081470492225b483 GIT binary patch literal 6148 zcmeHKK~BR!475v-BK1;n;4huGjSuh_#0U5iSH|{&5=G_6 z0mhPdvbHCi%ps0NL|2d7rN}}=YPg|1+cGuFn@?<3A{9{W9=qG+`lf65lgh&Z<5tqj zwcN|Yh(G(d9Ol}tX*RoVgIN9YG=DvLdp{rNw?F3hcY|j;J_D6T1*iZOpaN9jUn+o} zZC1|%xl#ctKn1=PuB-*`7%`z!%W769ggeIOz*4Jt6GT1E^F zI^wC+<$`@+&_(@Z+^3wZWkOLu9r5JlqB)Q&6`%rR1&(67u>OAmKQRA~N!(EZD)6Ti z(5hKCE4)(at&^9tUYp=o@GnEHmt*l(4D?ovjkV&_L0z(IXhxcS>-l)sZ!M39h}>{9>l1Z}D1$O49SkkPe%6L0YGJ42dn~T{qiMNZ zH6qRMUm4)DOKDDHx}|Y+e#yf}-M1`@VzMYFux0N@cTdMJuY=e>`_;d?uDu&+cttw2 zrc1h^k~Wx4c^>V624`5IC91xc``+`{iR`5{@@H4)>$lI{k5eu6b1IBX7@ z#ehqTQ8C0LX>Dyh9M@V8y@0ZCTqU?o!6cMo#BwR_L4&~Vc>>H8D?wNw_9GBzu)!Gk HQwF{PY~fF| literal 0 HcmV?d00001 diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f1ac8ac2ee0489b828c3923f4b30172b71962d9d GIT binary patch literal 6148 zcmeHKF-`+P47AA=C()d!DEABb!4e&Pq-Ka+;mGs>bK_U`Qq?$HO#Jl$nNe2yH<11XjFg-Pys4H1^%@H z=-FoVc_2qBKn1A4hXVG0NN~ekun+WK2L`|91MM2`hPl5bfXM>DT(A#B1g1d+235-w zLxYZZDs{PF9~g8|KNZNQt7RukF#Ez;5YE2q1MYWcq;~aE5^cF@#UZ{*&O*?un%-P;!X$hB4E1E JsK9S1@D65dC|v*m literal 0 HcmV?d00001 diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/Main.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/Main.java new file mode 100644 index 0000000..a59ed69 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/Main.java @@ -0,0 +1,117 @@ +package org.texttechnologylab.project.gruppe_05_1; + + +import com.mongodb.client.MongoDatabase; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoObjectFactory; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Mdb; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbDocument; +import org.texttechnologylab.project.gruppe_05_1.rest.RESTHandler; +import org.texttechnologylab.project.gruppe_05_1.util.PPRUtils; +import org.texttechnologylab.project.gruppe_05_1.util.PropertiesUtils; +import org.texttechnologylab.project.gruppe_05_1.util.XmlUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.FileObjectFactory; +import org.w3c.dom.Element; + +import java.util.List; +import java.util.Properties; + +/* +import com.mongodb.client.*; +import org.bson.Document; + +import org.texttechnologylab.project.Schelp_Valentin.database.MongoDBHandler; +import org.texttechnologylab.project.Schelp_Valentin.database.MongoObjectFactory; +import org.texttechnologylab.project.Schelp_Valentin.domain.mdb.MdbDocument; +import org.texttechnologylab.project.Schelp_Valentin.domain.mdb.Mdb; +import org.texttechnologylab.project.Schelp_Valentin.domain.reden.PlenarProtokoll; +import org.texttechnologylab.project.Schelp_Valentin.html.HtmlGenerationUtils; +import org.texttechnologylab.project.Schelp_Valentin.html.SortPossibilities; +import org.texttechnologylab.project.Schelp_Valentin.util.FileUtils; +import org.texttechnologylab.project.Schelp_Valentin.util.PPRUtils; +import org.texttechnologylab.project.Schelp_Valentin.util.PropertiesUtils; +import org.texttechnologylab.project.Schelp_Valentin.util.XmlUtils; +import org.texttechnologylab.project.Schelp_Valentin.xml.FileObjectFactory; +import org.texttechnologylab.project.Schelp_Valentin.xml.reden.PlenarProtokoll_File_Impl; +import org.w3c.dom.Element; + +import java.util.*; +import java.util.stream.Collectors; + */ +public class Main { + + public static final String RESOURCES_DIR="src/main/resources/"; + + private static final FileObjectFactory xmlFactory = FileObjectFactory.getFactory(); + private static final MongoObjectFactory mongoFactory = MongoObjectFactory.getFactory(); + + public static void main(String[] args) { + + // Stellt fest, dass alle nötigen Datenbank-Collections existieren + PPRUtils.ensureCollectionExist(); + + // Alle Informationen (Parlamentarier, Reden, Kommentare etc.) lesen und in die Mongo-DB einfügen, falls diese noch nicht vorhanden sind. + PPRUtils.parlamentExplorerInit(xmlFactory, mongoFactory); + + // NLP-Verarbeitung - TODO + RESTHandler restHandler = new RESTHandler(); + restHandler.startJavalin(); + + } + + + /* Auskommentiert aber nicht gelöscht, damit meine Methodik/Anwendung nachvollzogen werden kann + + + public static void main(String[] args) { + + + + + + // Plenarprotokolle lesen und in die MongoDB schreiben + Set protokollFileNames = FileUtils.listFilesInDirectory(PROTOKOLLE_DIRNAME) + .stream() + .filter(file -> file.endsWith(".xml")) + .collect(Collectors.toSet()); + ; + + String collectionName = "speeches"; + // MongoDBHandler.createCollectionIfNotExist(database, collectionName); + MongoDBHandler.createOrTrancateCollection(database, collectionName); + MongoCollection collection = database.getCollection(collectionName); + for (String filename : protokollFileNames) { + // for (String filename : Arrays.asList("1.XML", "2.XML")) { // für Testzwecke,,, + System.out.println("Plenarprotokoll wird aus " + filename + " gelesen"); + Element redenRoot = XmlUtils.getRootDocument("src/main/resources/plenarprotokolle/" + filename); + PlenarProtokoll redenDoc = new PlenarProtokoll_File_Impl().fromXmlNode(redenRoot); + MongoDBHandler.createPlenarprotokoll(collection, redenDoc); + } + + + // wichtige Datenstrukturen erzeugen: Listen, Zuordnungen + Map> pareiMdbZuordnung = PPRUtils.createMdbParteiZuordnung(mdbList); + + + // HTML-Generierung + // Vorbereitung + HtmlGenerationUtils.prepareHtmlGeneration(); + + // index.html + + /* + * Hier wird bestimmt, wie die index.html-Seite aufgebaut wird, je nach verwendete Enum aus SortPossibilities: + * - MDB_ALPHABETISCH: parteiübergreifend alphabetisch sortiert + * - nach Partei gruppiert, innerhalb der Partei alphabetisch sortiert: + * - PARTEI_MDB_ALPHABETISCH: die Parteien erscheinen in alphabetischen Reihenfolge + * - PARTEI_NACH_GROESSE: die Parteien erscheinen nach Anzahl ihrer dBs sortiert + * TODO: CLOSE COMMENT + HtmlGenerationUtils.generateIndexHtml(mdbList, pareiMdbZuordnung, SortPossibilities.MDB_ALPHABETISCH); + + HtmlGenerationUtils.generateMdbPages(mdbList); + +} + */ + +} + diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java new file mode 100644 index 0000000..5cb60f1 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java @@ -0,0 +1,365 @@ +package org.texttechnologylab.project.gruppe_05_1.database; + +import com.mongodb.MongoClientSettings; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Updates; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.bson.types.ObjectId; +import org.texttechnologylab.project.gruppe_05_1.util.PropertiesUtils; + +import java.util.*; + +import static com.mongodb.client.model.Filters.eq; + +public class MongoDBHandler { + + public static final String propertiesFileName = "mongoDB.properties"; + + private static MongoDatabase mongoDatabase = null; + + public final static Class DOC_LIST_CLASS = new ArrayList().getClass(); + + private static String localServer; // z.B mongodb://localhost:27017 + private static String remoteServer; + private static String user; + private static String password; + private static String port; + private static String collection; + private static String databaseName; + + /** + * Get the MongoDB according to properties. + * If a local server URI is defined, use it. Otherwise, use remote server. + * @return MongoDatabase + */ + static public MongoDatabase getMongoDatabase() { + + if (mongoDatabase == null) { + Properties mongoProperties = PropertiesUtils.readPropertiesFromResource(propertiesFileName); + // Zugangsdaten + localServer = mongoProperties.getProperty("localserver"); + remoteServer = mongoProperties.getProperty("remote_host"); + user = mongoProperties.getProperty("remote_user"); + password = mongoProperties.getProperty("remote_password"); + port = mongoProperties.getProperty("remote_port"); + collection = mongoProperties.getProperty("remote_collection"); + databaseName = mongoProperties.getProperty("remote_database"); + } + + // MongoDBClient erzeugen + // String uri = mongoServer + "://" + mongoUser + ":" + mongoPassword + "@" + mongoNeetwork; // cluster, network, user... + + // URI für lokale Datenbank oder für eine Datenbank auf dem Server + String uri; + if ( (localServer != null) && (! localServer.isBlank())) { + uri = localServer; + MongoClient mongoClient = MongoClients.create(uri); + + // Connect + MongoDatabase mongoDatabase = mongoClient.getDatabase(databaseName); + + return mongoDatabase; + } else { + MongoCredential credential = MongoCredential.createCredential(user, databaseName, password.toCharArray()); + + // Build MongoClientSettings + MongoClientSettings settings = MongoClientSettings.builder() + .applyToClusterSettings(builder -> + builder.hosts(Collections.singletonList(new ServerAddress(remoteServer, + Integer.parseInt(port))))) + .credential(credential) + .build(); + + // Create MongoClient + MongoClient mongoClient = MongoClients.create(settings); + mongoDatabase = mongoClient.getDatabase(databaseName); + } + + return mongoDatabase; + } + + /* + * Collection Operations + * ===================== + */ + + /** + * + * @return List with the names of all collections + */ + static public Set getCollectionNames() { + // return getMongoDatabase().listCollectionNames().into(new ArrayList<>()); + return getMongoDatabase().listCollectionNames().into(new HashSet<>()); + } + + /** + * + * @param name Name of collection to check for existance + * @return does the collection exist + */ + static public boolean collectionExists(String name) { + return getMongoDatabase().listCollectionNames().into(new ArrayList<>()).contains(name); + } + + + /** + * Tries to create a collection. If the collection exists and contains documents, throw an exception + * @param database + * @param collectionName + */ + + static public void createCollectionIfNotExist(MongoDatabase database, String collectionName) { + if (collectionName.isBlank()) { + throw new IllegalArgumentException("Collection name for MongoDB may not be blank"); + } else { + MongoCollection collection = database.getCollection(collectionName); + if (collection.countDocuments() > 0) { + throw new IllegalArgumentException("Collection '" + collectionName + "' is not empty"); + } else { + database.createCollection(collectionName); + } + + } + } + + static public void createCollectionIfNotExist(String collectionName) { + createCollectionIfNotExist(getMongoDatabase(), collectionName); + } + + + /** + * Create Collection + * @param database + * @param collectionName + */ + static public void createCollection(MongoDatabase database, String collectionName) { + if (collectionName.isBlank()) { + throw new IllegalArgumentException("Collection name for MongoDB may not be blank"); + } else { + database.createCollection(collectionName); + } + } + + static public void createCollection(String collectionName) { + createCollection(getMongoDatabase(), collectionName); + } + + + /** + * Creates a collection. If the collection exists already, delete all its document + * @param database + * @param collectionName + */ + static public void createOrTrancateCollection(MongoDatabase database, String collectionName) { + if (collectionName.isBlank()) { + throw new IllegalArgumentException("Collection name for MongoDB may not be blank"); + } else { + MongoCollection collection = database.getCollection(collectionName); + if (collection.countDocuments() > 0) { + collection.drop(); + } + database.createCollection(collectionName); + } + } + + static public void createOrTrancateCollection(String collectionName) { + createOrTrancateCollection(getMongoDatabase(), collectionName); + } + + /** + * Does a document with a given ID (for the "_id"-field) exists in a given collection? + * @param collection + * @param id + * @return + */ + static public boolean existsDocument(MongoCollection collection, String id) { + ObjectId idToFind = new ObjectId(id); + Document foundDocument = collection.find(new Document("_id", idToFind)).first(); + return (foundDocument != null); + } + + + /** + * Find a document with a given ID (for the "_id"-field) in a given collection + * @param collection + * @param id + * @return the document (null if not found) + */ + static public Document findDocumentByIdInCollection(MongoCollection collection, String id) { + ObjectId idToFind = new ObjectId(id); + Document foundDocument = collection.find(new Document("_id", idToFind)).first(); + return foundDocument; + } + + /** + * + * @param collection + * @return count of documents in the collection + */ + static public long size(MongoCollection collection) { + if (null == collection) { + throw new IllegalArgumentException("Collection may not be null"); + } else { + return collection.countDocuments(); + } + } + + + /** + * + * @param database + * @param collectionName + * @return count of documents in the collection + */ + static public long size(MongoDatabase database, String collectionName) { + if (collectionName.isBlank()) { + throw new IllegalArgumentException("Collection name for MongoDB may not be blank"); + } else { + return database.getCollection(collectionName).countDocuments(); + } + } + + /** + * + * @param database + * @param collectionName + */ + static public void dropCollection(MongoDatabase database, String collectionName) { + if (collectionName.isBlank()) { + throw new IllegalArgumentException("Collection name for MongoDB may not be blank"); + } else { + database.getCollection(collectionName).drop(); + } + } + + + /* + * Document Operations + * =================== + */ + + /** + * Creates a BSON document containing only simple fields according to fields given in a map + * @param attributes + * @return + */ + static public Document createDocument(boolean createIdField, Map attributes) { + Document doc = new Document(); + + if (createIdField) { + doc.append("_id", new ObjectId()); + } + + for (Map.Entry entry : attributes.entrySet()) { + doc.append(entry.getKey(), entry.getValue()); + } + return doc; + } + + /** + * Creates a BSON document containing simple fields (attributes) as well as other (possibly nested) objects + * @param attributes the simple fields + * @param fields the (possibly nested) objects + * @return + */ + static public Document createDocument(boolean createIdField, Map attributes, Map fields) { + Document doc = new Document(); + + if (createIdField) { + doc.append("_id", new ObjectId()); + } + + if ( ! attributes.isEmpty()) { + Map attributesMap = new HashMap<>(); + for (Map.Entry entry : attributes.entrySet()) { + attributesMap.put(entry.getKey(), entry.getValue()); + } + Document attributeChild = createDocument(createIdField, attributesMap); + doc.append("attributes", attributeChild); + } + + for (Map.Entry entry : fields.entrySet()) { + doc.append(entry.getKey(), entry.getValue()); + } + return doc; + } + + /* + * Weitere CRUD Operations + * ======================= + */ + + + /** + * + * @param collection + * @param doc + * @return + */ + static public void insertDocument(MongoCollection collection, Document doc) { + collection.insertOne(doc); + } + + /** + * + * @param collection + * @param docs + * @return + */ + static public void insertDocuments(MongoCollection collection, List docs) { + collection.insertMany(docs); + } + + /** + * + * @param collection + * @param fieldName + * @param fieldValue + * @return + */ + static public Document findFirstDocumentInCollection(MongoCollection collection, String fieldName, String fieldValue) { + return collection.find(eq(fieldName, fieldValue)).first(); + } + + + /** + * Searches a document and performs an update on it + * The document to update must be matched by name and value of a certain field + * @param collection + * @param searchCriteriaName search criteria: name of the field + * @param searchCriteriaValue search criteria: value of the field + * @param newOrUpdatedFieldName name of new field + * @param newOrUpdatedFieldValue value of new field + */ + static public void updateDocument(MongoCollection collection, + String searchCriteriaName, String searchCriteriaValue, + String newOrUpdatedFieldName, Object newOrUpdatedFieldValue){ + + Document updateQuery = new Document().append(searchCriteriaName, searchCriteriaValue); + + Bson updates = Updates.combine( + Updates.addToSet(newOrUpdatedFieldName, newOrUpdatedFieldValue)); + + collection.updateOne(updateQuery, updates); + } + + + /** + * + * @param collection + * @param searchCriteriaName search criteria: name of the field + * @param searchCriteriaValue search criteria: value of the field + */ + static public void deleteOneDocument(MongoCollection collection, String searchCriteriaName, String searchCriteriaValue) { + Bson deleteQuery = eq(searchCriteriaName, searchCriteriaValue); + + collection.deleteOne(deleteQuery); + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java new file mode 100644 index 0000000..9a45a4f --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java @@ -0,0 +1,65 @@ +package org.texttechnologylab.project.gruppe_05_1.database; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb.*; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.*; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker; + +import java.util.List; + +public class MongoObjectFactory { + + private static MongoObjectFactory factory = null; + + /** + * + * @return MongoObjectFactory + */ + public static MongoObjectFactory getFactory() { + if (factory == null) { + factory = new MongoObjectFactory(); + } + return factory; + } + + /* + * *** MDB Strukturen *** + * ===================== + */ + public Document createBiografischeAngaben(BiografischeAngaben entity) { + return new BiografischeAngaben_Mongo_Impl().createEntity(entity); + } + + public Document createInstitution(Institution entity) { + return new Institution_Mongo_Impl().createEntity(entity); + } + + public Document createMdb(Mdb entity) { + return new Mdb_Mongo_Impl().createEntity(entity); + } + + public Document createMdbName(MdbName entity) { + return new MdbName_Mongo_Impl().createEntity(entity); + } + + public Document createWahlperiode(Wahlperiode entity) { + return new Wahlperiode_Mongo_Impl().createEntity(entity); + } + + /* + * *** Speaker Strukturen *** + * ======================== + */ + public Document createSpeaker(Speaker entity) { + return new Speaker_Mongo_Impl().createEntity(entity); + } + + public Document createMembership(Membership entity) { + return new Membership_Mongo_Impl().createEntity(entity); + } + + public List createMemberships(List list) { + return new Membership_Mongo_Impl().createList(list); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java new file mode 100644 index 0000000..e6d2f7a --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java @@ -0,0 +1,12 @@ +package org.texttechnologylab.project.gruppe_05_1.database; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.xml.FileObjectFactory; + +import java.util.List; + +public interface MongoOperations { + MongoObjectFactory factory = MongoObjectFactory.getFactory(); + public Document createEntity(T entity); + public List createList(List list); +} 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 new file mode 100644 index 0000000..a49dc55 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java @@ -0,0 +1,254 @@ +package org.texttechnologylab.project.gruppe_05_1.database; + +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import org.bson.Document; +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.Speech; +import org.texttechnologylab.project.gruppe_05_1.util.PPRUtils; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Diese Klasse beinhaltet Mongo-Utilities, welche spezifisch für die PPR-Datenstrukturen sind. + * + * Mongo-Utilities genereller Natur stehen in der Klasse MongoDBHandler. + */ +public class MongoPprUtils { + + /* + * Collection-Information und-zugang + * ======================================================================= + */ + public static final String SPEAKER_COLLECTION_NAME = "speaker"; + public static final String SPEECH_COLLECTION_NAME = "speech"; + public static final String PICTURES_COLLECTION_NAME = "pictures"; + public static final String COMMENT_COLLECTION_NAME = "comment"; + + private static MongoCollection speakerCollecion = null; + private static MongoCollection speechCollecion = null; + private static MongoCollection picturesCollecion = null; + private static MongoCollection commentCollecion = null; + + public static MongoCollection getSpeakerCollection() { + if (speakerCollecion == null) speakerCollecion = MongoDBHandler.getMongoDatabase().getCollection(SPEAKER_COLLECTION_NAME); + return speakerCollecion; + } + + public static MongoCollection getSpeechCollection() { + if (speechCollecion == null) speechCollecion = MongoDBHandler.getMongoDatabase().getCollection(SPEECH_COLLECTION_NAME); + return speechCollecion; + } + + public static MongoCollection getPicturesCollection() { + if (picturesCollecion == null) picturesCollecion = MongoDBHandler.getMongoDatabase().getCollection(PICTURES_COLLECTION_NAME); + return picturesCollecion; + } + + public static MongoCollection getCommentCollection() { + if (commentCollecion == null) commentCollecion = MongoDBHandler.getMongoDatabase().getCollection(COMMENT_COLLECTION_NAME); + return commentCollecion; + } + + /* + * Parlamentarier + * ======================================================================= + */ + + + /** + * Holt 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 + * @param filter (optional): Suchkriterium + * @return List + */ + public static List getAllParlamentarier(String filter) { + List plist = new ArrayList<>(); + + MongoCursor cursor; + + if (filter== null || filter.isBlank()) { + cursor = getSpeakerCollection().find().iterator(); + } else { + String pattern = ".*" + filter + ".*"; + Document searchDocument = new Document("$or", List.of( + new Document("name", new Document("$regex", pattern).append("$options", "i")), + new Document("firstName", new Document("$regex", pattern).append("$options", "i")), + new Document("party", new Document("$regex", pattern).append("$options", "i")), + new Document("_id", new Document("$regex", pattern).append("$options", "i")) + )); + cursor = getSpeakerCollection().find(searchDocument).cursor(); + } + + try { + while (cursor.hasNext()) { + Parlamentarier p = readParlamentarierFromSpeaker(cursor.next()); + plist.add(p); + } + } catch (Throwable t) { + System.err.println(t); + } finally { + cursor.close(); + } + + return plist; + } + + + /** + * Liest einen Parlamentarier von der MongoDB + * @param doc - MongoDB Dokument eines Parlamentariers + * @return Parlamentarier + */ + private static Parlamentarier readParlamentarierFromSpeaker(Document doc) { + Parlamentarier p = new Parlamentarier(); + + p.setId((String) doc.get("_id")); + p.setNachname((String) doc.get("name")); + p.setVorname((String) doc.get("firstName")); + String partei = (String) doc.get("party"); + if (partei == null) { + p.setPartei("(parteilos)"); + } else { + p.setPartei(partei); + } + + return p; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + // ParlamentarierDetails + + + /** + * Holt die Details eines Parlamentariers + * @param id Parlamentarier-ID (String) + * @return ParlamentarierDetails + */ + public static ParlamentarierDetails getParlamentarierDetailsByID(String id) { + Document doc = MongoDBHandler.findFirstDocumentInCollection(getSpeakerCollection(), "_id", id); + ParlamentarierDetails p = readParlamentarierDetailsFromSpeaker(doc); + return p; + } + + + /** + * Holt die Details eines Parlamentariers + * @param id Parlamentarier-ID (Integer) + * @return ParlamentarierDetails + */ + public static ParlamentarierDetails getParlamentarierDetailsByID(Integer id) { + Document doc = MongoDBHandler.findFirstDocumentInCollection(getSpeakerCollection(), "_id", id.toString()); + ParlamentarierDetails p = readParlamentarierDetailsFromSpeaker(doc); + return p; + } + + /** + * Liest die Details eines Parlamentariers aus MongoDB, reiche diese mit Bildinformationen aus dem "pictures"-Collection, falls vorhanden, an + * @param doc - MongoDB Dokument eines Parlamentariers + * @return ParlamentarierDetails + */ + private static ParlamentarierDetails readParlamentarierDetailsFromSpeaker(Document doc) { + ParlamentarierDetails p = new ParlamentarierDetails(); + + String pid = (String) doc.get("_id"); + p.setId(pid); + p.setNachname((String) doc.get("name")); + p.setVorname((String) doc.get("firstName")); + String partei = (String) doc.get("party"); + if (partei == null) { + p.setPartei("(parteilos)"); + } else { + p.setPartei(partei); + } + p.setTitle((String) doc.get("title")); + p.setGeburtsort((String) doc.get("geburtsort")); + p.setGeschlecht((String) doc.get("geschlecht")); + p.setBeruf((String) doc.get("beruf")); + p.setAkademischertitel((String) doc.get("akademischertitel")); + p.setFamilienstand((String) doc.get("familienstand")); + p.setReligion((String) doc.get("religion")); + p.setVita((String) doc.get("vita")); + p.setPrimaryFoto((String) doc.get("primaryFoto")); + + Date geburtsdatum = (Date) doc.get("geburtsdatum"); + if (geburtsdatum != null) { + p.setGeburtsdatum(LocalDate.ofInstant(geburtsdatum.toInstant(), ZoneId.systemDefault())); + } + Date sterbedatum = (Date) doc.get("sterbedatum"); + if (sterbedatum != null) { + p.setSterbedatum(LocalDate.ofInstant(sterbedatum.toInstant(), ZoneId.systemDefault())); + } + + List membershipDocList = doc.get("memberships", MongoDBHandler.DOC_LIST_CLASS); + if (membershipDocList == null) { + p.setMemberships(new ArrayList<>()); + } else { + p.setMemberships(getMemberships(membershipDocList)); + } + + + /* - TODO + List reden = readSpeechesOfParlamentarier(pid); + PPRUtils.sortSpeechByDate(reden); + p.setReden(reden); + + */ + + return p; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + // ParlamentarierDetails - Memberships + + /** + * Liest die Memberships eines Parlamentariers + * @param doclist Liste von MongoDB-Dokumente für die Memberships + * @return List + */ + private static List getMemberships(List doclist) { + List memberships = new ArrayList<>(); + for (Document doc : doclist) { + memberships.add(getMembership(doc)); + } + return memberships; + } + + /** + * Liest eine Memberships + * @param doc MongoDB-Dokument für eine Membership + * @return Membership + */ + private static Membership getMembership(Document doc) { + Membership m = new Membership(); + + Date begin = (Date) doc.get("begin"); + if (begin != null) { + m.setBegin(LocalDate.ofInstant(begin.toInstant(), ZoneId.systemDefault())); + } + Date end = (Date) doc.get("end"); + if (end != null) { + m.setEnd(LocalDate.ofInstant(end.toInstant(), ZoneId.systemDefault())); + } + + m.setRole((String) doc.get("role")); + m.setMember((String) doc.get("member")); + m.setLabel((String) doc.get("label")); + m.setWp((Integer) doc.get("wp")); + + return m; + } + + // TODO: kopiere die Speech-Sachen von Übung 4 hierher! +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/BiografischeAngaben_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/BiografischeAngaben_Mongo_Impl.java new file mode 100644 index 0000000..5d47cb3 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/BiografischeAngaben_Mongo_Impl.java @@ -0,0 +1,41 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.BiografischeAngaben; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BiografischeAngaben_Mongo_Impl extends BiografischeAngaben implements MongoOperations { + @Override + public Document createEntity(BiografischeAngaben entity) { + Map fields = new HashMap<>(); + fields.put("geburtsdatum", GeneralUtils.formatDate(entity.getSterbedatum())); + fields.put("geburtsort", entity.getGeburtsort()); + fields.put("geburtsland", entity.getGeburtsland()); + fields.put("sterbedatum", GeneralUtils.formatDate(entity.getSterbedatum())); + fields.put("gender", entity.getGender()); + fields.put("maritalStatus", entity.getFamilienstand()); + fields.put("religion", entity.getReligion()); + fields.put("beruf", entity.getBeruf()); + fields.put("parteiKuerzel", entity.getParteiKuerzel()); + fields.put("vitaKurz", entity.getVitaKurz()); + fields.put("veroeffentlichungspflichtiges", entity.getVeroeffentlichungspflichtiges()); + Document doc = MongoDBHandler.createDocument(false, fields); + return doc; + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (BiografischeAngaben bio : list) { + result.add(createEntity(bio)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Institution_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Institution_Mongo_Impl.java new file mode 100644 index 0000000..6d5f245 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Institution_Mongo_Impl.java @@ -0,0 +1,37 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Institution; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Institution_Mongo_Impl extends Institution implements MongoOperations { + @Override + public Document createEntity(Institution entity) { + Map fields = new HashMap<>(); + fields.put("insartLang", entity.getInsartLang()); + fields.put("insLang", entity.getInsLang()); + fields.put("mdbinsVon", entity.getMdbinsVon()); + fields.put("mdbinsBis", entity.getMdbinsBis()); + fields.put("fktLang", entity.getFktLang()); + fields.put("fktinsVon", entity.getFktinsVon()); + fields.put("fktinsBis", entity.getFktinsBis()); + + Document doc = MongoDBHandler.createDocument(false, fields); + return doc; + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (Institution inst : list) { + result.add(createEntity(inst)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/MdbName_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/MdbName_Mongo_Impl.java new file mode 100644 index 0000000..4b7e4be --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/MdbName_Mongo_Impl.java @@ -0,0 +1,37 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbName; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MdbName_Mongo_Impl extends MdbName implements MongoOperations { + @Override + public Document createEntity(MdbName entity) { + Map fields = new HashMap<>(); + fields.put("nachname", entity.getNachname()); + fields.put("vorname", entity.getVorname()); + fields.put("ortszusatz", entity.getOrtszusatz()); + fields.put("adel", entity.getAdel()); + fields.put("praefix", entity.getPraefix()); + fields.put("andereTitel", entity.getAndereTitel()); + fields.put("akadTitel", entity.getAkadTitel()); + fields.put("historieVon", entity.getHistorieVon()); + fields.put("historieBis", entity.getHistorieBis()); + return MongoDBHandler.createDocument(false, fields); + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (MdbName mdbName : list) { + result.add(createEntity(mdbName)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Mdb_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Mdb_Mongo_Impl.java new file mode 100644 index 0000000..7203320 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Mdb_Mongo_Impl.java @@ -0,0 +1,50 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Mdb; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbName; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Wahlperiode; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class Mdb_Mongo_Impl extends Mdb implements MongoOperations { + @Override + public Document createEntity(Mdb entity) { + Document bioDoc = factory.createBiografischeAngaben(entity.getBio()); + + List namen= entity.getNamen(); + List namenDocs = new ArrayList<>(); + for (MdbName mdbName : namen) { + namenDocs.add(factory.createMdbName(mdbName)); + } + + List wps= entity.getWahlperioden(); + List wpDocs = new ArrayList<>(); + for (Wahlperiode wp : wps) { + wpDocs.add(factory.createWahlperiode(wp)); + } + + Map fields = Map.of( + "id", entity.getId(), + "namen", namenDocs, + "bio", bioDoc, + "wahlperioden", wpDocs + ); + Document doc = MongoDBHandler.createDocument(false, fields); + + return doc; + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (Mdb mdb : list) { + result.add(createEntity(mdb)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Membership_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Membership_Mongo_Impl.java new file mode 100644 index 0000000..8c6306f --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Membership_Mongo_Impl.java @@ -0,0 +1,40 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbName; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Wahlperiode; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Membership_Mongo_Impl extends Membership implements MongoOperations { + @Override + public Document createEntity(Membership entity) { + Map fields = new HashMap<>(); + + fields.put("begin", entity.getBegin()); + fields.put("end", entity.getEnd()); + fields.put("role", entity.getRole()); + fields.put("label", entity.getLabel()); + fields.put("member", entity.getMember()); // TODO: wahrscheinlich nicht nötig + + Document doc = MongoDBHandler.createDocument(false, fields); + + return doc; + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (Membership membership : list) { + result.add(createEntity(membership)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Speaker_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Speaker_Mongo_Impl.java new file mode 100644 index 0000000..a321599 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Speaker_Mongo_Impl.java @@ -0,0 +1,51 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Speaker_Mongo_Impl extends Speaker implements MongoOperations { + @Override + public Document createEntity(Speaker entity) { + + List memberships= entity.getMemberships(); + List membershipDocs = factory.createMemberships(memberships); + + Map fields = new HashMap<>(); + fields.put("_id", entity.getId()); + fields.put("name", entity.getName()); + fields.put("firstName", entity.getFirstName()); + fields.put("title", entity.getTitle()); + fields.put("geburtsdatum", entity.getGeburtsdatum()); + fields.put("geburtsort", entity.getGeburtsort()); + fields.put("sterbedatum", entity.getSterbedatum()); + fields.put("geschlecht", entity.getGeschlecht()); + fields.put("beruf", entity.getBeruf()); + fields.put("akademischertitel", entity.getAkademischertitel()); + fields.put("familienstand", entity.getFamilienstand()); + fields.put("religion", entity.getReligion()); + fields.put("vita", entity.getVita()); + fields.put("party", entity.getParty()); + fields.put("memberships", membershipDocs); + + Document doc = MongoDBHandler.createDocument(false, fields); + + return doc; + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (Speaker speaker : list) { + result.add(createEntity(speaker)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Wahlperiode_Mongo_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Wahlperiode_Mongo_Impl.java new file mode 100644 index 0000000..0f472a3 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/domainimpl/mdb/Wahlperiode_Mongo_Impl.java @@ -0,0 +1,47 @@ +package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb; + +import org.bson.Document; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Institution; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Wahlperiode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Wahlperiode_Mongo_Impl extends Wahlperiode implements MongoOperations { + @Override + public Document createEntity(Wahlperiode entity) { + + Map fields = new HashMap<>(); + fields.put("wp", entity.getWp()); + fields.put("mdbWpVon", entity.getMdbWpVon()); + fields.put("mdbWpBis", entity.getMdbWpBis()); + fields.put("wknNr", entity.getWknNr()); + fields.put("wkrName", entity.getWkrName()); + fields.put("wkrLand", entity.getWkrLand()); + fields.put("liste", entity.getListe()); + fields.put("mandatsart", entity.getMandatsart().name()); + + List institutionen = entity.getInstitutionen(); + List instDocs = new ArrayList<>(); + for (Institution inst : institutionen) { + instDocs.add(factory.createInstitution(inst)); + } + fields.put("institutionen", instDocs); + + Document doc = MongoDBHandler.createDocument(false, fields); + return doc; + } + + @Override + public List createList(List list) { + List result = new ArrayList<>(); + for (Wahlperiode wp : list) { + result.add(createEntity(wp)); + } + return result; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/Gender.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/Gender.java new file mode 100644 index 0000000..5053091 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/Gender.java @@ -0,0 +1,24 @@ +package org.texttechnologylab.project.gruppe_05_1.domain; + +public enum Gender { // TODO: Delete + + M("männlich"), + F("weiblich"), // nur diese beide Werte sind in der XML-Datei vorhanden! + NA("") // falls Daten nicht vorhanden + ; + + private final String text; + + public String getText() { + return this.text; + } + + private Gender(String text) {this.text = text;} + + public static Gender byText(String text) { + if (null == text) return NA; + if (text.equalsIgnoreCase(M.text)) return M; + if (text.equalsIgnoreCase(F.text)) return F; + return NA; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/Parlamentarier.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/Parlamentarier.java new file mode 100644 index 0000000..47828d7 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/Parlamentarier.java @@ -0,0 +1,65 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.html; + +import java.util.Objects; +import java.util.StringJoiner; + +public class Parlamentarier { + String id; + String vorname; + String nachname; + String partei; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVorname() { + return vorname; + } + + public void setVorname(String vorname) { + this.vorname = vorname; + } + + public String getNachname() { + return nachname; + } + + public void setNachname(String nachname) { + this.nachname = nachname; + } + + public String getPartei() { + return partei; + } + + public void setPartei(String partei) { + this.partei = partei; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Parlamentarier that)) return false; + return Objects.equals(id, that.id) && Objects.equals(vorname, that.vorname) && Objects.equals(nachname, that.nachname) && Objects.equals(partei, that.partei); + } + + @Override + public int hashCode() { + return Objects.hash(id, vorname, nachname, partei); + } + + @Override + public String toString() { + return new StringJoiner(", ", Parlamentarier.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("vorname='" + vorname + "'") + .add("nachname='" + nachname + "'") + .add("partei='" + partei + "'") + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/ParlamentarierDetails.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/ParlamentarierDetails.java new file mode 100644 index 0000000..119b8a1 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/html/ParlamentarierDetails.java @@ -0,0 +1,219 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.html; + +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership; +import org.texttechnologylab.project.gruppe_05_1.domain.speech.Speech; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; + +import java.time.LocalDate; +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public class ParlamentarierDetails { + String id; + String vorname; + String nachname; + String partei; + String title; + LocalDate geburtsdatum; + String geburtsort; + LocalDate sterbedatum; + String geschlecht; + String beruf; + String akademischertitel; + String familienstand; + String religion; + String vita; + String primaryFoto; // war nicht ursprünglich in der Datenbank, wurde hinzugefügt, um das primäres Bild zu speichern + String party; + + List memberships; + + List reden; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVorname() { + return vorname; + } + + public void setVorname(String vorname) { + this.vorname = vorname; + } + + public String getNachname() { + return nachname; + } + + public void setNachname(String nachname) { + this.nachname = nachname; + } + + public String getPartei() { + return partei; + } + + public void setPartei(String partei) { + this.partei = partei; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public LocalDate getGeburtsdatum() { + return geburtsdatum; + } + + public String getGeburtsdatumPP() { + if (geburtsdatum == null) return null; + return GeneralUtils.formatDate(geburtsdatum); + } + + public void setGeburtsdatum(LocalDate geburtsdatum) { + this.geburtsdatum = geburtsdatum; + } + + public String getGeburtsort() { + return geburtsort; + } + + public void setGeburtsort(String geburtsort) { + this.geburtsort = geburtsort; + } + + public LocalDate getSterbedatum() { + return sterbedatum; + } + + public void setSterbedatum(LocalDate sterbedatum) { + this.sterbedatum = sterbedatum; + } + + public String getGeschlecht() { + return geschlecht; + } + + public void setGeschlecht(String geschlecht) { + this.geschlecht = geschlecht; + } + + public String getBeruf() { + return beruf; + } + + public void setBeruf(String beruf) { + this.beruf = beruf; + } + + public String getAkademischertitel() { + return akademischertitel; + } + + public void setAkademischertitel(String akademischertitel) { + this.akademischertitel = akademischertitel; + } + + public String getFamilienstand() { + return familienstand; + } + + public void setFamilienstand(String familienstand) { + this.familienstand = familienstand; + } + + public String getReligion() { + return religion; + } + + public void setReligion(String religion) { + this.religion = religion; + } + + public String getVita() { + return vita; + } + + public void setVita(String vita) { + this.vita = vita; + } + + public String getParty() { + return party; + } + + public void setParty(String party) { + this.party = party; + } + + public String getPrimaryFoto() { + return primaryFoto; + } + + public void setPrimaryFoto(String primaryFoto) { + this.primaryFoto = primaryFoto; + } + + public List getMemberships() { + return memberships; + } + + public void setMemberships(List memberships) { + this.memberships = memberships; + } + + public List getReden() { + return reden; + } + + public void setReden(List reden) { + this.reden = reden; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ParlamentarierDetails)) return false; + ParlamentarierDetails that = (ParlamentarierDetails) o; + return Objects.equals(id, that.id) ; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return new StringJoiner(", ", ParlamentarierDetails.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("vorname='" + vorname + "'") + .add("nachname='" + nachname + "'") + .add("partei='" + partei + "'") + .add("title='" + title + "'") + .add("geburtsdatum=" + geburtsdatum) + .add("geburtsort='" + geburtsort + "'") + .add("sterbedatum=" + sterbedatum) + .add("geschlecht='" + geschlecht + "'") + .add("beruf='" + beruf + "'") + .add("akademischertitel='" + akademischertitel + "'") + .add("familienstand='" + familienstand + "'") + .add("religion='" + religion + "'") + .add("vita='" + vita + "'") + .add("primaryFoto='" + primaryFoto + "'") + .add("party='" + party + "'") + // .add("memberships=" + memberships) + .add("reden=" + reden) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/BiografischeAngaben.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/BiografischeAngaben.java new file mode 100644 index 0000000..6dec0ab --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/BiografischeAngaben.java @@ -0,0 +1,140 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +import java.time.LocalDate; +import java.util.Objects; +import java.util.StringJoiner; + +import org.texttechnologylab.project.gruppe_05_1.domain.Gender; + +public abstract class BiografischeAngaben { + + private LocalDate geburtsdatum; + private String geburtsort; + private String geburtsland; + private LocalDate sterbedatum; + private String gender; + private String familienstand; // String und kein Enum, weil über 60 Werte wie "alleinerziehend, 3 Kinder", "eheähnl. Lebensgemeinschaft, 3 Kinder", "verheiratet, 12 Kinder" vorkommen... + private String religion; + private String beruf; + private String parteiKuerzel; + private String vitaKurz; + private String veroeffentlichungspflichtiges; + + public LocalDate getGeburtsdatum() { + return geburtsdatum; + } + + public void setGeburtsdatum(LocalDate geburtsdatum) { + this.geburtsdatum = geburtsdatum; + } + + public String getGeburtsort() { + return geburtsort; + } + + public void setGeburtsort(String geburtsort) { + this.geburtsort = geburtsort; + } + + public String getGeburtsland() { + return geburtsland; + } + + public void setGeburtsland(String geburtsland) { + this.geburtsland = geburtsland; + } + + public LocalDate getSterbedatum() { + return sterbedatum; + } + + public void setSterbedatum(LocalDate sterbedatum) { + this.sterbedatum = sterbedatum; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getFamilienstand() { + return familienstand; + } + + public void setFamilienstand(String familienstand) { + this.familienstand = familienstand; + } + + public String getReligion() { + return religion; + } + + public void setReligion(String religion) { + this.religion = religion; + } + + public String getBeruf() { + return beruf; + } + + public void setBeruf(String beruf) { + this.beruf = beruf; + } + + public String getParteiKuerzel() { + return parteiKuerzel; + } + + public void setParteiKuerzel(String parteiKuerzel) { + this.parteiKuerzel = parteiKuerzel; + } + + public String getVitaKurz() { + return vitaKurz; + } + + public void setVitaKurz(String vitaKurz) { + this.vitaKurz = vitaKurz; + } + + public String getVeroeffentlichungspflichtiges() { + return veroeffentlichungspflichtiges; + } + + public void setVeroeffentlichungspflichtiges(String veroeffentlichungspflichtiges) { + this.veroeffentlichungspflichtiges = veroeffentlichungspflichtiges; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof BiografischeAngaben)) return false; + BiografischeAngaben that = (BiografischeAngaben) o; + return Objects.equals(geburtsdatum, that.geburtsdatum) && Objects.equals(geburtsort, that.geburtsort) && Objects.equals(geburtsland, that.geburtsland) && Objects.equals(sterbedatum, that.sterbedatum) && gender == that.gender && familienstand == that.familienstand && religion == that.religion && Objects.equals(beruf, that.beruf) && Objects.equals(parteiKuerzel, that.parteiKuerzel) && Objects.equals(vitaKurz, that.vitaKurz) && Objects.equals(veroeffentlichungspflichtiges, that.veroeffentlichungspflichtiges); + } + + @Override + public int hashCode() { + return Objects.hash(geburtsdatum, geburtsort, geburtsland, sterbedatum, gender, familienstand, religion, beruf, parteiKuerzel, vitaKurz, veroeffentlichungspflichtiges); + } + + @Override + public String toString() { + return new StringJoiner(", ", BiografischeAngaben.class.getSimpleName() + "[", "]") + .add("geburtsdatum=" + geburtsdatum) + .add("geburtsort='" + geburtsort + "'") + .add("geburtsland='" + geburtsland + "'") + .add("sterbedatum=" + sterbedatum) + .add("gender=" + gender) + .add("maritalStatus=" + familienstand) + .add("religion=" + religion) + .add("beruf='" + beruf + "'") + .add("parteiKuerzel='" + parteiKuerzel + "'") + .add("vitaKurz='" + vitaKurz + "'") + .add("veroeffentlichungspflichtiges='" + veroeffentlichungspflichtiges + "'") + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Institution.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Institution.java new file mode 100644 index 0000000..e988ed3 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Institution.java @@ -0,0 +1,98 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +import java.time.LocalDate; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Institution { + + private String insartLang; + private String insLang; + private LocalDate mdbinsVon; + private LocalDate mdbinsBis; + private String fktLang; + private LocalDate fktinsVon; + private LocalDate fktinsBis; + + public String getInsartLang() { + return insartLang; + } + + public void setInsartLang(String insartLang) { + this.insartLang = insartLang; + } + + public String getInsLang() { + return insLang; + } + + public void setInsLang(String insLang) { + this.insLang = insLang; + } + + public LocalDate getMdbinsVon() { + return mdbinsVon; + } + + public void setMdbinsVon(LocalDate mdbinsVon) { + this.mdbinsVon = mdbinsVon; + } + + public LocalDate getMdbinsBis() { + return mdbinsBis; + } + + public void setMdbinsBis(LocalDate mdbinsBis) { + this.mdbinsBis = mdbinsBis; + } + + public String getFktLang() { + return fktLang; + } + + public void setFktLang(String fktLang) { + this.fktLang = fktLang; + } + + public LocalDate getFktinsVon() { + return fktinsVon; + } + + public void setFktinsVon(LocalDate fktinsVon) { + this.fktinsVon = fktinsVon; + } + + public LocalDate getFktinsBis() { + return fktinsBis; + } + + public void setFktinsBis(LocalDate fktinsBis) { + this.fktinsBis = fktinsBis; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Institution)) return false; + Institution that = (Institution) o; + return Objects.equals(insartLang, that.insartLang) && Objects.equals(insLang, that.insLang) && Objects.equals(mdbinsVon, that.mdbinsVon) && Objects.equals(mdbinsBis, that.mdbinsBis) && Objects.equals(fktLang, that.fktLang) && Objects.equals(fktinsVon, that.fktinsVon) && Objects.equals(fktinsBis, that.fktinsBis); + } + + @Override + public int hashCode() { + return Objects.hash(insartLang, insLang, mdbinsVon, mdbinsBis, fktLang, fktinsVon, fktinsBis); + } + + @Override + public String toString() { + return new StringJoiner(", ", Institution.class.getSimpleName() + "[", "]") + .add("insartLang='" + insartLang + "'") + .add("insLang='" + insLang + "'") + .add("mdbinsVon=" + mdbinsVon) + .add("mdbinsBis=" + mdbinsBis) + .add("fktLang='" + fktLang + "'") + .add("fktinsVon=" + fktinsVon) + .add("fktinsBis=" + fktinsBis) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mandatsart.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mandatsart.java new file mode 100644 index 0000000..03bed1f --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mandatsart.java @@ -0,0 +1,22 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +public enum Mandatsart { + + DIREKT("Direktwahl"), + LANDESLISTE("Landesliste"), + VOLKSKAMMER("Volkskammer"), + NA("") // falls Daten nicht vorhanden + ; + + private final String text; + + private Mandatsart(String text) {this.text = text;} + + public static Mandatsart byText(String text) { + if (null == text) return NA; + if (text.equalsIgnoreCase(DIREKT.text)) return DIREKT; + if (text.equalsIgnoreCase(LANDESLISTE.text)) return LANDESLISTE; + if (text.equalsIgnoreCase(VOLKSKAMMER.text)) return VOLKSKAMMER; + return NA; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mdb.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mdb.java new file mode 100644 index 0000000..19b87f1 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Mdb.java @@ -0,0 +1,68 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Mdb { + + private String id; + private List namen; + private BiografischeAngaben bio; + private List wahlperioden; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public List getNamen() { + return namen; + } + + public void setNamen(List namen) { + this.namen = namen; + } + + public BiografischeAngaben getBio() { + return bio; + } + + public void setBio(BiografischeAngaben bio) { + this.bio = bio; + } + + public List getWahlperioden() { + return wahlperioden; + } + + public void setWahlperioden(List wahlperioden) { + this.wahlperioden = wahlperioden; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Mdb)) return false; + Mdb mdb = (Mdb) o; + return Objects.equals(id, mdb.id) && Objects.equals(namen, mdb.namen) && Objects.equals(bio, mdb.bio) && Objects.equals(wahlperioden, mdb.wahlperioden); + } + + @Override + public int hashCode() { + return Objects.hash(id, namen, bio, wahlperioden); + } + + @Override + public String toString() { + return new StringJoiner(", ", Mdb.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("namen=" + namen) + .add("bio=" + bio) + .add("wahlperioden=" + wahlperioden) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbDocument.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbDocument.java new file mode 100644 index 0000000..8542a8d --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbDocument.java @@ -0,0 +1,48 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class MdbDocument { + + private String version; + private List mdbs; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public List getMdbs() { + return mdbs; + } + + public void setMdbs(List mdbs) { + this.mdbs = mdbs; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof MdbDocument)) return false; + MdbDocument that = (MdbDocument) o; + return Objects.equals(version, that.version) && Objects.equals(mdbs, that.mdbs); + } + + @Override + public int hashCode() { + return Objects.hash(version, mdbs); + } + + @Override + public String toString() { + return new StringJoiner(", ", MdbDocument.class.getSimpleName() + "[", "]") + .add("version='" + version + "'") + .add("mdbs=" + mdbs) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbName.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbName.java new file mode 100644 index 0000000..3839933 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/MdbName.java @@ -0,0 +1,119 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +import java.time.LocalDate; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class MdbName { + + private String nachname; + private String vorname; + private String ortszusatz; + private String adel; + private String praefix; + private String andereTitel; + private String akadTitel; + + private LocalDate historieVon; + private LocalDate historieBis; + + public String getNachname() { + return nachname; + } + + public void setNachname(String nachname) { + this.nachname = nachname; + } + + public String getVorname() { + return vorname; + } + + public void setVorname(String vorname) { + this.vorname = vorname; + } + + public String getOrtszusatz() { + return ortszusatz; + } + + public void setOrtszusatz(String ortszusatz) { + this.ortszusatz = ortszusatz; + } + + public String getAdel() { + return adel; + } + + public void setAdel(String adel) { + this.adel = adel; + } + + public String getPraefix() { + return praefix; + } + + public void setPraefix(String praefix) { + this.praefix = praefix; + } + + public String getAndereTitel() { + return andereTitel; + } + + public void setAndereTitel(String andereTitel) { + this.andereTitel = andereTitel; + } + + public String getAkadTitel() { + return akadTitel; + } + + public void setAkadTitel(String akadTitel) { + this.akadTitel = akadTitel; + } + + public LocalDate getHistorieVon() { + return historieVon; + } + + public void setHistorieVon(LocalDate historieVon) { + this.historieVon = historieVon; + } + + public LocalDate getHistorieBis() { + return historieBis; + } + + public void setHistorieBis(LocalDate historieBis) { + this.historieBis = historieBis; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof MdbName)) return false; + MdbName name = (MdbName) o; + return Objects.equals(nachname, name.nachname) && Objects.equals(vorname, name.vorname) && Objects.equals(ortszusatz, name.ortszusatz) && Objects.equals(adel, name.adel) && Objects.equals(praefix, name.praefix) && Objects.equals(andereTitel, name.andereTitel) && Objects.equals(akadTitel, name.akadTitel) && Objects.equals(historieVon, name.historieVon) && Objects.equals(historieBis, name.historieBis); + } + + @Override + public int hashCode() { + return Objects.hash(nachname, vorname, ortszusatz, adel, praefix, andereTitel, akadTitel, historieVon, historieBis); + } + + @Override + public String toString() { + return new StringJoiner(", ", MdbName.class.getSimpleName() + "[", "]") + .add("nachname='" + nachname + "'") + .add("vorname='" + vorname + "'") + .add("ortszusatz='" + ortszusatz + "'") + .add("adel='" + adel + "'") + .add("praefix='" + praefix + "'") + .add("andereTitel='" + andereTitel + "'") + .add("akadTitel='" + akadTitel + "'") + .add("historieVon=" + historieVon) + .add("historieBis=" + historieBis) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Wahlperiode.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Wahlperiode.java new file mode 100644 index 0000000..c39addd --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/mdb/Wahlperiode.java @@ -0,0 +1,119 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.mdb; + +import java.time.LocalDate; +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Wahlperiode { + + private int wp; + private LocalDate mdbWpVon; + private LocalDate mdbWpBis; + private String wknNr; // String, nicht int, weil manchmal leer + private String wkrName; + private String wkrLand; + private String liste; + private Mandatsart mandatsart; + private List institutionen; + + public int getWp() { + return wp; + } + + public void setWp(int wp) { + this.wp = wp; + } + + public LocalDate getMdbWpVon() { + return mdbWpVon; + } + + public void setMdbWpVon(LocalDate mdbWpVon) { + this.mdbWpVon = mdbWpVon; + } + + public LocalDate getMdbWpBis() { + return mdbWpBis; + } + + public void setMdbWpBis(LocalDate mdbWpBis) { + this.mdbWpBis = mdbWpBis; + } + + public String getWknNr() { + return wknNr; + } + + public void setWknNr(String wknNr) { + this.wknNr = wknNr; + } + + public String getWkrName() { + return wkrName; + } + + public void setWkrName(String wkrName) { + this.wkrName = wkrName; + } + + public String getWkrLand() { + return wkrLand; + } + + public void setWkrLand(String wkrLand) { + this.wkrLand = wkrLand; + } + + public String getListe() { + return liste; + } + + public void setListe(String liste) { + this.liste = liste; + } + + public Mandatsart getMandatsart() { + return mandatsart; + } + + public void setMandatsart(Mandatsart mandatsart) { + this.mandatsart = mandatsart; + } + + public List getInstitutionen() { + return institutionen; + } + + public void setInstitutionen(List institutionen) { + this.institutionen = institutionen; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Wahlperiode)) return false; + Wahlperiode that = (Wahlperiode) o; + return wp == that.wp && wknNr == that.wknNr && Objects.equals(mdbWpVon, that.mdbWpVon) && Objects.equals(mdbWpBis, that.mdbWpBis) && Objects.equals(wkrName, that.wkrName) && Objects.equals(wkrLand, that.wkrLand) && Objects.equals(liste, that.liste) && mandatsart == that.mandatsart && Objects.equals(institutionen, that.institutionen); + } + + @Override + public int hashCode() { + return Objects.hash(wp, mdbWpVon, mdbWpBis, wknNr, wkrName, wkrLand, liste, mandatsart, institutionen); + } + + @Override + public String toString() { + return new StringJoiner(", ", Wahlperiode.class.getSimpleName() + "[", "]") + .add("wp=" + wp) + .add("mdbWpVon=" + mdbWpVon) + .add("mdbWpBis=" + mdbWpBis) + .add("wknNr=" + wknNr) + .add("wkrName='" + wkrName + "'") + .add("wkrLand='" + wkrLand + "'") + .add("liste='" + liste + "'") + .add("mandatsart=" + mandatsart) + .add("institutionen=" + institutionen) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Membership.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Membership.java new file mode 100644 index 0000000..e7bb3ba --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Membership.java @@ -0,0 +1,87 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.speaker; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.StringJoiner; + +public class Membership { + String role; + String member; // TODO: wozu? Dr. Abrami hat hier die ID des Parlamentariers gespeichert + LocalDate begin; // TODO: in Mongo eigentlich Date? + LocalDate end; // TODO: in Mongo eigentlich Date? + String label; + Integer wp; + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getMember() { + return member; + } + + public void setMember(String member) { + this.member = member; + } + + public LocalDate getBegin() { + return begin; + } + + public void setBegin(LocalDate begin) { + this.begin = begin; + } + + public LocalDate getEnd() { + return end; + } + + public void setEnd(LocalDate end) { + this.end = end; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Integer getWp() { + return wp; + } + + public void setWp(Integer wp) { + this.wp = wp; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Membership that)) return false; + return Objects.equals(role, that.role) && Objects.equals(member, that.member) && Objects.equals(begin, that.begin) && Objects.equals(end, that.end) && Objects.equals(label, that.label) && Objects.equals(wp, that.wp); + } + + @Override + public int hashCode() { + return Objects.hash(role, member, begin, end, label, wp); + } + + @Override + public String toString() { + return new StringJoiner(", ", Membership.class.getSimpleName() + "[", "]") + .add("role='" + role + "'") + .add("member='" + member + "'") + .add("begin=" + begin) + .add("end=" + end) + .add("label='" + label + "'") + .add("wp=" + wp) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Speaker.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Speaker.java new file mode 100644 index 0000000..c281111 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speaker/Speaker.java @@ -0,0 +1,198 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.speaker; + +import java.time.LocalDate; +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Speaker { + String id; + String name; + String firstName; + String title; + LocalDate geburtsdatum; // in Mongo eigentlich LocalDateTime, ziemlich sinnlos + String geburtsort; + LocalDate sterbedatum; // in Mongo eigentlich LocalDateTime, ziemlich sinnlos + String geschlecht; + String beruf; + String akademischertitel; + String familienstand; + String religion; + String vita; + String party; + String primaryFoto; + List memberships; + + // TODO: List speeches; + + // TODO: Photos + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public LocalDate getGeburtsdatum() { + return geburtsdatum; + } + + public void setGeburtsdatum(LocalDate geburtsdatum) { + this.geburtsdatum = geburtsdatum; + } + + public String getGeburtsort() { + return geburtsort; + } + + public void setGeburtsort(String geburtsort) { + this.geburtsort = geburtsort; + } + + public LocalDate getSterbedatum() { + return sterbedatum; + } + + public void setSterbedatum(LocalDate sterbedatum) { + this.sterbedatum = sterbedatum; + } + + public String getGeschlecht() { + return geschlecht; + } + + public void setGeschlecht(String geschlecht) { + this.geschlecht = geschlecht; + } + + public String getBeruf() { + return beruf; + } + + public void setBeruf(String beruf) { + this.beruf = beruf; + } + + public String getAkademischertitel() { + return akademischertitel; + } + + public void setAkademischertitel(String akademischertitel) { + this.akademischertitel = akademischertitel; + } + + public String getFamilienstand() { + return familienstand; + } + + public void setFamilienstand(String familienstand) { + this.familienstand = familienstand; + } + + public String getReligion() { + return religion; + } + + public void setReligion(String religion) { + this.religion = religion; + } + + public String getVita() { + return vita; + } + + public void setVita(String vita) { + this.vita = vita; + } + + public String getParty() { + return party; + } + + public void setParty(String party) { + this.party = party; + } + + public String getPrimaryFoto() { + return primaryFoto; + } + + public void setPrimaryFoto(String primaryFoto) { + this.primaryFoto = primaryFoto; + } + + public List getMemberships() { + return memberships; + } + + public void setMemberships(List memberships) { + this.memberships = memberships; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Speaker speaker)) return false; + return Objects.equals(id, speaker.id) && Objects.equals(name, speaker.name) + && Objects.equals(firstName, speaker.firstName) && Objects.equals(title, speaker.title) + && Objects.equals(geburtsdatum, speaker.geburtsdatum) && Objects.equals(geburtsort, speaker.geburtsort) + && Objects.equals(sterbedatum, speaker.sterbedatum) && Objects.equals(geschlecht, speaker.geschlecht) + && Objects.equals(beruf, speaker.beruf) && Objects.equals(akademischertitel, speaker.akademischertitel) + && Objects.equals(familienstand, speaker.familienstand) && Objects.equals(religion, speaker.religion) + && Objects.equals(vita, speaker.vita) && Objects.equals(party, speaker.party) && Objects.equals(memberships, speaker.memberships); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, firstName, title, geburtsdatum, geburtsort, sterbedatum, geschlecht, + beruf, akademischertitel, familienstand, religion, vita, party, memberships); + } + + @Override + public String toString() { + return new StringJoiner(", ", Speaker.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("name='" + name + "'") + .add("firstName='" + firstName + "'") + .add("title='" + title + "'") + .add("geburtsdatum=" + geburtsdatum) + .add("geburtsort='" + geburtsort + "'") + .add("sterbedatum=" + sterbedatum) + .add("geschlecht='" + geschlecht + "'") + .add("beruf='" + beruf + "'") + .add("akademischertitel='" + akademischertitel + "'") + .add("familienstand='" + familienstand + "'") + .add("religion='" + religion + "'") + .add("vita='" + vita + "'") + .add("party='" + party + "'") + .add("primaryFoto='" + primaryFoto + "'") + .add("memberships=" + memberships) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Agenda.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Agenda.java new file mode 100644 index 0000000..b8532cd --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Agenda.java @@ -0,0 +1,55 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.speech; + +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Agenda { + String index; + String id; + String title; + + public String getIndex() { + return index; + } + + public void setIndex(String index) { + this.index = index; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Agenda agenda)) return false; + return Objects.equals(index, agenda.index) && Objects.equals(id, agenda.id) && Objects.equals(title, agenda.title); + } + + @Override + public int hashCode() { + return Objects.hash(index, id, title); + } + + @Override + public String toString() { + return new StringJoiner(", ", Agenda.class.getSimpleName() + "[", "]") + .add("index='" + index + "'") + .add("id='" + id + "'") + .add("title='" + title + "'") + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Protocol.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Protocol.java new file mode 100644 index 0000000..904efc1 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Protocol.java @@ -0,0 +1,100 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.speech; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Protocol { + LocalDate date; + LocalTime starttime; + LocalTime endtime; + Integer index; + String titel; + String place; + Integer wp; + + public LocalDate getDate() { + return date; + } + + public void setDate(LocalDate date) { + this.date = date; + } + + public LocalTime getStarttime() { + return starttime; + } + + public void setStarttime(LocalTime starttime) { + this.starttime = starttime; + } + + public LocalTime getEndtime() { + return endtime; + } + + public void setEndtime(LocalTime endtime) { + this.endtime = endtime; + } + + public Integer getIndex() { + return index; + } + + public void setIndex(Integer index) { + this.index = index; + } + + public String getTitel() { + return titel; + } + + public void setTitel(String titel) { + this.titel = titel; + } + + public String getPlace() { + return place; + } + + public void setPlace(String place) { + this.place = place; + } + + public Integer getWp() { + return wp; + } + + public void setWp(Integer wp) { + this.wp = wp; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Protocol protocol)) return false; + return Objects.equals(date, protocol.date) && Objects.equals(starttime, protocol.starttime) + && Objects.equals(endtime, protocol.endtime) && Objects.equals(index, protocol.index) + && Objects.equals(titel, protocol.titel) && Objects.equals(place, protocol.place) && Objects.equals(wp, protocol.wp); + } + + @Override + public int hashCode() { + return Objects.hash(date, starttime, endtime, index, titel, place, wp); + } + + @Override + public String toString() { + return new StringJoiner(", ", Protocol.class.getSimpleName() + "[", "]") + .add("date=" + date) + .add("starttime=" + starttime) + .add("endtime=" + endtime) + .add("index=" + index) + .add("titel='" + titel + "'") + .add("place='" + place + "'") + .add("wp=" + wp) + .toString(); + } +} + diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Speech.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Speech.java new file mode 100644 index 0000000..ff50e6c --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/Speech.java @@ -0,0 +1,86 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.speech; + +import java.util.List; +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class Speech { + String id; + String text; + String speakerId; + Protocol protocol; + List textContents; + Agenda agenda; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getSpeakerId() { + return speakerId; + } + + public void setSpeakerId(String speakerId) { + this.speakerId = speakerId; + } + + public Protocol getProtocol() { + return protocol; + } + + public void setProtocol(Protocol protocol) { + this.protocol = protocol; + } + + public List getTextContents() { + return textContents; + } + + public void setTextContents(List textContents) { + this.textContents = textContents; + } + + public Agenda getAgenda() { + return agenda; + } + + public void setAgenda(Agenda agenda) { + this.agenda = agenda; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Speech speech)) return false; + return Objects.equals(id, speech.id) && Objects.equals(text, speech.text) && Objects.equals(speakerId, speech.speakerId) && Objects.equals(protocol, speech.protocol) && Objects.equals(textContents, speech.textContents) && Objects.equals(agenda, speech.agenda); + } + + @Override + public int hashCode() { + return Objects.hash(id, text, speakerId, protocol, textContents, agenda); + } + + @Override + public String toString() { + return new StringJoiner(", ", Speech.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("text='" + text + "'") + .add("speakerId='" + speakerId + "'") + .add("protocol=" + protocol) + .add("textContent=" + textContents) + .add("agenda=" + agenda) + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/TextContent.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/TextContent.java new file mode 100644 index 0000000..167ae99 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/domain/speech/TextContent.java @@ -0,0 +1,65 @@ +package org.texttechnologylab.project.gruppe_05_1.domain.speech; + +import java.util.Objects; +import java.util.StringJoiner; + +public abstract class TextContent { + String id; + String speakerId; + String text; + String type; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getSpeakerId() { + return speakerId; + } + + public void setSpeakerId(String speakerId) { + this.speakerId = speakerId; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TextContent that)) return false; + return Objects.equals(id, that.id) && Objects.equals(speakerId, that.speakerId) && Objects.equals(text, that.text) && Objects.equals(type, that.type); + } + + @Override + public int hashCode() { + return Objects.hash(id, speakerId, text, type); + } + + @Override + public String toString() { + return new StringJoiner(", ", TextContent.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("speakerId='" + speakerId + "'") + .add("text='" + text + "'") + .add("type='" + type + "'") + .toString(); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/nlp/NlpUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/nlp/NlpUtils.java new file mode 100644 index 0000000..7b80788 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/nlp/NlpUtils.java @@ -0,0 +1,313 @@ +package org.texttechnologylab.project.gruppe_05_1.nlp; + +import de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; +import org.apache.commons.io.FileUtils; +import org.apache.uima.UIMAException; +import org.apache.uima.cas.CASException; +import org.apache.uima.fit.factory.JCasFactory; +import org.apache.uima.fit.util.JCasUtil; +import org.apache.uima.jcas.JCas; +import org.apache.uima.resource.ResourceInitializationException; +import org.dkpro.core.io.xmi.XmiWriter; +import org.texttechnologylab.DockerUnifiedUIMAInterface.DUUIComposer; +import org.texttechnologylab.DockerUnifiedUIMAInterface.driver.DUUIDockerDriver; +import org.texttechnologylab.DockerUnifiedUIMAInterface.driver.DUUIRemoteDriver; +import org.texttechnologylab.DockerUnifiedUIMAInterface.driver.DUUIUIMADriver; +import org.texttechnologylab.DockerUnifiedUIMAInterface.lua.DUUILuaContext; +import org.texttechnologylab.annotation.NamedEntity; +import org.texttechnologylab.uima.type.Sentiment; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Base64; +import java.util.Collection; + +import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngineDescription; + +public class NlpUtils { + + // common class-attributes + private static DUUIComposer pComposer = null; + private static int iWorkers = 1; + + + public static void createNlpData() { + // Source: Dr. Abrami - Beispiel TODO + duuiInit(); + runDockerDriver(); + try { + runVideos(); + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + // Source: + casInit(); + createSentenceInfo(); + createNAmedEntities(); + createSentimentInfo(); + } + + private static void duuiInit() { + + DUUILuaContext ctx = null; + try { + ctx = new DUUILuaContext().withJsonLibrary(); + } catch (IOException e) { + System.err.println("IOException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + try { + pComposer = new DUUIComposer() + .withSkipVerification(true) // wir überspringen die Verifikation aller Componenten =) + .withLuaContext(ctx) // wir setzen den definierten Kontext + .withWorkers(iWorkers); // wir geben dem Composer eine Anzahl an Threads mit. + } catch (URISyntaxException e) { + System.err.println("URISyntaxException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + DUUIUIMADriver uima_driver = new DUUIUIMADriver(); + DUUIRemoteDriver remoteDriver = new DUUIRemoteDriver(); + DUUIDockerDriver dockerDriver = null; + try { + dockerDriver = new DUUIDockerDriver(); + } catch (IOException e) { + System.err.println("IOException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } catch (UIMAException e) { + System.err.println("UIMAException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } catch (SAXException e) { + System.err.println("SAXException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + // Hinzufügen der einzelnen Driver zum Composer + // pComposer.addDriver(uima_driver, remoteDriver, dockerDriver); // ORIG + pComposer.addDriver(uima_driver); + + } + + /** + * Initialization of a sample CAS document + * @return + * @throws ResourceInitializationException + * @throws CASException + */ + public static JCas getCas() { + // init a CAS with a static text. + JCas pCas = null; + try { + pCas = JCasFactory.createText("Ich finde dieses Programm läuft sehr gut. Ich überlege wie ich dieses für meine Bachelor-Arbeit nachnutzen kann.", "de"); + } catch (ResourceInitializationException e) { + System.err.println("ResourceInitializationException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } catch (CASException e) { + System.err.println("CASException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + // Define some metadata to serialize the CAS with the xmi writer + DocumentMetaData dmd = new DocumentMetaData(pCas); + dmd.setDocumentId("test"); + dmd.setDocumentTitle("DUUI Test-Dokument"); + dmd.addToIndexes(); + + return pCas; + } + + + public static void runDockerDriver() { + + // reset existing pipeline-components + pComposer.resetPipeline(); + + // Please note that the Docker images are first downloaded when they are called up for the first time. + try { + pComposer.add(new DUUIDockerDriver.Component("docker.texttechnologylab.org/textimager-duui-spacy-single-de_core_news_sm:0.1.4") + .withImageFetching() + .withScale(iWorkers) + .build()); + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + try { + pComposer.add(new DUUIDockerDriver.Component("docker.texttechnologylab.org/gervader_duui:1.0.2") + .withParameter("selection", "text") // nessecary + .withImageFetching() + .withScale(iWorkers) + .build()); + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + JCas tCas = getCas(); + + try { + pComposer.run(tCas); + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + JCasUtil.select(tCas, Sentence.class).stream().forEach(sentence -> { + System.out.println(sentence.getBegin()+"-"+sentence.getEnd()+": "+sentence.getCoveredText()); + System.out.println(JCasUtil.selectCovered(org.hucompute.textimager.uima.type.Sentiment.class, sentence)); + }); + } + + private static void casInit() { + JCas jcas = null; + try { + jcas = JCasFactory.createJCas(); + } catch (ResourceInitializationException e) { + System.err.println("ResourceInitializationException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } catch (CASException e) { + System.err.println("CASException: " + e.getMessage()); + System.err.println(e.getStackTrace()); + throw new RuntimeException(e); + } + + jcas.setDocumentLanguage("de"); + jcas.setDocumentText( + "Frau Präsidentin! Liebe Kolleginnen! Liebe Kollegen! Der Jahreswirtschaftsbericht war heute Gegenstand der Kabinettssitzung. Der Kollege Robert Habeck wird ihn im Wirtschaftsausschuss vorstellen, und morgen besteht ja auch hier Gelegenheit zur Debatte. Eine erfreuliche Nachricht ist, dass die Inflation zurückgeht. Eine der größten Bedrohungen für unsere wirtschaftliche Entwicklung und auch für den Lebensstandard der Bürgerinnen und Bürger ist die Geldentwertung. Im Zusammenwirken der Geldpolitik der Europäischen Zentralbank und der moderat restriktiven Fiskalpolitik der Bundesregierung haben wir große Fortschritte erzielt. Ich glaube, wir dürfen sagen: Die Entwicklung der Inflation ist nun beherrschbar geworden. Auf der anderen Seite ist die wirtschaftliche Entwicklung unseres Landes nicht zufriedenstellend. Wir haben eine zu geringe wirtschaftliche Dynamik. Dies hat damit zu tun, dass wir einen steigenden Zins und reduzierte Nachfrage auf den Weltmärkten aufgrund einer sich abkühlenden globalen Konjunktur haben, und auch die Folgen des Ausfalls günstiger fossiler Energieimporte nach Deutschland sind zu verzeichnen. Aber diese gegenwärtige Wachstumsschwäche unseres Landes passt sich ein in ein längeres Bild. In den vergangenen zehn Jahren, seit 2014, ist Deutschland in allen internationalen Standortvergleichen Schritt für Schritt zurückgefallen. Wir haben es also nicht mit einfachen Erklärungen zu tun, sondern mit strukturellen Aufgaben, denen wir uns stellen müssen. Ich leite daraus zwei Dinge ab: Erstens. Einfache Erklärungen sind nicht zutreffend. Zweitens. Alle, die in den vergangenen zehn Jahren Verantwortung getragen haben und heute Verantwortung tragen, sind aufgefordert, daran mitzuwirken, die Wachstumsdynamik in unserem Land zu verbessern. Ich will dazu konkret Folgendes sagen: Erstens. Die Bundesregierung setzt sich für eine Belebung auf unserem Arbeitsmarkt ein; denn der Mangel an Arbeitskräften ist eine Wachstumsbremse. In diesem Zusammenhang haben wir mit dem Fachkräfteeinwanderungsgesetz einen großen Fortschritt erzielt. Ihm müssen nun weitere Anstrengungen bei der Mobilisierung der Reserven unseres Arbeitsmarktes folgen. Zweitens. Die Bürokratiebelastung ist auf einem Allzeithoch seit dem Jahr 2012, in dem erstmals die Bürokratiebelastung gemessen worden ist. Mit den Meseberger Beschlüssen des Bundeskabinetts zum Bürokratieabbau werden diese Belastungen auf ein Allzeittief sinken, und wir müssen weitere Anstrengungen unternehmen, unsere Betriebe zu entfesseln. Drittens. Wir investieren auf einem Rekordniveau in Schiene, Straße, Wasserstraße, digitale Netze und in unsere Energieinfrastruktur. Aber diesen Anstrengungen müssen weitere folgen, insbesondere müssen jetzt die Rahmenbedingungen für private Investitionen und die Mobilisierung privaten Kapitals in Deutschland und Europa optimiert werden. Viertens. Unser steuerliches Umfeld, unsere steuerlichen Rahmenbedingungen müssen wettbewerbsfähiger werden. Die Bundesregierung und der Gesetzgeber haben ja bereits mit dem Zukunftsfinanzierungsgesetz Veränderungen vorgenommen, die sehr positiv wahrgenommen werden. Nun geht es darum, mit dem Wachstumschancengesetz einen weiteren Baustein gemeinsam zu beschließen, um im Bereich von Investitionsanreizen, zum Beispiel in der Baukonjunktur, und durch die Stärkung von privaten Forschungsvorhaben unserer Wirtschaft einen echten Schub zu geben. Hier kommt auch der Opposition eine besondere Verantwortung zu, mit dazu beizutragen, das wirtschaftliche Umfeld zu verbessern. Weitere Anstrengungen im Bereich der Steuerpolitik werden zu diskutieren sein. Liebe Kolleginnen und Kollegen, wir haben es gemeinsam im Zusammenwirken in Europa vermocht, die Geldentwertung unter Kontrolle zu bringen. Nun steht die nächste große Aufgabe vor uns: eine Wirtschaftswende, damit auch die Wachstumsdynamik unseres Landes wieder größer wird. " + ); + + Collection sentences = JCasUtil.select(jcas, Sentence.class); + for (Sentence sentence : sentences) { + // The text described by an annotation can be output using the getCoveredText() method + sentence.getCoveredText(); + + // Retrieve nested annotations, for example all tokens of a sentence + Collection tokens = JCasUtil.selectCovered(Token.class, sentence); + + + } + for (Token token : JCasUtil.select(jcas, Token.class)) { + System.out.println(token.getCoveredText() + '\t' + token.getPosValue()); + } + + + for (NamedEntity entity : JCasUtil.select(jcas, NamedEntity.class)) { + if (entity.getValue().equals("PER")) { + System.out.println("Person: " + entity.getCoveredText()); + } + else if (entity.getValue().equals("LOC")) { + System.out.println("Location: " + entity.getCoveredText()); + } + } + + for (Sentence sentence : JCasUtil.select(jcas, Sentence.class)) { + System.out.println(sentence.getCoveredText()); + for (Sentiment sentiment : JCasUtil.selectCovered(Sentiment.class, sentence)) { + System.out.println("Sentiment: " + sentiment.getSentiment()); + } + } + + } + + + + /** + * Execution of video processing via DUUI using the RemoteDriver + * @throws Exception + */ + public static void runVideos() throws Exception { + + // laden eines Videos aus dem Ressourcen-Ordner + ClassLoader classLoader = NlpUtils.class.getClassLoader(); + URL fVideo = classLoader.getResource("example.mp4"); // TODO + + // convertieren eines Videos in einen Base64-String + File fFile = new File(fVideo.getPath()); + byte[] bFile = FileUtils.readFileToByteArray(fFile); + String encodedString = Base64.getEncoder().encodeToString(bFile); + String pMimeType = Files.probeContentType(Path.of(fVideo.getPath())); + + // erzeugng einer Beispiel-Cas + JCas pCas = getCas(); + + // erstellen einer view namens "video" und setzen des Mimetpes sowie der SofaData + JCas videoCas = pCas.createView("video"); + videoCas.setSofaDataString(encodedString, pMimeType); + videoCas.setDocumentLanguage("de"); + + // erstellen einer weiteren View, für die Transcription + JCas transcriptCas = pCas.createView("transcript"); + + // this takes some time, because the video is not small, but also not to large. + pComposer.add(new DUUIRemoteDriver.Component("http://whisperx.lehre.texttechnologylab.org") + .withScale(iWorkers) + .withSourceView("video") // where is the video + .withTargetView("transcript") // where the transcript must be annotated + .build()); + + // alternativ +// pComposer.add(new DUUIDockerDriver.Component("docker.texttechnologylab.org/duui_whisperx:0.1") +// .withScale(iWorkers) +// .withSourceView("video") +// .withTargetView("transcript") +// .build()); + + // write into XMI for debugging purposes. + pComposer.add(new DUUIUIMADriver.Component(createEngineDescription(XmiWriter.class, + XmiWriter.PARAM_TARGET_LOCATION, "/tmp/", + XmiWriter.PARAM_PRETTY_PRINT, true, + XmiWriter.PARAM_OVERWRITE, true, + XmiWriter.PARAM_VERSION, "1.1", + XmiWriter.PARAM_COMPRESSION, "GZIP" + )).build()); + + pComposer.run(pCas); + + // select some data + JCasUtil.selectAll(videoCas).stream().forEach(videoAnnotation->{ + System.out.println(videoAnnotation); + }); + + // select some data + JCasUtil.selectAll(transcriptCas).stream().forEach(tAnnotation->{ + System.out.println(tAnnotation); + }); + + + } + + private static void createSentenceInfo() { + + } + + private static void createNAmedEntities() { + + } + + private static void createSentimentInfo() { + + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/JavalinConfig.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/JavalinConfig.java new file mode 100644 index 0000000..4d37a16 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/JavalinConfig.java @@ -0,0 +1,57 @@ +package org.texttechnologylab.project.gruppe_05_1.rest; + +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; +import org.texttechnologylab.project.gruppe_05_1.util.PropertiesUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Diese Klasse dient der Konfiguruerung von Javalin + */ +public class JavalinConfig extends Properties { + + private static final String propertiesFileName = "javalin.properties"; + + /** + * Default Constructor + */ + public JavalinConfig() { + this(propertiesFileName); + } + + /** + * Constructor mit Pfad zur Properties-Datei + * @param sPath + */ + public JavalinConfig(String sPath) { + + try (InputStream input = PropertiesUtils.class.getClassLoader().getResourceAsStream(propertiesFileName)) { + if (null == input) { + System.err.println("Properties-Datei '" + propertiesFileName + "' konnte nicht gelesen werden"); + } + + this.load(input); + } catch (IOException ioex) { + System.err.println("Exception beim Lesen der properties-Datei '" + propertiesFileName + "': " + ioex.getLocalizedMessage()); + } + } + + + /** + * Liefert alle Properties zurück + * @return Properties + */ + public Properties getJavalinProperties() { + return this; + } + + /** + * Liefert den Port zurück, auf dem Javalin läuft + * @return + */ + public Integer getPort() { + return GeneralUtils.parseInt(getProperty("port")); + } +} 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 new file mode 100644 index 0000000..9760e05 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/ParlamentarierController.java @@ -0,0 +1,94 @@ +package org.texttechnologylab.project.gruppe_05_1.rest; + +import io.javalin.http.Context; +import io.javalin.openapi.*; +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.database.MongoPprUtils; +import org.texttechnologylab.project.gruppe_05_1.util.PPRUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Dieser Kontroller zeigt Informationen um den Parlamentariern: + * 1. Die Einstiegsseite: eine Filter-fähige Auflistung der Parlamentariern. + * Angezeigt werden Vor- und Nachname, Partei sowie ID. + * Die Filter-Funktion funktioniert für all diese Felder. + * 2. Ein Parlamentarierportfolio. Dieses beinhaltet: + * - Name und Partei im Header + * - Foto, falls ein Foto als Primärfoto angegeben wurde + * - Die Anzahl der Reden + Link auf die Redenseite des Parlamentariers + * - Persönliche Daten (Titel, Geschlecht, Religion, Beruf, Vita etc.) + * - Eine Auflistung aller Mitgliedschaften + * - Eine Auflistung aller vorhandenen Fototupeln. Für jedes Tupel steht einen Link, um diese zu editieren + */ +public class ParlamentarierController { + /** + * Liste alle Abgeordnete. + * Der Query-Parameter "filter" kann die Menge der Ergebnisse einschränken + * @param ctx JavaLin-Context + */ + + @OpenApi( + summary = "Get alle Parlamentarier. Man kann nach Vor-, Nachname oder Partei filtern.", + description = "Listet alle Parlamentarier bzw. diejenige, welche den Filter entsprechen", + operationId = "getAllParlamentarier", + path = "/", + methods = HttpMethod.GET, + tags = {"Parlamentarier"}, + queryParams = { + @OpenApiParam(name = "filter", description = "Full-Text-Filter. Kann Vorname, Nachname oder Partei filtern", required = false), + }, + responses = { + @OpenApiResponse(status = "200", content = {@OpenApiContent(from = Parlamentarier[].class)}) + }) + public static void getAllParlamentarier(Context ctx) { + String filter = ctx.queryParam("filter"); + System.out.println("Filter: '" + filter + "'"); + + List parlamentarier = MongoPprUtils.getAllParlamentarier(filter); + PPRUtils.sortParlamentarierByName(parlamentarier); + System.out.println(parlamentarier.size() + " MdBs gefunden"); + + Map attributes = new HashMap<>(); + attributes.put("parlamentarier", parlamentarier); + attributes.put("filter", filter); + ctx.render("parlamentarier.ftl", attributes); + } + + + /** + * Zeigt die Details eines Parlamentariers an: + * - persönliche Daten (Geburtsdatum, -ort, Vita, Religion etc.). + * - Mitgliederschaften, falls vorhanden + * - Fotos, falls vorhanden + * @param ctx JavaLin-Context + */ + + @OpenApi( + summary = "Zeigt die Details eines Parlamentariers an", + description = "Zeigt persönliche Daten, Mitgliederschaften, Fotos", + operationId = "getParlamentarierDetails", + path = "/portfolio/{id}", + methods = HttpMethod.GET, + tags = {"Parlamentarier"}, + pathParams = { + @OpenApiParam(name = "id", description = "id des Parlamentariers", required = true), + }, + responses = { + @OpenApiResponse(status = "200", content = {@OpenApiContent(from = ParlamentarierDetails.class)}) + }) + public static void getParlamentarierDetails(Context ctx) { + String id = ctx.pathParam("id"); + System.out.println("getParlamentarierDetails, ID = " + id); + + ParlamentarierDetails pd = MongoPprUtils.getParlamentarierDetailsByID(id); + + Map attributes = new HashMap<>(); + attributes.put("p", pd); + attributes.put("speechesCount", pd.getReden() == null ? 0 : pd.getReden().size()); + ctx.render("parlamentarierDetails.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 new file mode 100644 index 0000000..2590ba1 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/RESTHandler.java @@ -0,0 +1,72 @@ +package org.texttechnologylab.project.gruppe_05_1.rest; + +import freemarker.template.Configuration; +import freemarker.template.TemplateExceptionHandler; +import io.javalin.Javalin; +import io.javalin.http.staticfiles.Location; +import io.javalin.openapi.plugin.OpenApiPlugin; +import io.javalin.openapi.plugin.redoc.ReDocPlugin; +import io.javalin.rendering.template.JavalinFreemarker; + +import java.io.File; +import java.io.IOException; + +public class RESTHandler { + public static final String TEMPLATE_DIR = "src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates"; + + public void startJavalin() { + + // Javalin Konfiguration (z.B. port) + JavalinConfig jlConfig = new JavalinConfig(); + int port = jlConfig.getPort(); + + // FreeMarker Konfiguration + Configuration fmConfig = new Configuration(Configuration.VERSION_2_3_33); + fmConfig.setDefaultEncoding("UTF-8"); + try { + fmConfig.setDirectoryForTemplateLoading(new File(TEMPLATE_DIR)); + } catch (IOException e) { + throw new RuntimeException(e); + } + fmConfig.setLogTemplateExceptions(true); + fmConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + + // Erzeuge die Javalin app + Javalin app = Javalin.create(config -> { + config.staticFiles.add("src/main/resources/public", Location.EXTERNAL); // momentan nicht benutzt + + config.fileRenderer(new JavalinFreemarker(fmConfig)); + + config.registerPlugin(new OpenApiPlugin(pluginConfig -> { + // Define OpenAPI spec configuration + pluginConfig.withDefinitionConfiguration((version, definition) -> { + definition.withOpenApiInfo(info -> info.setTitle("Javalin OpenAPI Documentation")); + }); + })); + + config.registerPlugin(new ReDocPlugin()); + + }) + .start(port); + + // Routes + // ====== + + // Parlamentarier + app.get("/", ParlamentarierController::getAllParlamentarier); + app.get("/portfolio/{id}", ParlamentarierController::getParlamentarierDetails); + + /* - TODO + // Fotos + app.get("/editFoto/{id}", FotosController::editFotos); + app.post("/editFoto/updateFotoUrl/{id}/{pictureId}", FotosController::updateFotoUrl); + app.post("/editFoto/defineFotoAsPrimary/{id}", FotosController::defineFotoAsPrimary); + + // Reden + app.get("/reden/{id}", RedenController::listSpeeches); // zeige Reden eines Parlamentariers an + app.get("/reden/{id}/{redeId}", RedenController::showSpeech); // zeige eine bestimmte Rede des Parlamentariers an + app.post("/reden/updateComment/{id}/{speechId}/{commentId}", RedenController::updateComment); // aktualisiere Änderung an einer Kommentar + + */ + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/FileUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/FileUtils.java new file mode 100644 index 0000000..1e2a740 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/FileUtils.java @@ -0,0 +1,134 @@ +package org.texttechnologylab.project.gruppe_05_1.util; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public abstract class FileUtils { + + + + + /** + * Creates a (possibly nested) directory + * @param dir (e.g. "generated" , "level1/level2/level3" etc. + */ + public static void createDirectoryIFNotExists(String dir) { + File directory = new File(dir); + if (! directory.exists()){ + directory.mkdirs(); + } + } + + /** + * Write a list of Strings to file + * @param fileName + * @param stringsList + */ + public static void writeStringsToFile(String fileName, List stringsList) { + FileWriter fileWriter = null; + try { + fileWriter = new FileWriter(fileName); + } catch (IOException e) { + throw new RuntimeException(e); + } + for (String str : stringsList) { + try { + fileWriter.write(str + System.lineSeparator()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + try { + fileWriter.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * + * @param fileName + * @param string + */ + public static void writeStringToFile(String fileName, String string) { + FileWriter fileWriter = null; + try { + fileWriter = new FileWriter(fileName); + } catch (IOException e) { + throw new RuntimeException(e); + } + + try { + fileWriter.write(string + System.lineSeparator()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + try { + fileWriter.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * + * @param fileName + * @return + * @throws IOException + */ + public static FileWriter createFileWriter(String fileName) throws IOException{ + FileWriter fileWriter = null; + fileWriter = new FileWriter(fileName); + return fileWriter; + } + + + /** + * + * @param fileWriter + * @param stringsList + */ + + public static void writeStringsToFile(FileWriter fileWriter, List stringsList) { + for (String str : stringsList) { + try { + fileWriter.write(str + System.lineSeparator()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + try { + fileWriter.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + + /** + * + * @param dir + * @return + */ + public static Set listFilesInDirectory(String dir) { + try (Stream stream = Files.list(Paths.get(dir))) { + return stream + .filter(file -> !Files.isDirectory(file)) + .map(Path::getFileName) + .map(Path::toString) + .collect(Collectors.toSet()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/GeneralUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/GeneralUtils.java new file mode 100644 index 0000000..fff29e9 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/GeneralUtils.java @@ -0,0 +1,89 @@ +package org.texttechnologylab.project.gruppe_05_1.util; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public abstract class GeneralUtils { + + /** + * + * @param integer + * @return + */ + public static Integer parseInt(String integer) { + + try { + return Integer.parseInt(integer); + } catch (NumberFormatException ex) { + return null; + } + } + + /** + * Parse a date in the format used in Germany + * @param date + * @return + */ + public static LocalDate parseDate(String date) { + + try { + return LocalDate.parse(date, DateTimeFormatter.ofPattern("dd.MM.yyyy")); + } catch (DateTimeParseException ex) { + return null; + } + } + + + /** + * Parse tiem in a give format + * @param date + * @param timeFormat + * @return + */ + + public static LocalTime parseTime(String date, String timeFormat) { + + try { + return LocalTime.parse(date, DateTimeFormatter.ofPattern(timeFormat)); + } catch (DateTimeParseException ex) { + return null; + } + } + + /** + * Parse a Formatiere Datumsfelder wie in Deutschland üblich ist. + * @param date + * @return + */ + public static String formatDate(LocalDate date) { + + if (null== date) return ""; + return date.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")); + } + + /** + * Format time in the format used in Germany + * @param time + * @return + */ + public static String formatTime(LocalTime time) { + + if (null== time) return ""; + return time.format(DateTimeFormatter.ofPattern("HH.mm")); + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PPRUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PPRUtils.java new file mode 100644 index 0000000..902d2e1 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PPRUtils.java @@ -0,0 +1,357 @@ +package org.texttechnologylab.project.gruppe_05_1.util; + +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Indexes; +import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler; +import org.texttechnologylab.project.gruppe_05_1.database.MongoObjectFactory; +import org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils; +import org.texttechnologylab.project.gruppe_05_1.domain.html.Parlamentarier; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.BiografischeAngaben; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Mdb; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbDocument; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker; +import org.texttechnologylab.project.gruppe_05_1.nlp.NlpUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.FileObjectFactory; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.*; +import java.net.URL; +import java.util.*; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public abstract class PPRUtils { + + public static final String PARTEILOS_KUERZEL = "Parteilos"; + + + /** + * Prüfe, ob die Collections existieren. Falls nicht: erzeuge sie und lege Indizes an + */ + public static void ensureCollectionExist() { + + Set existingCollectionNames = MongoDBHandler.getCollectionNames(); + + if (existingCollectionNames.contains(MongoPprUtils.SPEAKER_COLLECTION_NAME)) { + MongoDBHandler.createCollection(MongoPprUtils.SPEAKER_COLLECTION_NAME); + + // Add Indexes + MongoCollection speakerCollection = MongoPprUtils.getSpeakerCollection(); + // MongoDB creates automatically an index on "_id" + speakerCollection.createIndex(Indexes.ascending("name")); + speakerCollection.createIndex(Indexes.ascending("firstName")); + speakerCollection.createIndex(Indexes.ascending("party")); + } + + if (existingCollectionNames.contains(MongoPprUtils.SPEECH_COLLECTION_NAME)) { + MongoDBHandler.createCollection(MongoPprUtils.SPEECH_COLLECTION_NAME); + + // Add Indexes + MongoCollection speechCollection = MongoPprUtils.getSpeechCollection(); + // MongoDB creates automatically an index on "_id" + speechCollection.createIndex(Indexes.ascending("speaker")); + } + + if (existingCollectionNames.contains(MongoPprUtils.COMMENT_COLLECTION_NAME)) { + MongoDBHandler.createCollection(MongoPprUtils.COMMENT_COLLECTION_NAME); + + // TODO: Add Indexes + MongoCollection commentCollection = MongoPprUtils.getCommentCollection(); + // MongoDB creates automatically an index on "_id" + // commentCollection.createIndex(Indexes.ascending("???")); + } + + if (existingCollectionNames.contains(MongoPprUtils.PICTURES_COLLECTION_NAME)) { + MongoDBHandler.createCollection(MongoPprUtils.PICTURES_COLLECTION_NAME); + + // TODO: Add Indexes + MongoCollection pictureCollection = MongoPprUtils.getPicturesCollection(); + // MongoDB creates automatically an index on "_id" + // pictureCollection.createIndex(Indexes.ascending("???")); + } + } + + /** + * Alle Informationen lesen... + * - Parlamentarier + * - Reden + * - Kommentare + * - etc. + * ... und in die Mongo-DB persistieren, falls noch nicht vorhanden sind. + * @param xmlFactory + */ + public static void parlamentExplorerInit(FileObjectFactory xmlFactory, MongoObjectFactory mongoFactory) { + + // + Properties xmlProperties = PropertiesUtils.readPropertiesFromResource("xml.properties"); + + // MdB lesen: MDBs werden nur dann gelesen und persistiert, wenn die Collection noch leer ist + String mdbUrl = xmlProperties.getProperty("mdb_url"); + if (MongoPprUtils.getSpeakerCollection().countDocuments() == 0) { + readAndPersistMdbs(mdbUrl, xmlFactory, mongoFactory); + } else { + System.out.println("MDBs (Speakers) werden nicht gelesen, da sie bereits in der Datenbank stehen"); + } + + // Reden und Kommentare einlesen und persistieren - TODO + readSpeechesAndComments(xmlFactory, mongoFactory); + + // Fotos hochladen - TODO + readPhotos(mongoFactory); + + // NLP-Analyse (Text und Video) + // TODO: Anpassung notwendig, Daten aus dem NEtz statt aus resources holen + // Achtung: läuft nicht unter Windows. Verwende Linux (nativ oder im Virtual Box) + // NlpUtils.createNlpData(); + + } + + /** + * Fotos hochladen - TODO + * @param mongoFactory + */ + public static void readPhotos(MongoObjectFactory mongoFactory) { + + } + + /** + * Reden und Kommentare einlesen - TODO + * @param xmlFactory + * @param mongoFactory + */ + public static void readSpeechesAndComments(FileObjectFactory xmlFactory, MongoObjectFactory mongoFactory) { + + } + + /** + * Liest die MdBs aus der Bundestag-Seite und persistiere sie in die MongoDB + * @param mdbUrl + * @param xmlFactory + */ + public static void readAndPersistMdbs(String mdbUrl, FileObjectFactory xmlFactory, MongoObjectFactory mongoFactory) { + org.w3c.dom.Document mdbRoot = getMdbFromRemoteXmlZipfile(mdbUrl); + Element rootElement = mdbRoot.getDocumentElement(); + // TODO: optional! persist the metadata of the 1723434311 element + + MdbDocument doc = xmlFactory.createMdbDocument(rootElement); + List mdbList = doc.getMdbs(); + + List mdbNodes = XmlUtils.getChildrenByName(rootElement, "MDB"); + for (Node mdbNode : mdbNodes) { + Speaker speaker = xmlFactory.createSpeaker(mdbNode); + System.out.println("Speaker " + speaker.getId() + " (" + speaker.getFirstName() + " " + speaker.getName() + ", " + speaker.getParty() + ")"); + + org.bson.Document speakerDoc = mongoFactory.createSpeaker(speaker); + + MongoDBHandler.insertDocument(MongoPprUtils.getSpeakerCollection(), speakerDoc); + } + + // TODO: persist each speaker! + // TODO: guard: if not in the DB already + + } + + /** + * Liest die MDB aus einer Zip-Datei der bundestag,de-Seite + * @param zipUrl + * @return + */ + private static org.w3c.dom.Document getMdbFromRemoteXmlZipfile(String zipUrl) { + URL url = null; + InputStream urlInputStream = null; + try { + url = new URL(zipUrl); + urlInputStream = url.openStream(); + ZipInputStream zipInputStream = new ZipInputStream(urlInputStream); + ZipEntry entry; + + // Temporary storage for XML and DTD content + ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream(); + ByteArrayOutputStream dtdOutputStream = new ByteArrayOutputStream(); + + while ((entry = zipInputStream.getNextEntry()) != null) { + String entryName = entry.getName(); + if (entryName.equals("MDB_STAMMDATEN.XML")) { + copyStream(zipInputStream, xmlOutputStream); // copy the XML InputStream + } else if (entryName.equals("MDB_STAMMDATEN.DTD")) { + copyStream(zipInputStream, dtdOutputStream);// copy theDTD InputStream + } + zipInputStream.closeEntry(); + } + + if (xmlOutputStream.size() == 0 || dtdOutputStream.size() == 0) { // TODO + // throw new FileNotFoundException("XML or DTD not found in the ZIP archive"); + } + InputStream xmlInputStreamFinal = new ByteArrayInputStream(xmlOutputStream.toByteArray()); + InputStream dtdInputStreamFinal = new ByteArrayInputStream(dtdOutputStream.toByteArray()); + + + + org.w3c.dom.Document doc = XmlUtils.loadXmlDocumentFromRemoteZip(entry, xmlInputStreamFinal, dtdInputStreamFinal); + // Cleanup + zipInputStream.close(); + urlInputStream.close(); + return doc; + + } catch (IOException e) { + // TODO + throw new RuntimeException(e); + } + } + + /** + * Helper method to save a stream for a later use. + * We use it to save the DTD and the XML files of the MDBs, which are within a zipfile on the bundestag.de site + * @param input + * @param output + * @throws IOException + */ + + private static void copyStream(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = input.read(buffer)) != -1) { + output.write(buffer, 0, bytesRead); + } + } + + + /** + * Eine Liste von Parlamentariern nach Namen (erst nach Nachnamen, dann nach Vornamen) sortieren (aufsteigend) + * @param mdbList + */ + public static void sortParlamentarierByName(List mdbList) { + + mdbList.sort((o1, o2) -> { + int compareNachname = o1.getNachname().compareTo(o2.getNachname()); + if (0 == compareNachname) { + return o1.getVorname().compareTo(o2.getVorname()); + } else { + return compareNachname; + } + }); + } + + // TODO: altes Zeug, sortieren... + + /** + * Alle Parteien (aus einer Liste der MdBs) herausfinden. + * null-Einträge durch einen Platzhalter ersetzen, damit später keine null pointer exceptions auftretten + * @param mdbList + * @return + */ + public static Set getFraktionenFromMdbList(List mdbList) { + + /* mdb --> BIOGRAFISCHE_ANGABEN --> PARTEI_KURZ ergibt die aussagekräftige Ergebnisse + * parteiKurz: [null, DRP, SPD, DPS, DP, WAV, BP, FU, SRP, CSUS, FDP, DIE LINKE., CDU, PDS/LL, GRÜNE, + * PDS, AfD, CSU, DIE GRÜNEN/BÜNDNIS 90, Plos, DSU, BSW, BÜNDNIS 90/DIE GRÜNEN, LKR, + * GB/ BHE, SSW, DPB, Die PARTEI, DZP, CVP, KPD] + */ + + Set parteikuerzel= + mdbList.stream() + .map(Mdb::getBio) + .map(BiografischeAngaben::getParteiKuerzel) + .collect(Collectors.toSet()); + + // Parteilose dabei? + if (parteikuerzel.contains(null)) { + parteikuerzel.remove(null); + parteikuerzel.add(PARTEILOS_KUERZEL); + } + + return parteikuerzel; + } + + /** + * Eine Zuordnung zwischen Partei und deren Mitgliedern erzeugen. Ein Mitglied ist hier die MDB-Struktur + * @param mdbList + * @return + */ + public static Map> createMdbParteiZuordnung(List mdbList) { + + Map> zuordnung = new HashMap<>(); + + for (Mdb mdb : mdbList) { + String partei = mdb.getBio().getParteiKuerzel(); + if (null == partei) { + partei = PARTEILOS_KUERZEL; + } + if (zuordnung.containsKey(partei)) { + zuordnung.get(partei).add(mdb); + } else { + zuordnung.put(partei, new ArrayList<>()); + zuordnung.get(partei).add(mdb); + } + + } + + return zuordnung; + } + + /** + * Eine Zuordnung zwischen Partei und deren Mitgliedern erzeugen. Ein Mitglied wird hier durch seine ID erfaßt + * @param parteien + * @param mdbList + * @return + */ + public static Map> getMdbParteiZuordnung(Set parteien, List mdbList) { + + Map> zuordnung = new HashMap<>(); + + for (String partei : parteien) { + if (partei.equals(PARTEILOS_KUERZEL)) { + List ids = mdbList.stream() + .filter(mdb -> (null == mdb.getBio().getParteiKuerzel())) + .map(Mdb::getId) + .collect(Collectors.toList()); + zuordnung.put(partei, ids); + } else { + List ids = mdbList.stream() + .filter(mdb -> (( null != mdb.getBio().getParteiKuerzel() ) && (mdb.getBio().getParteiKuerzel().equals(partei)))) + .map(Mdb::getId) + .collect(Collectors.toList()); + zuordnung.put(partei, ids); + } + } + + return zuordnung; + } + + /** + * Eine Zuordnung zwischen MdB (repräsentiert durch seine ID) und seien biographischen Daten erzeugen. + * @param mdbList + * @return + */ + public static Map getMdbParteiZuordnung(List mdbList) { + + Map zuordnung = new HashMap<>(); + + for (Mdb mdb : mdbList) { + zuordnung.put(mdb.getId(), mdb.getBio()); + } + + return zuordnung; + } + + /** + * Eine Liste von MdBs nach Namen (erst nach Nachnamen, dann nach Vornamen) sortieren (aufsteigend) + * @param mdbList + */ + public static void sortMdbByName(List mdbList) { + + mdbList.sort((o1, o2) -> { + int compareNachname = o1.getNamen().get(0).getNachname().compareTo(o2.getNamen().get(0).getNachname()); + if (0 == compareNachname) { + return o1.getNamen().get(0).getVorname().compareTo(o2.getNamen().get(0).getVorname()); + } else { + return compareNachname; + } + }); + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PropertiesUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PropertiesUtils.java new file mode 100644 index 0000000..5b875f3 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/PropertiesUtils.java @@ -0,0 +1,24 @@ +package org.texttechnologylab.project.gruppe_05_1.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public abstract class PropertiesUtils { + + public static Properties readPropertiesFromResource(String propertiesFileName) { + + Properties properties = new Properties(); + try (InputStream input = PropertiesUtils.class.getClassLoader().getResourceAsStream(propertiesFileName)) { + if (null == input) { + System.err.println("Properties-Datei '" + propertiesFileName + "' konnte nicht gelesen werden"); + } + + properties.load(input); + } catch (IOException ioex) { + System.err.println("Exception beim Lesen der properties-Datei '" + propertiesFileName + "': " + ioex.getLocalizedMessage()); + } + + return properties; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/XmlUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/XmlUtils.java new file mode 100644 index 0000000..8ff4ae6 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/util/XmlUtils.java @@ -0,0 +1,252 @@ +package org.texttechnologylab.project.gruppe_05_1.util; + + +import org.w3c.dom.*; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public abstract class XmlUtils { + + public static Document loadXmlDocumentFromRemoteZip(ZipEntry zipEntry, + InputStream xmlInputStream, + InputStream dtdInputStream) { + + Document document = null; + + // Set up a DocumentBuilderFactory and enable DTD validation + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(true); + DocumentBuilder builder = null; + try { + builder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } + builder.setEntityResolver((publicId, systemId) -> { + if (systemId != null && systemId.endsWith(".DTD")) { + return new InputSource(dtdInputStream); + } + return null; + }); + try { + document = builder.parse(xmlInputStream); + + // TODO: Error handling... + } catch (SAXException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + + document.getDocumentElement().normalize(); + return document; + } + + + /** + * Read an XML document from a given path + * @param filePath (example: src/main/resources/myData.xml) + * @return + */ + public static Document loadXmlDocument(String filePath) { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + try { + builder = dbf.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } + + Document doc = null; + try { + doc = builder.parse(new File(filePath)); // systemID = "MDB_STAMMDATEN.DTD" + } catch (SAXException e) { + throw new RuntimeException(e); + } catch (IOException e) { + System.err.println(e); + System.err.println("\n"); + System.err.println(e.getLocalizedMessage()); + throw new RuntimeException(e); + } + doc.getDocumentElement().normalize(); + + return doc; + } + + + /** + * Read an XML document and return its root element + * @param filePath + * @return the root element of document + */ + public static Element getRootDocument(String filePath) { + Document doc = loadXmlDocument(filePath); + return doc.getDocumentElement(); + } + + + /** + * Get a list of children nodes + * @param origin + * @return list of children nodes + */ + public static List getChildren(Element origin) { + + NodeList nl = origin.getChildNodes(); + for (int i=0 ; i< nl.getLength() ; i++) { + Node n = nl.item(i); + System.out.println(nl.item(i)); + } + + List list = new ArrayList<>(); + Node current = origin.getFirstChild(); + while (null != current) { + list.add(current); + current = current.getNextSibling(); + } + + return list; + } + + /** + * Get a list of children nodes which have the specified name + * @param origin + * @param name + * @return list of children nodes with a specified name + */ + public static List getChildrenByName(Node origin, String name) { + List list = new ArrayList<>(); + + Node current = origin.getFirstChild(); + while (null != current) { + if (current.getNodeName().equals(name)) { + list.add(current); + } + current = current.getNextSibling(); + } + + return list; + } + + /** + * Get first child nodes which has the specified name + * @param origin + * @param name + * @return first child node with a specified name + */ + public static Node getFirstChildByName(Node origin, String name) { + + Node current = origin.getFirstChild(); + while (null != current) { + if (current.getNodeName().equals(name)) { + return current; + } + current = current.getNextSibling(); + } + + return null; + } + + /** + * + * @param node + * @return attributes of the given node + */ + public static Map getNodeAttributes(Node node) { + NamedNodeMap attributes = node.getAttributes(); + Map attributesList = new HashMap<>(); + for (int i=0 ; i< attributes.getLength() ; i++) { + Node attributeNode = attributes.item(i); + attributesList.put(attributeNode.getNodeName(), attributeNode.getNodeValue()); + } + return attributesList; + } + + /** + * + * @param node + * @param attributeName + * @return + */ + public static String getNodeAttributeByName(Node node, String attributeName) { + NamedNodeMap attributes = node.getAttributes(); + for (int i=0 ; i< attributes.getLength() ; i++) { + Node attributeNode = attributes.item(i); + if (attributeNode.getNodeName().equals(attributeName)) return attributeNode.getNodeValue(); + } + return null; + } + + /** + * Return the content of a Node as raw text + * @param node + * @return String + */ + public static String getRawText(Node node) { + return getRawText(node, 0); + } + + private static String getRawText(Node node, int depth) { + StringBuilder sb = new StringBuilder(); + + String padding = " ".repeat(2 * depth); + switch (node.getNodeType()) { + case Node.TEXT_NODE: // 3 + if ( ! node.getNodeValue().trim().isBlank()) { + sb.append(node.getNodeValue()); + } + break; + + case Node.ELEMENT_NODE: // 1 + // Print tag + sb.append('\n').append(padding).append('<').append(node.getNodeName()); + + // Print attributes, if any + Map attributes = getNodeAttributes(node); + if (attributes.isEmpty()) { + sb.append('>'); + } else { + for (Map.Entry entry : attributes.entrySet()) { + sb.append(' ').append(entry.getKey()).append("=\"").append(entry.getValue()).append('"'); + } + sb.append('>'); + } + + // Visit all Children + NodeList children = node.getChildNodes(); + for (int i=0 ; i < children.getLength() ; i++) { + Node child = children.item(i); + sb.append(getRawText(child, depth+1)); + } + + // Print closing tag + sb.append('\n').append(padding).append("'); + break; + + default: + System.out.println("Unknown type in getRawText(), depth " + depth + +"Type = " + node.getNodeType() + + " / Name = '" + node.getNodeName() + + "' / Value = '" + node.getNodeValue() + + "' / Context = '" + node.getTextContent() + + "'"); + } + + return sb.toString(); + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/memberships.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/memberships.ftl new file mode 100644 index 0000000..d267673 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/memberships.ftl @@ -0,0 +1,23 @@ + + + ${m.begin!'-'} + + + ${m.end!'-'} + + + <#if m.label??> + ${m.label} + + + <#if m.role??> +
+ Role: ${m.role} + + + <#if m.wp??> +
+ (WP: ${m.wp}) + + + diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarier.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarier.ftl new file mode 100644 index 0000000..c539b15 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarier.ftl @@ -0,0 +1,54 @@ + + + + + + Abgeordnete Übersicht + + + + +
+

Abgeordnete (alphabetisch sortiert)

+
+
+ +
+ Name : + +
+ +
+ + + + + + + + + + + <#list parlamentarier as p> + + + + + + + +
NameParteiID
${p.nachname}, ${p.vorname}${p.partei}${p.id}
+ Zurück zum Anfang +
+ + + + + + diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierAttribut.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierAttribut.ftl new file mode 100644 index 0000000..b376f65 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierAttribut.ftl @@ -0,0 +1,6 @@ + <#if value??> + + ${title} + ${value} + + \ No newline at end of file diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierDetails.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierDetails.ftl new file mode 100644 index 0000000..0ad5435 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/parlamentarierDetails.ftl @@ -0,0 +1,101 @@ + + + + + + ${p.vorname} ${p.nachname} (${p.partei}) + + + +
+

${p.vorname} ${p.nachname} (${p.partei})

+
+ +
+ <#if p.primaryFoto??> + Abgeordneterfoto +

+ + +
+
+

Reden

+ <#if p.reden??> + ${speechesCount} Reden vorhanden + <#else> + Keine Reden + +

+
+ +
+

Persönliche Daten

+ <#include "persoenlicheDaten.ftl"> +
+ +


+ + <#if p.memberships??> +
+

Mitgliedschaften

+ + + + + + + + + + + <#list p.memberships as m> + <#include "memberships.ftl"> + + +
VonBisBeschreibung
+
+ + +


+ + <#if p.pictures??> +
+

Fotos

+ + + + + + + + + + + + + + <#list p.pictures as pic> + <#include "pictures.ftl"> + + +
DatumBeschreibungFoto (HP)Foto (HQ)
+ +
+ + +
+
+
+ +
+
+ +
+ + diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/persoenlicheDaten.ftl b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/persoenlicheDaten.ftl new file mode 100644 index 0000000..a72a044 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/website/templates/persoenlicheDaten.ftl @@ -0,0 +1,64 @@ + + + <#if p.akademischertitel??> + <#assign title = "Akademischer Titel"> + <#assign value = "${p.akademischertitel}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.title??> + <#assign title = "Titel"> + <#assign value = "${p.title}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.geschlecht??> + <#assign title = "Geschlecht"> + <#assign value = "${p.geschlecht}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.familienstand??> + <#assign title = "Familienstand"> + <#assign value = "${p.familienstand}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.beruf??> + <#assign title = "Beruf"> + <#assign value = "${p.beruf}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.religion??> + <#assign title = "Religion"> + <#assign value = "${p.religion}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.geburtsdatum??> + <#assign title = "Geburtsdatum"> + <#assign value = "${p.geburtsdatum}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.geburtsort??> + <#assign title = "Geburtsort"> + <#assign value = "${p.geburtsort}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.sterbedatum??> + <#assign title = "Sterbedatum"> + <#assign value = "${p.sterbedatum}"> + <#include "parlamentarierAttribut.ftl"> + + + <#if p.vita??> + <#assign title = "Vita"> + <#assign value = "${p.vita}"> + <#include "parlamentarierAttribut.ftl"> + + + +
diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/FileObjectFactory.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/FileObjectFactory.java new file mode 100644 index 0000000..1b88fcf --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/FileObjectFactory.java @@ -0,0 +1,63 @@ +package org.texttechnologylab.project.gruppe_05_1.xml; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.*; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker; +import org.texttechnologylab.project.gruppe_05_1.xml.mdb.*; +import org.texttechnologylab.project.gruppe_05_1.xml.speaker.Speaker_File_Impl; +import org.w3c.dom.Node; + +public class FileObjectFactory { + + private static FileObjectFactory oFactory = null; + + /** + * + * @return FileObjectFactory + */ + public static FileObjectFactory getFactory() { + if (oFactory == null) { + oFactory = new FileObjectFactory(); + } + return oFactory; + } + + /* + * *** MDB Strukturen *** + * ===================== + */ + public BiografischeAngaben createBiografischeAngaben(Node node) { + return new BiografischeAngaben_File_Impl().fromXmlNode(node); + } + + public Institution createInstitution(Node node) { + return new Institution_File_Impl().fromXmlNode(node); + } + + + public Mdb createMdb(Node node) { + return new Mdb_File_Impl().fromXmlNode(node); + } + + + public MdbDocument createMdbDocument(Node node) { + return new MdbDocument_File_Impl().fromXmlNode(node); + } + + public MdbName createMdbName(Node node) { + return new MdbName_File_Impl().fromXmlNode(node); + } + + public Wahlperiode createWahlperiode(Node node) { + return new Wahlperiode_File_Impl().fromXmlNode(node); + } + + /* + * *** Redner- Strukturen *** + * ===================== + */ + + public Speaker createSpeaker(Node node) { + return new Speaker_File_Impl().fromXmlNode(node); + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/XmlOperations.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/XmlOperations.java new file mode 100644 index 0000000..ff2fc96 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/XmlOperations.java @@ -0,0 +1,8 @@ +package org.texttechnologylab.project.gruppe_05_1.xml; + +import org.w3c.dom.Node; + +public interface XmlOperations { + FileObjectFactory factory = FileObjectFactory.getFactory(); + public Object fromXmlNode(Node node); +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/BiografischeAngaben_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/BiografischeAngaben_File_Impl.java new file mode 100644 index 0000000..c49f1bd --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/BiografischeAngaben_File_Impl.java @@ -0,0 +1,74 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.mdb; + +import org.texttechnologylab.project.gruppe_05_1.domain.Gender; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.BiografischeAngaben; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +public class BiografischeAngaben_File_Impl extends BiografischeAngaben implements XmlOperations { + @Override + public BiografischeAngaben fromXmlNode(Node node) { + Node current = node.getFirstChild(); + Node child; + BiografischeAngaben bio = new BiografischeAngaben_File_Impl(); + while (null != current) { + child = current.getFirstChild(); + switch (current.getNodeName()) { + case "GEBURTSDATUM": + bio.setGeburtsdatum(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "GEBURTSORT": + bio.setGeburtsort(null == child ? null : child.getNodeValue()); + break; + + case "GEBURTSLAND": + bio.setGeburtsland(null == child ? null : child.getNodeValue()); + break; + + case "STERBEDATUM": + bio.setSterbedatum(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "GESCHLECHT": + bio.setGender(null == child ? null : child.getNodeValue()); + break; + + case "FAMILIENSTAND": + bio.setFamilienstand(null == child ? null : child.getNodeValue()); + break; + + case "RELIGION": + bio.setReligion(null == child ? null : child.getNodeValue()); + break; + + case "BERUF": + bio.setBeruf(null == child ? null : child.getNodeValue()); + break; + + case "PARTEI_KURZ": + bio.setParteiKuerzel(null == child ? null : child.getNodeValue()); + break; + + case "VITA_KURZ": + bio.setVitaKurz(null == child ? null : child.getNodeValue()); + break; + + case "VEROEFFENTLICHUNGSPFLICHTIGES": + bio.setVeroeffentlichungspflichtiges(null == child ? null : child.getNodeValue()); + break; + + case "#text": + break; + + default: + System.err.println("Node name does not match anything known in BiografischeAngaben: " + current.getNodeName()); + } + + current = current.getNextSibling(); + } + + return bio; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Institution_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Institution_File_Impl.java new file mode 100644 index 0000000..3214e35 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Institution_File_Impl.java @@ -0,0 +1,58 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.mdb; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Institution; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +public class Institution_File_Impl extends Institution implements XmlOperations { + @Override + public Institution fromXmlNode(Node node) { + + Node current = node.getFirstChild(); + Node child; + Institution inst = new Institution_File_Impl(); + while (null != current) { + child = current.getFirstChild(); + switch (current.getNodeName()) { + + case "INSART_LANG": + inst.setInsartLang(null == child ? null : child.getNodeValue()); + break; + + case "INS_LANG": + inst.setInsLang(null == child ? null : child.getNodeValue()); + break; + + case "MDBINS_VON": + inst.setMdbinsVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "MDBINS_BIS": + inst.setMdbinsBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "FKT_LANG": + inst.setFktLang(null == child ? null : child.getNodeValue()); + break; + + case "FKTINS_VON": + inst.setFktinsVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "FKTINS_BIS": + inst.setFktinsBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "#text": + break; + + default: + System.err.println("Node name does not match anything known in Institution: " + current.getNodeName()); + } + current = current.getNextSibling(); + } + + return inst; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbDocument_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbDocument_File_Impl.java new file mode 100644 index 0000000..0dc96cb --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbDocument_File_Impl.java @@ -0,0 +1,30 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.mdb; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Mdb; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbDocument; +import org.texttechnologylab.project.gruppe_05_1.util.XmlUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +import java.util.ArrayList; +import java.util.List; + +public class MdbDocument_File_Impl extends MdbDocument implements XmlOperations { + @Override + public MdbDocument fromXmlNode(Node node) { + MdbDocument doc = new MdbDocument_File_Impl(); + + Node versionNode = XmlUtils.getFirstChildByName(node, "VERSION"); + doc.setVersion(versionNode.getFirstChild().getNodeValue()); + + List mdbs = new ArrayList<>(); + List mdbNodeList = XmlUtils.getChildrenByName(node, "MDB"); + for (Node mdbNode : mdbNodeList) { + Mdb mdb = factory.createMdb(mdbNode); + mdbs.add(mdb); + } + doc.setMdbs(mdbs); + + return doc; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbName_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbName_File_Impl.java new file mode 100644 index 0000000..ed57ee8 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/MdbName_File_Impl.java @@ -0,0 +1,66 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.mdb; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbName; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +public class MdbName_File_Impl extends MdbName implements XmlOperations { + @Override + public MdbName fromXmlNode(Node node) { + Node current = node.getFirstChild(); + Node child; + MdbName name = new MdbName_File_Impl(); + + while (null != current) { + child = current.getFirstChild(); + switch (current.getNodeName()) { + case "NACHNAME": + name.setNachname(null == child ? null : child.getNodeValue()); + break; + + case "VORNAME": + name.setVorname(null == child ? null : child.getNodeValue()); + break; + + case "ORTSZUSATZ": + name.setOrtszusatz(null == child ? null : child.getNodeValue()); + break; + + case "ADEL": + name.setAdel(null == child ? null : child.getNodeValue()); + break; + + case "PRAEFIX": + name.setPraefix(null == child ? null : child.getNodeValue()); + break; + + case "ANREDE_TITEL": + name.setAndereTitel(null == child ? null : child.getNodeValue()); + break; + + case "AKAD_TITEL": + name.setAkadTitel(null == child ? null : child.getNodeValue()); + break; + + case "HISTORIE_VON": + name.setHistorieVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "HISTORIE_BIS": + name.setHistorieBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "#text": + break; + + default: + System.err.println("Node name does not match anything known in Name: " + current.getNodeName()); + } + + current = current.getNextSibling(); + } + + return name; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Mdb_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Mdb_File_Impl.java new file mode 100644 index 0000000..c651c07 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Mdb_File_Impl.java @@ -0,0 +1,44 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.mdb; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Mdb; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbName; +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Wahlperiode; +import org.texttechnologylab.project.gruppe_05_1.util.XmlUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +import java.util.ArrayList; +import java.util.List; + +public class Mdb_File_Impl extends Mdb implements XmlOperations { + @Override + public Mdb fromXmlNode(Node node) { + Mdb mdb = new Mdb_File_Impl(); + Node idNode = XmlUtils.getFirstChildByName(node, "ID"); + mdb.setId(idNode.getFirstChild().getNodeValue()); + + Node namenNode = XmlUtils.getFirstChildByName(node, "NAMEN"); + List nameNodeList = XmlUtils.getChildrenByName(namenNode, "NAME"); + List mdbNameList = new ArrayList<>(); + for (Node nameNode : nameNodeList) { + MdbName mdbName = factory.createMdbName(nameNode); + mdbNameList.add(mdbName); + } + mdb.setNamen(mdbNameList); + + Node bioNode = XmlUtils.getFirstChildByName(node, "BIOGRAFISCHE_ANGABEN"); + mdb.setBio(factory.createBiografischeAngaben(bioNode)); + + + Node wpenNode = XmlUtils.getFirstChildByName(node, "WAHLPERIODEN"); + List wpNodeList = XmlUtils.getChildrenByName(wpenNode, "WAHLPERIODE"); + List wpList = new ArrayList<>(); + for (Node wpNode : wpNodeList) { + Wahlperiode wp = factory.createWahlperiode(wpNode); + wpList.add(wp); + } + mdb.setWahlperioden(wpList); + + return mdb; + } +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Wahlperiode_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Wahlperiode_File_Impl.java new file mode 100644 index 0000000..c3483a8 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/mdb/Wahlperiode_File_Impl.java @@ -0,0 +1,82 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.mdb; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.*; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; +import org.texttechnologylab.project.gruppe_05_1.util.XmlUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +import java.util.ArrayList; +import java.util.List; + +public class Wahlperiode_File_Impl extends Wahlperiode implements XmlOperations { + @Override + public Wahlperiode fromXmlNode(Node node) { + + Node current = node.getFirstChild(); + Node child; + Wahlperiode wp = new Wahlperiode_File_Impl(); + while (null != current) { + child = current.getFirstChild(); + switch (current.getNodeName()) { + case "WP": + wp.setWp(null == child ? null : GeneralUtils.parseInt(child.getNodeValue())); + break; + + case "MDBWP_VON": + wp.setMdbWpVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "MDBWP_BIS": + wp.setMdbWpBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue())); + break; + + case "WKR_NUMMER": + wp.setWknNr(null == child ? null : child.getNodeValue()); + break; + + case "WKR_NAME": + wp.setWkrName(null == child ? null : child.getNodeValue()); + break; + + case "WKR_LAND": + wp.setWkrLand(null == child ? null : child.getNodeValue()); + break; + + case "LISTE": + wp.setListe(null == child ? null : child.getNodeValue()); + break; + + case "MANDATSART": + if (null == child) { + wp.setMandatsart(Mandatsart.NA); + } else { + wp.setMandatsart(Mandatsart.byText(child.getNodeValue())); + } + break; + + case "INSTITUTIONEN": + // Node institutionenNode = XmlUtils.getFirstChildByName(node, "INSTITUTIONEN"); + List institutionNodeList = XmlUtils.getChildrenByName(current, "INSTITUTION"); + List institutionList = new ArrayList<>(); + for (Node institutionNode : institutionNodeList) { + Institution inst = factory.createInstitution(institutionNode); + institutionList.add(inst); + } + wp.setInstitutionen(institutionList); + break; + + case "#text": + break; + + default: + System.err.println("Node name does not match anything known in Wahlperiode: " + current.getNodeName()); + } + + current = current.getNextSibling(); + } + + return wp; + } + +} diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/speaker/Speaker_File_Impl.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/speaker/Speaker_File_Impl.java new file mode 100644 index 0000000..1e64039 --- /dev/null +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/xml/speaker/Speaker_File_Impl.java @@ -0,0 +1,89 @@ +package org.texttechnologylab.project.gruppe_05_1.xml.speaker; + +import org.texttechnologylab.project.gruppe_05_1.domain.mdb.*; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership; +import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker; +import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils; +import org.texttechnologylab.project.gruppe_05_1.util.PPRUtils; +import org.texttechnologylab.project.gruppe_05_1.util.XmlUtils; +import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations; +import org.w3c.dom.Node; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class Speaker_File_Impl extends Speaker implements XmlOperations { + @Override + public Speaker fromXmlNode(Node node) { + Speaker speaker = new Speaker_File_Impl(); + + // ID + Node idNode = XmlUtils.getFirstChildByName(node, "ID"); + speaker.setId(idNode.getFirstChild().getNodeValue()); + + // Name: alle Namen lesen, nur den letzten berücksichtigen + Node namenNode = XmlUtils.getFirstChildByName(node, "NAMEN"); + List nameNodeList = XmlUtils.getChildrenByName(namenNode, "NAME"); + List mdbNameList = new ArrayList<>(); + for (Node nameNode : nameNodeList) { + MdbName mdbName = factory.createMdbName(nameNode); + mdbNameList.add(mdbName); + } + mdbNameList.sort((n1, n2 )-> n2.getHistorieVon().compareTo(n1.getHistorieVon())); // Descending order + MdbName newestMdbName = mdbNameList.get(0); // TODO + speaker.setName(newestMdbName.getNachname()); + speaker.setFirstName(newestMdbName.getVorname()); + speaker.setAkademischertitel(newestMdbName.getAkadTitel()); + speaker.setTitle(newestMdbName.getAndereTitel()); + + // Biografische Daten: + Node bioNode = XmlUtils.getFirstChildByName(node, "BIOGRAFISCHE_ANGABEN"); + BiografischeAngaben bio = factory.createBiografischeAngaben(bioNode); + if (bio.getGeburtsland() == null || bio.getGeburtsland().isBlank()) { + speaker.setGeburtsort(bio.getGeburtsort()); + } else { + speaker.setGeburtsort(bio.getGeburtsort() + " (" + bio.getGeburtsland() + ")"); + } + speaker.setGeburtsdatum(bio.getGeburtsdatum()); + speaker.setSterbedatum(bio.getSterbedatum()); + speaker.setGeschlecht(bio.getGender()); + speaker.setBeruf(bio.getBeruf()); + speaker.setFamilienstand(bio.getFamilienstand()); + speaker.setReligion(bio.getReligion()); + speaker.setVita(bio.getVitaKurz()); + + // Da wir nach Partei sortieren und vergleichen, darf das Feld nicht null sein... + speaker.setParty(bio.getParteiKuerzel() == null ? PPRUtils.PARTEILOS_KUERZEL : bio.getParteiKuerzel()); + + // Memberships + Node wpenNode = XmlUtils.getFirstChildByName(node, "WAHLPERIODEN"); + List wpNodeList = XmlUtils.getChildrenByName(wpenNode, "WAHLPERIODE"); + List wpList = new ArrayList<>(); + for (Node wpNode : wpNodeList) { + Wahlperiode wp = factory.createWahlperiode(wpNode); + wpList.add(wp); + } + wpList.sort((wp1, wp2 )-> wp2.getMdbWpVon().compareTo(wp1.getMdbWpVon())); // Descending order + List memberships = new ArrayList<>(); + for (Wahlperiode wp : wpList) { + LocalDate mdbwpVon = wp.getMdbWpVon(); + LocalDate mdbwpBis = wp.getMdbWpBis(); + + for (Institution inst : wp.getInstitutionen()) { + Membership m = new Membership(); + m.setBegin(inst.getMdbinsVon() == null? mdbwpVon : inst.getMdbinsVon()); + m.setEnd(inst.getFktinsBis() == null? mdbwpBis : inst.getFktinsBis()); + m.setRole(inst.getFktLang()); + m.setLabel(inst.getInsLang()); + m.setWp(wp.getWp()); + + memberships.add(m); + } + + } + speaker.setMemberships(memberships); + + return speaker; + } +} diff --git a/src/main/resources/.DS_Store b/src/main/resources/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..558c0a3d69821fe11caa8220681a138569846b17 GIT binary patch literal 6148 zcmeHKu};G<5PfbdR0Km{V$8x${~%Q13%W5uT2v4Ti7L8hWk7rhJNy72z>N3-eu8(l z)y9NUSP(*Y()l^(JNx|7=4=3FIG+rF2tc1I*x6+BiO9HUOFG`NO*AscU^Fg^s^zDK zzsrEUyDkb$kmb|X`|~43nWkA@X7rUG!p_~p)8R6%C?{WxR_Co*BUH$7hAW(6#{LW? zuBn&QTt>o7_TRYH+L&gJx6e2CyN@=6GAAuSZ+LWwTa_$!8S;k3uzFY#DAbm1^|WzOSQHvWcU{0Yd! z)*U8ssI4-f41^4H-D4#6|7i97KMc|*Wk4DDR}7e5I!cG!lCQ0;%}K3|sV7ts@v9v! kLfEmTn7&eq_o!BAkEKIQJk}0rq3A)t(x8np@T&~G0}@VjjQ{`u literal 0 HcmV?d00001 diff --git a/src/main/resources/javalin.properties b/src/main/resources/javalin.properties new file mode 100644 index 0000000..44ba1a4 --- /dev/null +++ b/src/main/resources/javalin.properties @@ -0,0 +1 @@ +port=5876 \ No newline at end of file diff --git a/src/main/resources/mongoDB.properties b/src/main/resources/mongoDB.properties new file mode 100644 index 0000000..31df9ae --- /dev/null +++ b/src/main/resources/mongoDB.properties @@ -0,0 +1,7 @@ +localserver_x_nur_testing=mongodb://localhost:27017 +remote_host = ppr.lehre.texttechnologylab.org +remote_database = PPR_WiSe24_Project_5_1 +remote_user = PPR_WiSe24_Project_5_1_rw +remote_password = E7H3ICPG +remote_port = 27020 +remote_collection = speeches \ No newline at end of file diff --git a/src/main/resources/mongoDB_Uebung2.properties b/src/main/resources/mongoDB_Uebung2.properties new file mode 100644 index 0000000..098c8c7 --- /dev/null +++ b/src/main/resources/mongoDB_Uebung2.properties @@ -0,0 +1,7 @@ +localserver=mongodb://localhost:27017 +remote_host=ppr.lehre.texttechnologylab.org +remote_database=PPR_WiSe24_264 +remote_user=PPR_WiSe24_264_rw +remote_password=XPs5GfDf +remote_port=27020 +remote_collection=speeches \ No newline at end of file diff --git a/src/main/resources/plenarprotokolle/dbtplenarprotokoll.dtd b/src/main/resources/plenarprotokolle/dbtplenarprotokoll.dtd new file mode 100644 index 0000000..a8a4429 --- /dev/null +++ b/src/main/resources/plenarprotokolle/dbtplenarprotokoll.dtd @@ -0,0 +1,298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html new file mode 100644 index 0000000..7f481fd --- /dev/null +++ b/src/main/resources/public/index.html @@ -0,0 +1,9 @@ + + + + +

Heading

+

paragraph.

+ + + \ No newline at end of file diff --git a/src/main/resources/xml.properties b/src/main/resources/xml.properties new file mode 100644 index 0000000..c677e25 --- /dev/null +++ b/src/main/resources/xml.properties @@ -0,0 +1,7 @@ +mdb_url=https://www.bundestag.de/resource/blob/472878/4d360eba29319547ed7fce385335a326/MdB-Stammdaten-data.zip + +# TODO: cleanup... +mdb_file_name=mdb/MDB_STAMMDATEN.XML +mdb_full_file_name=mdb/MDB_STAMMDATEN.XML +mdb_short_file_name=mdb/MDB_STAMMDATEN_SHORT.XML +protokolle_dir=plenarprotokolle \ No newline at end of file