{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import psycopg2\n", "\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "from langchain_community.document_loaders import DataFrameLoader\n", "from langchain_community.embeddings import HuggingFaceEmbeddings\n", "from langchain_community.vectorstores import FAISS\n", "from datetime import datetime\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Retrieve Speeches" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# db_connection -----------------------------------------------------------\n", "con_details = {\n", " \"host\" : \"localhost\",\n", " \"database\" : \"next\",\n", " \"user\" : \"postgres\",\n", " \"password\" : \"postgres\",\n", " \"port\" : \"5433\"\n", "}\n", "con = psycopg2.connect(**con_details)\n", "\n", "# get data tables ---------------------------------------------------------\n", "df = pd.read_sql_query(\"\"\"SELECT s.id,s.speech_content,s.date,f.abbreviation AS party\n", " FROM open_discourse.speeches AS s\n", " INNER JOIN open_discourse.factions AS f ON\n", " s.faction_id = f.id;\"\"\", con)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Process speeches" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(set(df['party'].to_list()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Removing keys from interruptions of a speech\n", "df[\"speech_content\"].replace(\"\\({\\d+}\\)\", \"\", inplace=True, regex=True) \n", "df['date'] = pd.to_datetime(df['date'])\n", "df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | id | \n", "speech_content | \n", "date | \n", "party | \n", "
---|---|---|---|---|
0 | \n", "0 | \n", "Meine Damen und Herren! Ich eröffne die 2. Sit... | \n", "1949-09-12 | \n", "not found | \n", "
1 | \n", "1 | \n", "Der Bundesrat ist versammelt, Herr Präsident.\\n | \n", "1949-09-12 | \n", "not found | \n", "
2 | \n", "2 | \n", "Ich danke für diese Erklärung. Ich stelle dami... | \n", "1949-09-12 | \n", "not found | \n", "
3 | \n", "3 | \n", "Ja, ich habe den Wunsch.\\n | \n", "1949-09-12 | \n", "not found | \n", "
4 | \n", "4 | \n", "Ich erteile dem Herrn Bundespräsidenten das Wo... | \n", "1949-09-12 | \n", "not found | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
930955 | \n", "1084268 | \n", "\\n\\nWir sind zwar Kollegen. | \n", "2022-12-16 | \n", "not found | \n", "
930956 | \n", "1084269 | \n", "\\n\\nLiebe, sehr geehrte Frau Präsidentin! | \n", "2022-12-16 | \n", "CDU/CSU | \n", "
930957 | \n", "1084270 | \n", "\\n\\nVielen Dank. | \n", "2022-12-16 | \n", "not found | \n", "
930958 | \n", "1084272 | \n", "\\n\\nDen Abschluss dieser Aktuellen Stunde bild... | \n", "2022-12-16 | \n", "not found | \n", "
930959 | \n", "1084273 | \n", "\\n\\nSehr geehrte Frau Präsidentin! Werte Kolle... | \n", "2022-12-16 | \n", "SPD | \n", "
930960 rows × 4 columns
\n", "