{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7a3837ac-cced-4e01-bf57-265e40729692",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import re\n",
    "import numpy as np\n",
    "import thefuzz\n",
    "from tqdm.notebook import tqdm\n",
    "import matplotlib.pyplot as plt\n",
    "import requests\n",
    "import json\n",
    "from IPython.display import display\n",
    "\n",
    "pd.set_option('display.max_colwidth', None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "29ca0dc8-cae7-4f12-bd60-fd74ea6ae5ac",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "BE_df = pd.read_excel('../Daten/Vorhersagen/Katalogauszug und Vorhersagen.xlsx', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c1e1c42a-962f-40bc-bb17-b62e8089feb7",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "entry_df = pd.read_excel('../Daten/Katalogabgleich/Einträge.xlsx', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "50d15898-4687-46b7-b7e0-528d7cf9aec0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def prepare_string(string):\n",
    "    new = re.sub(r'[àáâãå]', 'a', string)\n",
    "    new = re.sub(r'[èéêë]', 'e', new)\n",
    "    new = re.sub(r'[ìíîï]', 'i', new)\n",
    "    new = re.sub(r'[òóôõ]', 'o', new)\n",
    "    new = re.sub(r'[ùúû]', 'u', new)\n",
    "    new = re.sub(r'æ', 'ae', new)\n",
    "    new = re.sub('[.,:;()¬]|^[CLXVI]+? |^\\d+? |^\\d+?\\.+? |^\\.+ ?|= |# ', '', new)\n",
    "    return new\n",
    "\n",
    "entry_df['cleaned entry'] = entry_df['entry'].apply(lambda x: prepare_string(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "990dfeee-1141-4acb-8a3d-a7af0573f5be",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "BE_early = BE_df[BE_df['Anfang Veröffentlichungsdatum'] < 1736]\n",
    "BE_early_no_dup = BE_early.drop_duplicates('Titel')\n",
    "BE_no_year = BE_df[BE_df['Anfang Veröffentlichungsdatum'].isna()].drop_duplicates('Titel')\n",
    "BE_manual = BE_df.loc[BE_early_no_dup.index.union(BE_no_year.index)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "bcd301fe-cb80-4b1c-b65f-465fce5ed915",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['BE.1.T.33', '+Z167651701',\n",
       "        \"Les deux livres de S. Augustin, de la veritable religion et des moeurs de l'eglise catholique, traduits en francois, sur l'edition latine des Peres Benedictins de la congregation de S. Maur\",\n",
       "        'Augustinus, Aurelius Heiliger 354-430', nan, 1693.0, nan,\n",
       "        '1693', 'Paris', 'Paris', 'French', nan, nan, nan, nan, nan,\n",
       "        'Z167651701', 'Z167651701_00000001.jpg', 'B', 0.0008314285660162,\n",
       "        0.9985696077346802, 0.0003245634725317, 0.0002743884397204,\n",
       "        'blue', 0.9836959838867188, 0.0060312687419354,\n",
       "        0.0102726686745882]], dtype=object)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BE_manual[BE_manual['Signatur'].str.contains('BE.1.T.33')].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "c0f4a42a-7e21-41e8-833c-2dd2f9d1985e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume</th>\n",
       "      <th>page number</th>\n",
       "      <th>category</th>\n",
       "      <th>subcategory</th>\n",
       "      <th>format</th>\n",
       "      <th>handwritten page number</th>\n",
       "      <th>entry_ID</th>\n",
       "      <th>entry</th>\n",
       "      <th>cleaned entry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3144</th>\n",
       "      <td>14.377</td>\n",
       "      <td>65</td>\n",
       "      <td>Poëtica</td>\n",
       "      <td>Poëtæ Latini Recentiores, cum Germanicis</td>\n",
       "      <td>Octavo und kleiner</td>\n",
       "      <td>473</td>\n",
       "      <td>14.377_065_01</td>\n",
       "      <td>Pontani (I. Ioviani) Poëmata. 8.° Venet. 1505. Aldus. n. 755.</td>\n",
       "      <td>Pontani I Ioviani Poemata 8° Venet 1505 Aldus n 755</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4347</th>\n",
       "      <td>14.377</td>\n",
       "      <td>185</td>\n",
       "      <td>Philologia</td>\n",
       "      <td>Operum Latinorum varij Argumenti Collectiones</td>\n",
       "      <td>Folio</td>\n",
       "      <td>581</td>\n",
       "      <td>14.377_185_06</td>\n",
       "      <td>1021 Pontani (I. Ioviani) opera varij Argumenti; Ven. 1501. Bernardinus Vercellensis. n. 2216.</td>\n",
       "      <td>Pontani I Ioviani opera varij Argumenti Ven 1501 Bernardinus Vercellensis n 2216</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5892</th>\n",
       "      <td>14.377</td>\n",
       "      <td>455</td>\n",
       "      <td>Historia Antiqua</td>\n",
       "      <td>Historia Imperii Orientalis, Seu Bysantina</td>\n",
       "      <td>Folio</td>\n",
       "      <td>843</td>\n",
       "      <td>14.377_455_01</td>\n",
       "      <td>1472 Cantacuzeni Ex-Imperatoris (Ioan.) Historiarum Libri IV. græcè ac latinè, Iacobo Pontano interpréte cum ipsius &amp; Ioan. Gretseri notis. 3 Vol. Parisiis. 1645. è Typograph. Regiâ. n. 1421.</td>\n",
       "      <td>Cantacuzeni Ex-Imperatoris Ioan Historiarum Libri IV graece ac latine Iacobo Pontano interprete cum ipsius &amp; Ioan Gretseri notis 3 Vol Parisiis 1645 e Typograph Regia n 1421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5895</th>\n",
       "      <td>14.377</td>\n",
       "      <td>455</td>\n",
       "      <td>Historia Antiqua</td>\n",
       "      <td>Historia Imperii Orientalis, Seu Bysantina</td>\n",
       "      <td>Folio</td>\n",
       "      <td>843</td>\n",
       "      <td>14.377_455_04</td>\n",
       "      <td>1475 Theophilacti Simocattæ Historiarum Libri VIII. gr. &amp; Latinè Iac. Pontano interprete, cum Fabrotti emendationibus ac Augmento. Paris. 1647. è Typograph. Reg. accedit S. Nycephori Patriarchæ Constantinop. Breviarium¬ historicum græcè ac latine Dionys. Petavio interprete cum notis. Paris. 1648. è Typograph. Regiâ. n. 1424.</td>\n",
       "      <td>Theophilacti Simocattae Historiarum Libri VIII gr &amp; Latine Iac Pontano interprete cum Fabrotti emendationibus ac Augmento Paris 1647 e Typograph Reg accedit S Nycephori Patriarchae Constantinop Breviarium historicum graece ac latine Dionys Petavio interprete cum notis Paris 1648 e Typograph Regia n 1424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6019</th>\n",
       "      <td>14.378</td>\n",
       "      <td>30</td>\n",
       "      <td>Historia Nova Europæ</td>\n",
       "      <td>Canonum collectores &amp; Canonistæ; Epistolæ decretales &amp; Bullæ; necnon de Hierarchiâ &amp; Rebus Ecclesiasticis</td>\n",
       "      <td>Quarto</td>\n",
       "      <td>870</td>\n",
       "      <td>14.378_030_03</td>\n",
       "      <td>Discorso di Fabio Pontano Sopra l'Antichità di Foligno. in Perugia. 1618. Mario Naccarini. n. 493.</td>\n",
       "      <td>Discorso di Fabio Pontano Sopra l'Antichita di Foligno in Perugia 1618 Mario Naccarini n 493</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6089</th>\n",
       "      <td>14.378</td>\n",
       "      <td>43</td>\n",
       "      <td>Historia Nova Europæ</td>\n",
       "      <td>Historia Neapolitana generalis &amp; Singularis Historia Sicula generalis &amp; Singularis</td>\n",
       "      <td>Octavo und kleiner</td>\n",
       "      <td>883</td>\n",
       "      <td>14.378_043_00</td>\n",
       "      <td>Historia Neapolitana, autoribus Pandulpho Collenutio &amp; Ioanne Ioviano Pontano. Dordrechti. 1618. Berestout. n. 116.</td>\n",
       "      <td>Historia Neapolitana autoribus Pandulpho Collenutio &amp; Ioanne Ioviano Pontano Dordrechti 1618 Berestout n 116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6990</th>\n",
       "      <td>14.378</td>\n",
       "      <td>190</td>\n",
       "      <td>Historia Nova Europæ</td>\n",
       "      <td>Historia generalis &amp; Singularis Belgij Foederati</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1028</td>\n",
       "      <td>14.378_190_01</td>\n",
       "      <td>2000 Pontani (Ioan. Isaaci) Historiæ Gelricæ Libri XIV. ab anno ante Christum 57. ad Annum Chr. 1581. cum figuris. Hardervici Gelrorum. 1639. Iansson n. 1740.</td>\n",
       "      <td>Pontani Ioan Isaaci Historiae Gelricae Libri XIV ab anno ante Christum 57 ad Annum Chr 1581 cum figuris Hardervici Gelrorum 1639 Iansson n 1740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7124</th>\n",
       "      <td>14.378</td>\n",
       "      <td>214</td>\n",
       "      <td>Historia Nova Europæ</td>\n",
       "      <td>Historia Hispanica generalis &amp; aliquot temporum; Vitæ Regum; aliaque</td>\n",
       "      <td>Quarto</td>\n",
       "      <td>1052</td>\n",
       "      <td>14.378_214_05</td>\n",
       "      <td>Bracelli (Jac.) de Bello Hispanico Libri V. quibus accedunt I. Ioviani Pontani de Bello Neapolitano Libri VI. Haganoæ. 1530. I. Secerius n. 785.</td>\n",
       "      <td>Bracelli Jac de Bello Hispanico Libri V quibus accedunt I Ioviani Pontani de Bello Neapolitano Libri VI Haganoae 1530 I Secerius n 785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7332</th>\n",
       "      <td>14.378</td>\n",
       "      <td>257</td>\n",
       "      <td>Historia Nova Europæ</td>\n",
       "      <td>Regionum Septentrionalium nempe Daniæ, Norwegiæ, Lapponiæ, Islandiæ, Sueciæ, ac Livoniæ Historia</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1095</td>\n",
       "      <td>14.378_257_06</td>\n",
       "      <td>2125 Pontani (Isaaci) Rerum Danicarum Historia ab anno ante Christum III. ad Ann. Chr. 1448. cum Regni Chorographiâ. Hardervici Gelror. 1631. Nic. a Wiering. n. 1929.</td>\n",
       "      <td>Pontani Isaaci Rerum Danicarum Historia ab anno ante Christum III ad Ann Chr 1448 cum Regni Chorographia Hardervici Gelror 1631 Nic a Wiering n 1929</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      volume  page number              category   \n",
       "3144  14.377           65               Poëtica  \\\n",
       "4347  14.377          185            Philologia   \n",
       "5892  14.377          455      Historia Antiqua   \n",
       "5895  14.377          455      Historia Antiqua   \n",
       "6019  14.378           30  Historia Nova Europæ   \n",
       "6089  14.378           43  Historia Nova Europæ   \n",
       "6990  14.378          190  Historia Nova Europæ   \n",
       "7124  14.378          214  Historia Nova Europæ   \n",
       "7332  14.378          257  Historia Nova Europæ   \n",
       "\n",
       "                                                                                                    subcategory   \n",
       "3144                                                                   Poëtæ Latini Recentiores, cum Germanicis  \\\n",
       "4347                                                              Operum Latinorum varij Argumenti Collectiones   \n",
       "5892                                                                 Historia Imperii Orientalis, Seu Bysantina   \n",
       "5895                                                                 Historia Imperii Orientalis, Seu Bysantina   \n",
       "6019  Canonum collectores & Canonistæ; Epistolæ decretales & Bullæ; necnon de Hierarchiâ & Rebus Ecclesiasticis   \n",
       "6089                         Historia Neapolitana generalis & Singularis Historia Sicula generalis & Singularis   \n",
       "6990                                                           Historia generalis & Singularis Belgij Foederati   \n",
       "7124                                       Historia Hispanica generalis & aliquot temporum; Vitæ Regum; aliaque   \n",
       "7332           Regionum Septentrionalium nempe Daniæ, Norwegiæ, Lapponiæ, Islandiæ, Sueciæ, ac Livoniæ Historia   \n",
       "\n",
       "                  format handwritten page number       entry_ID   \n",
       "3144  Octavo und kleiner                     473  14.377_065_01  \\\n",
       "4347               Folio                     581  14.377_185_06   \n",
       "5892               Folio                     843  14.377_455_01   \n",
       "5895               Folio                     843  14.377_455_04   \n",
       "6019              Quarto                     870  14.378_030_03   \n",
       "6089  Octavo und kleiner                     883  14.378_043_00   \n",
       "6990               Folio                    1028  14.378_190_01   \n",
       "7124              Quarto                    1052  14.378_214_05   \n",
       "7332               Folio                    1095  14.378_257_06   \n",
       "\n",
       "                                                                                                                                                                                                                                                                                                                                       entry   \n",
       "3144                                                                                                                                                                                                                                                                           Pontani (I. Ioviani) Poëmata. 8.° Venet. 1505. Aldus. n. 755.  \\\n",
       "4347                                                                                                                                                                                                                                          1021 Pontani (I. Ioviani) opera varij Argumenti; Ven. 1501. Bernardinus Vercellensis. n. 2216.   \n",
       "5892                                                                                                                                         1472 Cantacuzeni Ex-Imperatoris (Ioan.) Historiarum Libri IV. græcè ac latinè, Iacobo Pontano interpréte cum ipsius & Ioan. Gretseri notis. 3 Vol. Parisiis. 1645. è Typograph. Regiâ. n. 1421.   \n",
       "5895  1475 Theophilacti Simocattæ Historiarum Libri VIII. gr. & Latinè Iac. Pontano interprete, cum Fabrotti emendationibus ac Augmento. Paris. 1647. è Typograph. Reg. accedit S. Nycephori Patriarchæ Constantinop. Breviarium¬ historicum græcè ac latine Dionys. Petavio interprete cum notis. Paris. 1648. è Typograph. Regiâ. n. 1424.   \n",
       "6019                                                                                                                                                                                                                                      Discorso di Fabio Pontano Sopra l'Antichità di Foligno. in Perugia. 1618. Mario Naccarini. n. 493.   \n",
       "6089                                                                                                                                                                                                                     Historia Neapolitana, autoribus Pandulpho Collenutio & Ioanne Ioviano Pontano. Dordrechti. 1618. Berestout. n. 116.   \n",
       "6990                                                                                                                                                                          2000 Pontani (Ioan. Isaaci) Historiæ Gelricæ Libri XIV. ab anno ante Christum 57. ad Annum Chr. 1581. cum figuris. Hardervici Gelrorum. 1639. Iansson n. 1740.   \n",
       "7124                                                                                                                                                                                        Bracelli (Jac.) de Bello Hispanico Libri V. quibus accedunt I. Ioviani Pontani de Bello Neapolitano Libri VI. Haganoæ. 1530. I. Secerius n. 785.   \n",
       "7332                                                                                                                                                                  2125 Pontani (Isaaci) Rerum Danicarum Historia ab anno ante Christum III. ad Ann. Chr. 1448. cum Regni Chorographiâ. Hardervici Gelror. 1631. Nic. a Wiering. n. 1929.   \n",
       "\n",
       "                                                                                                                                                                                                                                                                                                         cleaned entry  \n",
       "3144                                                                                                                                                                                                                                                               Pontani I Ioviani Poemata 8° Venet 1505 Aldus n 755  \n",
       "4347                                                                                                                                                                                                                                  Pontani I Ioviani opera varij Argumenti Ven 1501 Bernardinus Vercellensis n 2216  \n",
       "5892                                                                                                                                     Cantacuzeni Ex-Imperatoris Ioan Historiarum Libri IV graece ac latine Iacobo Pontano interprete cum ipsius & Ioan Gretseri notis 3 Vol Parisiis 1645 e Typograph Regia n 1421  \n",
       "5895  Theophilacti Simocattae Historiarum Libri VIII gr & Latine Iac Pontano interprete cum Fabrotti emendationibus ac Augmento Paris 1647 e Typograph Reg accedit S Nycephori Patriarchae Constantinop Breviarium historicum graece ac latine Dionys Petavio interprete cum notis Paris 1648 e Typograph Regia n 1424  \n",
       "6019                                                                                                                                                                                                                      Discorso di Fabio Pontano Sopra l'Antichita di Foligno in Perugia 1618 Mario Naccarini n 493  \n",
       "6089                                                                                                                                                                                                      Historia Neapolitana autoribus Pandulpho Collenutio & Ioanne Ioviano Pontano Dordrechti 1618 Berestout n 116  \n",
       "6990                                                                                                                                                                   Pontani Ioan Isaaci Historiae Gelricae Libri XIV ab anno ante Christum 57 ad Annum Chr 1581 cum figuris Hardervici Gelrorum 1639 Iansson n 1740  \n",
       "7124                                                                                                                                                                            Bracelli Jac de Bello Hispanico Libri V quibus accedunt I Ioviani Pontani de Bello Neapolitano Libri VI Haganoae 1530 I Secerius n 785  \n",
       "7332                                                                                                                                                              Pontani Isaaci Rerum Danicarum Historia ab anno ante Christum III ad Ann Chr 1448 cum Regni Chorographia Hardervici Gelror 1631 Nic a Wiering n 1929  "
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def search_in_entry(df, string):\n",
    "    return df[df['cleaned entry'].str.contains(string)]\n",
    "\n",
    "info = search_in_entry(search_in_entry(entry_df, 'Pontan'), '')\n",
    "print(len(info))\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "97b7a8d5-154c-4b7a-8d9e-a6bb3247a3c7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume</th>\n",
       "      <th>page number</th>\n",
       "      <th>category</th>\n",
       "      <th>subcategory</th>\n",
       "      <th>format</th>\n",
       "      <th>handwritten page number</th>\n",
       "      <th>entry_ID</th>\n",
       "      <th>entry</th>\n",
       "      <th>cleaned entry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1620</th>\n",
       "      <td>14.376</td>\n",
       "      <td>280</td>\n",
       "      <td>Historia Naturalis</td>\n",
       "      <td>Plantarum, Arborum, Fruticum &amp; Florum</td>\n",
       "      <td>Folio</td>\n",
       "      <td>240</td>\n",
       "      <td>14.376_280_05</td>\n",
       "      <td>451 Memoires pour l'Hist. des Plantes de L'acad. des Sciences. &amp;c. vide Imagines Pynacothecæ Regiæ.</td>\n",
       "      <td>Memoires pour l'Hist des Plantes de L'acad des Sciences &amp;c vide Imagines Pynacothecae Regiae</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      volume  page number            category   \n",
       "1620  14.376          280  Historia Naturalis  \\\n",
       "\n",
       "                                subcategory format handwritten page number   \n",
       "1620  Plantarum, Arborum, Fruticum & Florum  Folio                     240  \\\n",
       "\n",
       "           entry_ID   \n",
       "1620  14.376_280_05  \\\n",
       "\n",
       "                                                                                                    entry   \n",
       "1620  451 Memoires pour l'Hist. des Plantes de L'acad. des Sciences. &c. vide Imagines Pynacothecæ Regiæ.  \\\n",
       "\n",
       "                                                                                     cleaned entry  \n",
       "1620  Memoires pour l'Hist des Plantes de L'acad des Sciences &c vide Imagines Pynacothecae Regiae  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entry_df[entry_df['entry_ID'] == '14.376_280_05']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "c4394718-cfd3-459e-8923-3ef255a41012",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "volume                                                                                                                                       14.378\n",
       "page number                                                                                                                                     239\n",
       "category                                                                                                                       Historia Nova Europæ\n",
       "subcategory                                                                             Angliæ, Scotiæ, ac Hiberniæ Historia generalis & Singularis\n",
       "format                                                                                                                                        Folio\n",
       "handwritten page number                                                                                                                        1077\n",
       "entry_ID                                                                                                                              14.378_239_06\n",
       "entry                      2107 Boethij (Hectoris) Scotorum Historiæ a Gentis Orig. cum Ioan. Ferrerij continuatione. Paris. 1557. du Puys. n. 1917\n",
       "cleaned entry                           Boethij Hectoris Scotorum Historiae a Gentis Orig cum Ioan Ferrerij continuatione Paris 1557 du Puys n 1917\n",
       "Name: 7242, dtype: object"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entry_df.loc[7242]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "20facf5d-d609-498e-9907-7ebdffc09e15",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BE.1.A.10\n",
      "B1214205\n",
      "Antiquites du Bosphore Cimmerien conservees au Musee Imperial de l'Ermitage = Drevnosti Bosfora Kimmerijskago\n",
      "nan\n",
      "St. Petersburg\n",
      "nan\n",
      "nan\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Signatur                                                                                                                                                                                                                                                                                                                                                                              BE.1.A.10\n",
       "Barcode                                                                                                                                                                                                                                                                                                                                                                                B1214205\n",
       "Titel                                                                                                                                                                                                                                                                             Antiquites du Bosphore Cimmerien conservees au Musee Imperial de l'Ermitage = Drevnosti Bosfora Kimmerijskago\n",
       "Autor                                                                                                                                                                                                                                                                                                                                                                                       NaN\n",
       "Mitwirkender                                                                                                                                                                                                                                                                                                                                                            Gosudarstvennyj Ėrmitaž\n",
       "Anfang Veröffentlichungsdatum                                                                                                                                                                                                                                                                                                                                                               NaN\n",
       "Ende Veröffentlichungsdatum                                                                                                                                                                                                                                                                                                                                                                 NaN\n",
       "Veröffentlichungsdatum                                                                                                                                                                                                                                                                                                                                                                      NaN\n",
       "Veröffentlichungsort                                                                                                                                                                                                                                                                                                                                                             St. Petersburg\n",
       "Veröffentlichungsort (normiert)                                                                                                                                                                                                                                                                                                                                                             NaN\n",
       "Sprache                                                                                                                                                                                                                                                                                                                                                                                 unknown\n",
       "Schlagwörter                                                                                                                                                                                                                                                                                                                Sankt Petersburg; Museum; Eremitage; Straße von Kertsch; Antiquität\n",
       "Schlagwörter (mit GND)             Antiquität$Ds--(DE-588)4002325-4;Straße von Kertsch$Dg--(DE-588)4497588-0;Sankt Petersburg$Dg--(DE-588)4267026-3;Eremitage$Ds--(DE-588)4354208-6;AT-OBV--ONB-AK;Sankt Petersburg$Dg--(DE-588)4267026-3;Museum$Ds--(DE-588)4040795-0;Eremitage$Ds--(DE-588)4354208-6;Straße von Kertsch$Dg--(DE-588)4497588-0;Antiquität$Ds--(DE-588)4002325-4;AT-OBV--ONB-AK\n",
       "Vorbesitzer                                                                                                                                                                                                                                                                                                                                                                                 NaN\n",
       "Typ                                                                                                                                                                                                                                                                                                                                                                                         NaN\n",
       "Bemerkungen                                                                                                                                                                                                                                                                                                                                                                                 NaN\n",
       "Gültiger Barcode                                                                                                                                                                                                                                                                                                                                                                            NaN\n",
       "Dateiname                                                                                                                                                                                                                                                                                                                                                                                   NaN\n",
       "Wappenklassifizierung                                                                                                                                                                                                                                                                                                                                                                       NaN\n",
       "p_A                                                                                                                                                                                                                                                                                                                                                                                         NaN\n",
       "p_B                                                                                                                                                                                                                                                                                                                                                                                         NaN\n",
       "p_C                                                                                                                                                                                                                                                                                                                                                                                         NaN\n",
       "p_N                                                                                                                                                                                                                                                                                                                                                                                         NaN\n",
       "Farbklassifizierung                                                                                                                                                                                                                                                                                                                                                                         NaN\n",
       "p_blue                                                                                                                                                                                                                                                                                                                                                                                      NaN\n",
       "p_red                                                                                                                                                                                                                                                                                                                                                                                       NaN\n",
       "p_yellow                                                                                                                                                                                                                                                                                                                                                                                    NaN\n",
       "Name: 2, dtype: object"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BE_entry = BE_df.loc[2]\n",
    "print(BE_entry['Signatur'])\n",
    "print(BE_entry['Barcode'])\n",
    "print(BE_entry['Titel'])\n",
    "print(BE_entry['Autor'])\n",
    "print(BE_entry['Veröffentlichungsort'])\n",
    "print(BE_entry['Veröffentlichungsdatum'])\n",
    "print(BE_entry['Wappenklassifizierung'])\n",
    "BE_entry"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a499f1aa-20d8-4e5c-9386-abd2b7023974",
   "metadata": {},
   "source": [
    "# Create Matching data\n",
    "\n",
    "## Match from existing catalogue data for BE signatures. Combine author (+ printer etc), title, year and place and try to match it with an entry in the handwritten catalogue."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5388945-7294-420a-a524-c3372e3c761d",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "better_matches = []\n",
    "scorer = thefuzz.fuzz.token_set_ratio\n",
    "\n",
    "for index, row in tqdm.notebook.tqdm(BE_manual.iterrows(), total=len(BE_manual)):\n",
    "    keys = ['Autor', 'Mitwirkender', 'Titel', 'Veröffentlichungsort', 'Anfang Veröffentlichungsdatum']\n",
    "    comb_string = ''\n",
    "    for key in keys:\n",
    "        val = row[key]\n",
    "        if not pd.isna(val):\n",
    "            if key == 'Autor' or key == 'Mitwirkender':\n",
    "                if ',' in val:  # falls name, vorname\n",
    "                    val = val.split(',')[0]\n",
    "                val = val.split(' ')[0]\n",
    "            elif key == 'Titel':\n",
    "                val = prepare_string(val)\n",
    "            elif key == 'Anfang Veröffentlichungsdatum':\n",
    "                val = str(int(val))\n",
    "            else: # key == 'Veröffentlichungsort'\n",
    "                pass\n",
    "            comb_string += val + ' '\n",
    "    \n",
    "    matches_lis = thefuzz.process.extract(comb_string, entry_df['cleaned entry'], scorer=scorer, limit=5)\n",
    "    flat_matches = []\n",
    "    for match in matches_lis:\n",
    "        flat_matches.append(match[0])\n",
    "        flat_matches.append(match[1])\n",
    "        flat_matches.append(match[2])\n",
    "    better_matches.append([comb_string] + flat_matches)\n",
    "\n",
    "matches_df = pd.DataFrame(better_matches, columns=['input', 'match_1', 'score_1', 'id_1', 'match_2', 'score_2', 'id_2', 'match_3', 'score_3', 'id_3', 'match_4', 'score_4', 'id_4', 'match_5', 'score_5', 'id_5'])\n",
    "matches_df['control'] = ''\n",
    "matches_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0f42259-6df9-4e3b-80e1-1dbe4642545c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "matches_df_no_score = matches_df.drop(['score_1', 'score_2', 'score_3', 'score_4', 'score_5'], axis=1)\n",
    "matches_df_no_score.insert(1, 'input_id', BE_manual.index)\n",
    "matches_df_no_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 749,
   "id": "51aae223-d87e-4fa0-8a97-25c33b7c8d65",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Export in batches of 1000\n",
    "matches_df_no_score[:1000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_1000.xlsx', index=False)\n",
    "matches_df_no_score[1000:2000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_2000.xlsx', index=False)\n",
    "matches_df_no_score[2000:3000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_3000.xlsx', index=False)\n",
    "matches_df_no_score[3000:4000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_4000.xlsx', index=False)\n",
    "matches_df_no_score[4000:5000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_5000.xlsx', index=False)\n",
    "matches_df_no_score[5000:6000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_6000.xlsx', index=False)\n",
    "matches_df_no_score[6000:7000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_7000.xlsx', index=False)\n",
    "matches_df_no_score[7000:8000].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_8000.xlsx', index=False)\n",
    "matches_df_no_score[8000:].to_excel('../Daten/Katalogabgleich/Kandidaten/Kandidaten_8756.xlsx', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "68eb5b1e-a23b-4014-aa7d-903878c14a3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "non_BE = BE_df[~BE_df['Signatur'].str.contains('BE')]\n",
    "non_BE_wappen = non_BE[~non_BE['Wappenklassifizierung'].isna()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d34f7a91-6f09-4c93-8376-105dc804764f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Signatur</th>\n",
       "      <th>Wappenklassifizierung</th>\n",
       "      <th>Barcode</th>\n",
       "      <th>Mitwirkender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>22595</th>\n",
       "      <td>Be.10.J.38.(Vol.1,1)</td>\n",
       "      <td>N</td>\n",
       "      <td>+Z17136510X</td>\n",
       "      <td>Cotta; Nees von Esenbeck, Christian Gottfried Daniel 1776-1858; Eschweiler, Franz Gerhard 1796-1831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22599</th>\n",
       "      <td>Be.5.Q.69.(Vol.5)</td>\n",
       "      <td>N</td>\n",
       "      <td>+Z197357203</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22612</th>\n",
       "      <td>22.M.23</td>\n",
       "      <td>B</td>\n",
       "      <td>+Z43165504</td>\n",
       "      <td>Manuzio, Aldo Pio 1450-1515; Philostratus, Flavius 160-245; Eusebius Caesariensis 260-339; Rinuccinus, Alemannus 1426-1504; Acciaiuoli, Zanobi 1461-1519; Ευσεβιος Καισαρειας</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22613</th>\n",
       "      <td>22.N.14</td>\n",
       "      <td>B</td>\n",
       "      <td>+Z221977709</td>\n",
       "      <td>Manuzio, Paolo; Manuzio, Paolo 1512-1574</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22614</th>\n",
       "      <td>22.N.27 (Vol.1)</td>\n",
       "      <td>B</td>\n",
       "      <td>+Z43162801</td>\n",
       "      <td>Manuzio, Aldo Pio 1450-1515; Theophanes Confessor 752-817; Cosmas Hierosolymitanus -781; Marcus de Idronto ca. um 770; Johannes Damascenus 675-749; Clarius, Daniel ca. 15./16. Jh.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22615</th>\n",
       "      <td>22.N.67</td>\n",
       "      <td>B</td>\n",
       "      <td>+Z221954400</td>\n",
       "      <td>Manuzio, Paolo 1512-1574; Auria, Andrea &lt;&lt;d'&gt;&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22616</th>\n",
       "      <td>22.Q.37</td>\n",
       "      <td>N</td>\n",
       "      <td>+Z22196790X</td>\n",
       "      <td>Asulanus, Franciscus -1546; Aldo Manuzio Senior Haeredes; Carloni, Antonio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22618</th>\n",
       "      <td>60164-D.1</td>\n",
       "      <td>A</td>\n",
       "      <td>+Z194791901</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22619</th>\n",
       "      <td>60164-D.2</td>\n",
       "      <td>A</td>\n",
       "      <td>+Z254932002</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Signatur Wappenklassifizierung      Barcode  \\\n",
       "22595  Be.10.J.38.(Vol.1,1)                     N  +Z17136510X   \n",
       "22599     Be.5.Q.69.(Vol.5)                     N  +Z197357203   \n",
       "22612               22.M.23                     B   +Z43165504   \n",
       "22613               22.N.14                     B  +Z221977709   \n",
       "22614       22.N.27 (Vol.1)                     B   +Z43162801   \n",
       "22615               22.N.67                     B  +Z221954400   \n",
       "22616               22.Q.37                     N  +Z22196790X   \n",
       "22618             60164-D.1                     A  +Z194791901   \n",
       "22619             60164-D.2                     A  +Z254932002   \n",
       "\n",
       "                                                                                                                                                                              Mitwirkender  \n",
       "22595                                                                                  Cotta; Nees von Esenbeck, Christian Gottfried Daniel 1776-1858; Eschweiler, Franz Gerhard 1796-1831  \n",
       "22599                                                                                                                                                                                  NaN  \n",
       "22612        Manuzio, Aldo Pio 1450-1515; Philostratus, Flavius 160-245; Eusebius Caesariensis 260-339; Rinuccinus, Alemannus 1426-1504; Acciaiuoli, Zanobi 1461-1519; Ευσεβιος Καισαρειας  \n",
       "22613                                                                                                                                             Manuzio, Paolo; Manuzio, Paolo 1512-1574  \n",
       "22614  Manuzio, Aldo Pio 1450-1515; Theophanes Confessor 752-817; Cosmas Hierosolymitanus -781; Marcus de Idronto ca. um 770; Johannes Damascenus 675-749; Clarius, Daniel ca. 15./16. Jh.  \n",
       "22615                                                                                                                                       Manuzio, Paolo 1512-1574; Auria, Andrea <<d'>>  \n",
       "22616                                                                                                           Asulanus, Franciscus -1546; Aldo Manuzio Senior Haeredes; Carloni, Antonio  \n",
       "22618                                                                                                                                                                                  NaN  \n",
       "22619                                                                                                                                                                                  NaN  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "non_BE_wappen[['Signatur', 'Wappenklassifizierung', 'Barcode', 'Mitwirkender']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "512515e9-84a4-4e97-a16d-2f28df90abde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Signatur', 'Barcode', 'Titel', 'Autor', 'Mitwirkender',\n",
       "       'Anfang Veröffentlichungsdatum', 'Ende Veröffentlichungsdatum',\n",
       "       'Veröffentlichungsdatum', 'Veröffentlichungsort',\n",
       "       'Veröffentlichungsort (normiert)', 'Sprache', 'Schlagwörter',\n",
       "       'Schlagwörter (mit GND)', 'Vorbesitzer', 'Typ', 'Bemerkungen',\n",
       "       'Gültiger Barcode', 'Dateiname', 'Wappenklassifizierung', 'p_A', 'p_B',\n",
       "       'p_C', 'p_N', 'Farbklassifizierung', 'p_blue', 'p_red', 'p_yellow'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "non_BE_wappen.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "b8de2583-c260-46df-ab7c-15b4feff0a33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['filename', 'prediction', 'p_A', 'p_B', 'p_C', 'p_N', 'color', 'p_blue',\n",
       "       'p_red', 'p_yellow', 'man_prediction', 'man_color', 'valid_bc',\n",
       "       'Permanent Call Number', '992', '993', '695', '866',\n",
       "       'Library Code (Active)', 'Location Code', 'Barcode', 'Item Call Number',\n",
       "       'Title', 'Author', 'Author (contributor)', 'Begin Publication Date',\n",
       "       'End Publication Date', 'Publication Date', 'Publication Place',\n",
       "       'Publisher', 'Unnamed: 17', 'MMS Id', '856', 'Subjects',\n",
       "       'Subjects (Names)'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred = pd.read_csv('../Daten/Vorhersagen/catalogue_pred_combined.csv')\n",
    "pred.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "042eb3f3-6d53-4403-a230-513d36ea8b44",
   "metadata": {},
   "outputs": [],
   "source": [
    "no_sign_wappen = pred[pred['Permanent Call Number'].isna()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "87462bd0-ad17-4ea5-9486-f4b23605d74d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "803"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(no_sign_wappen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "d7326106-193b-4841-ac3c-becae1b27ddf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>filename</th>\n",
       "      <th>prediction</th>\n",
       "      <th>p_A</th>\n",
       "      <th>p_B</th>\n",
       "      <th>p_C</th>\n",
       "      <th>p_N</th>\n",
       "      <th>color</th>\n",
       "      <th>p_blue</th>\n",
       "      <th>p_red</th>\n",
       "      <th>p_yellow</th>\n",
       "      <th>...</th>\n",
       "      <th>Begin Publication Date</th>\n",
       "      <th>End Publication Date</th>\n",
       "      <th>Publication Date</th>\n",
       "      <th>Publication Place</th>\n",
       "      <th>Publisher</th>\n",
       "      <th>Unnamed: 17</th>\n",
       "      <th>MMS Id</th>\n",
       "      <th>856</th>\n",
       "      <th>Subjects</th>\n",
       "      <th>Subjects (Names)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Z103519105_00000001.jpg</td>\n",
       "      <td>A</td>\n",
       "      <td>0.998598</td>\n",
       "      <td>0.000445</td>\n",
       "      <td>0.000400</td>\n",
       "      <td>0.000558</td>\n",
       "      <td>red</td>\n",
       "      <td>0.000419</td>\n",
       "      <td>0.997730</td>\n",
       "      <td>0.001851</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Z10353460X_00000001.jpg</td>\n",
       "      <td>A</td>\n",
       "      <td>0.994711</td>\n",
       "      <td>0.002387</td>\n",
       "      <td>0.001679</td>\n",
       "      <td>0.001224</td>\n",
       "      <td>red</td>\n",
       "      <td>0.002559</td>\n",
       "      <td>0.982544</td>\n",
       "      <td>0.014897</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Z105561605_00000001.jpg</td>\n",
       "      <td>B</td>\n",
       "      <td>0.000142</td>\n",
       "      <td>0.999590</td>\n",
       "      <td>0.000070</td>\n",
       "      <td>0.000198</td>\n",
       "      <td>red</td>\n",
       "      <td>0.000502</td>\n",
       "      <td>0.995507</td>\n",
       "      <td>0.003991</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Z137115906_00000001.jpg</td>\n",
       "      <td>A</td>\n",
       "      <td>0.997722</td>\n",
       "      <td>0.001312</td>\n",
       "      <td>0.000461</td>\n",
       "      <td>0.000505</td>\n",
       "      <td>blue</td>\n",
       "      <td>0.993158</td>\n",
       "      <td>0.003776</td>\n",
       "      <td>0.003066</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>Z13711690X_00000001.jpg</td>\n",
       "      <td>A</td>\n",
       "      <td>0.999452</td>\n",
       "      <td>0.000185</td>\n",
       "      <td>0.000149</td>\n",
       "      <td>0.000213</td>\n",
       "      <td>blue</td>\n",
       "      <td>0.994273</td>\n",
       "      <td>0.005353</td>\n",
       "      <td>0.000374</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6154</th>\n",
       "      <td>Z260077107_00000001.jpg</td>\n",
       "      <td>B</td>\n",
       "      <td>0.000248</td>\n",
       "      <td>0.998484</td>\n",
       "      <td>0.000442</td>\n",
       "      <td>0.000827</td>\n",
       "      <td>red</td>\n",
       "      <td>0.000213</td>\n",
       "      <td>0.994317</td>\n",
       "      <td>0.005469</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6155</th>\n",
       "      <td>Z43162801_00000001.jpg</td>\n",
       "      <td>B</td>\n",
       "      <td>0.000684</td>\n",
       "      <td>0.997634</td>\n",
       "      <td>0.001180</td>\n",
       "      <td>0.000502</td>\n",
       "      <td>red</td>\n",
       "      <td>0.001450</td>\n",
       "      <td>0.997198</td>\n",
       "      <td>0.001353</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6156</th>\n",
       "      <td>Z43163301_00000001.jpg</td>\n",
       "      <td>B</td>\n",
       "      <td>0.000872</td>\n",
       "      <td>0.998139</td>\n",
       "      <td>0.000583</td>\n",
       "      <td>0.000406</td>\n",
       "      <td>red</td>\n",
       "      <td>0.000331</td>\n",
       "      <td>0.998473</td>\n",
       "      <td>0.001197</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6157</th>\n",
       "      <td>Z43165504_00000001.jpg</td>\n",
       "      <td>B</td>\n",
       "      <td>0.000670</td>\n",
       "      <td>0.998324</td>\n",
       "      <td>0.000560</td>\n",
       "      <td>0.000445</td>\n",
       "      <td>red</td>\n",
       "      <td>0.001188</td>\n",
       "      <td>0.996374</td>\n",
       "      <td>0.002438</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6158</th>\n",
       "      <td>Z43169509_00000001.jpg</td>\n",
       "      <td>A</td>\n",
       "      <td>0.995156</td>\n",
       "      <td>0.001711</td>\n",
       "      <td>0.002191</td>\n",
       "      <td>0.000941</td>\n",
       "      <td>red</td>\n",
       "      <td>0.000120</td>\n",
       "      <td>0.999710</td>\n",
       "      <td>0.000170</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>803 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     filename prediction       p_A       p_B       p_C  \\\n",
       "0     Z103519105_00000001.jpg          A  0.998598  0.000445  0.000400   \n",
       "4     Z10353460X_00000001.jpg          A  0.994711  0.002387  0.001679   \n",
       "13    Z105561605_00000001.jpg          B  0.000142  0.999590  0.000070   \n",
       "16    Z137115906_00000001.jpg          A  0.997722  0.001312  0.000461   \n",
       "17    Z13711690X_00000001.jpg          A  0.999452  0.000185  0.000149   \n",
       "...                       ...        ...       ...       ...       ...   \n",
       "6154  Z260077107_00000001.jpg          B  0.000248  0.998484  0.000442   \n",
       "6155   Z43162801_00000001.jpg          B  0.000684  0.997634  0.001180   \n",
       "6156   Z43163301_00000001.jpg          B  0.000872  0.998139  0.000583   \n",
       "6157   Z43165504_00000001.jpg          B  0.000670  0.998324  0.000560   \n",
       "6158   Z43169509_00000001.jpg          A  0.995156  0.001711  0.002191   \n",
       "\n",
       "           p_N color    p_blue     p_red  p_yellow  ...  \\\n",
       "0     0.000558   red  0.000419  0.997730  0.001851  ...   \n",
       "4     0.001224   red  0.002559  0.982544  0.014897  ...   \n",
       "13    0.000198   red  0.000502  0.995507  0.003991  ...   \n",
       "16    0.000505  blue  0.993158  0.003776  0.003066  ...   \n",
       "17    0.000213  blue  0.994273  0.005353  0.000374  ...   \n",
       "...        ...   ...       ...       ...       ...  ...   \n",
       "6154  0.000827   red  0.000213  0.994317  0.005469  ...   \n",
       "6155  0.000502   red  0.001450  0.997198  0.001353  ...   \n",
       "6156  0.000406   red  0.000331  0.998473  0.001197  ...   \n",
       "6157  0.000445   red  0.001188  0.996374  0.002438  ...   \n",
       "6158  0.000941   red  0.000120  0.999710  0.000170  ...   \n",
       "\n",
       "     Begin Publication Date End Publication Date Publication Date  \\\n",
       "0                       NaN                  NaN              NaN   \n",
       "4                       NaN                  NaN              NaN   \n",
       "13                      NaN                  NaN              NaN   \n",
       "16                      NaN                  NaN              NaN   \n",
       "17                      NaN                  NaN              NaN   \n",
       "...                     ...                  ...              ...   \n",
       "6154                    NaN                  NaN              NaN   \n",
       "6155                    NaN                  NaN              NaN   \n",
       "6156                    NaN                  NaN              NaN   \n",
       "6157                    NaN                  NaN              NaN   \n",
       "6158                    NaN                  NaN              NaN   \n",
       "\n",
       "     Publication Place Publisher Unnamed: 17 MMS Id  856 Subjects  \\\n",
       "0                  NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "4                  NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "13                 NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "16                 NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "17                 NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "...                ...       ...         ...    ...  ...      ...   \n",
       "6154               NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "6155               NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "6156               NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "6157               NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "6158               NaN       NaN         NaN    NaN  NaN      NaN   \n",
       "\n",
       "     Subjects (Names)  \n",
       "0                 NaN  \n",
       "4                 NaN  \n",
       "13                NaN  \n",
       "16                NaN  \n",
       "17                NaN  \n",
       "...               ...  \n",
       "6154              NaN  \n",
       "6155              NaN  \n",
       "6156              NaN  \n",
       "6157              NaN  \n",
       "6158              NaN  \n",
       "\n",
       "[803 rows x 35 columns]"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "no_sign_wappen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "07da4f64-6dbd-4a57-9122-338a9c66bf5b",
   "metadata": {},
   "outputs": [],
   "source": [
    "nsw = no_sign_wappen.dropna(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "73c74495-9522-427a-88db-d8f1cca96cdd",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_content(url):\n",
    "    retries = 0\n",
    "    while retries < 3:\n",
    "        try:\n",
    "            resp = requests.get(url)\n",
    "            if resp.status_code == 200:\n",
    "                return resp.content\n",
    "            else:\n",
    "                retries += 1\n",
    "        except requests.exceptions.Timeout:\n",
    "            retries += 1\n",
    "        except (requests.exceptions.TooManyRedirects, requests.exceptions.RequestException) as e:\n",
    "            raise SystemExit(e)\n",
    "\n",
    "def extract_signature_from_manifest(bc):\n",
    "    man_url = f'https://iiif.onb.ac.at/presentation/ABO/{bc}/manifest'\n",
    "    metadata = json.loads(get_content(man_url))['metadata']\n",
    "    metadata_str = json.dumps(metadata)\n",
    "    loc_s = re.compile('<a.+?data.onb.ac.at.+?>(.+?)</a>')\n",
    "    ac_s = re.compile('AC[0-9]+')\n",
    "    loc = loc_s.findall(metadata_str)\n",
    "    if len(loc) > 0:\n",
    "        loc = loc[0]\n",
    "    else:\n",
    "        loc = ''\n",
    "    acnr = ac_s.findall(metadata_str)\n",
    "    if len(acnr) > 0:\n",
    "        acnr = acnr[0]\n",
    "    else:\n",
    "        acnr = ''\n",
    "    return (loc, acnr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "f4ef590d-775f-41c6-bd35-384aa9e5dd8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('', 'AC09912489')"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "extract_signature_from_manifest('Z150809200')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "8920d0a5-6ead-4db8-8407-cd6d4c8657e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_7044/501467936.py:4: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  nsw.loc[i, 'Signatur'] = sig\n",
      "/tmp/ipykernel_7044/501467936.py:5: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  nsw.loc[i, 'AC-Nummer'] = ac\n"
     ]
    }
   ],
   "source": [
    "for i in nsw.index:\n",
    "    bc = nsw.loc[i, 'valid_bc']\n",
    "    sig, ac = extract_signature_from_manifest(bc)\n",
    "    nsw.loc[i, 'Signatur'] = sig\n",
    "    nsw.loc[i, 'AC-Nummer'] = ac"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "0ae7c215-f811-4b6d-897f-55328337ead4",
   "metadata": {},
   "outputs": [],
   "source": [
    "nsw_no_dup = nsw.drop_duplicates('valid_bc')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "e3916d07-7d22-40c3-aff2-eb9823840f96",
   "metadata": {},
   "outputs": [],
   "source": [
    "keine_BE = nsw_no_dup.drop(['filename', 'prediction', 'p_A', 'p_B', 'p_C', 'p_N', 'color', 'p_blue', 'p_red', 'p_yellow'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "62d169f7-2bcb-431b-8f6b-76d37194abc9",
   "metadata": {},
   "outputs": [],
   "source": [
    "keine_BE.rename(columns={'man_prediction': 'Wappen', 'man_color': 'Einbandfarbe', 'valid_bc': 'Barcode'}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "3cc27a7c-b960-4360-81c8-6873fc39a95e",
   "metadata": {},
   "outputs": [],
   "source": [
    "keine_BE = keine_BE.reindex(columns=['Barcode', 'Signatur', 'AC-Nummer', 'Wappen', 'Einbandfarbe'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "f2c1a4aa-3312-4353-9767-ef0009bf35da",
   "metadata": {},
   "outputs": [],
   "source": [
    "keine_BE.to_excel('../Daten/Vorhersagen/Eugeniana aber nicht BE.xlsx', index=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "054a6f0d-251d-4cc5-84b9-0d777b7d1f7c",
   "metadata": {},
   "source": [
    "# Analyze manual matching data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d6efcff5-0393-4835-b673-001e85877f13",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "manual_file_names = [\n",
    "    'Ausgefüllt_1000.xlsx',\n",
    "    'Ausgefüllt_2000.xlsx',\n",
    "    'Ausgefüllt_3000.xlsx',\n",
    "    'Ausgefüllt_4000.xlsx',\n",
    "    'Ausgefüllt_5000.xlsx',\n",
    "    'Ausgefüllt_6000.xlsx',\n",
    "    'Ausgefüllt_7000.xlsx',\n",
    "    'Ausgefüllt_8000.xlsx',\n",
    "    'Ausgefüllt_8756.xlsx',\n",
    "]\n",
    "\n",
    "manual_matches_dfs = []\n",
    "\n",
    "for fname in manual_file_names:\n",
    "    df = pd.read_excel(f'../Daten/Katalogabgleich/Ausgefüllt/{fname}')\n",
    "    manual_matches_dfs.append(df)\n",
    "\n",
    "man_matches = pd.concat(manual_matches_dfs, ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7a39c6a7-d81b-4f79-89a0-bafc96411d93",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "has_hw_catalog = man_matches.dropna(subset=['control'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "881ea2ed-277b-46da-8f23-e3f3f56aae86",
   "metadata": {},
   "source": [
    "## Matching statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 686,
   "id": "cb7b6815-c782-4e00-bd7f-9abcf7f523f5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "75 <class 'numpy.int64'>\n",
      "75 <class 'int'>\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "def num_in_lis(num, lis_str):\n",
    "    if pd.isna(lis_str):\n",
    "        return False \n",
    "    else:\n",
    "        if isinstance(lis_str, int):\n",
    "            lis = [lis_str]\n",
    "        if isinstance(lis_str, str):\n",
    "            if '?' in lis_str:\n",
    "                return False\n",
    "            lis = lis_str.split(', ')\n",
    "            lis = [int(n) for n in lis]\n",
    "        return num in lis\n",
    "\n",
    "example = man_matches.loc[9]\n",
    "print(example['id_1'], type(example['id_1']))\n",
    "print(example['control'], type(example['control']))\n",
    "print(num_in_lis(example['id_1'], example['control']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 687,
   "id": "836d1b5e-ef2f-4ff8-9c03-298b029f73b2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5770 out of 8756 BE signatures from the appropriate time period were matched\n",
      "For 4727 matches the first one was correct\n",
      "For 5286 matches one of the five given ones in the table was correct\n",
      "132 matches have two or more mentions in the handwritten catalog\n",
      "152 connections are uncertain\n"
     ]
    }
   ],
   "source": [
    "BE_signatures_matched = len(man_matches.dropna(subset=['control']))\n",
    "print(BE_signatures_matched, 'out of', len(man_matches), 'BE signatures from the appropriate time period were matched')\n",
    "\n",
    "first_matches = sum(man_matches.apply(lambda x: num_in_lis(x['id_1'], x['control']), axis=1))\n",
    "print('For', first_matches, 'matches the first one was correct')\n",
    "any_matches = sum(man_matches.apply(lambda x: num_in_lis(x['id_1'], x['control']) \n",
    "                                    or num_in_lis(x['id_2'], x['control']) \n",
    "                                    or num_in_lis(x['id_3'], x['control']) \n",
    "                                    or num_in_lis(x['id_4'], x['control']) \n",
    "                                    or num_in_lis(x['id_5'], x['control']), axis=1))\n",
    "print('For', any_matches, 'matches one of the five given ones in the table was correct')\n",
    "\n",
    "double_matches = man_matches['control'].str.contains(',').sum()\n",
    "print(double_matches, 'matches have two or more mentions in the handwritten catalog')\n",
    "\n",
    "weak_matches = man_matches['control'].str.contains('/?').sum()\n",
    "print(weak_matches, 'connections are uncertain')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 688,
   "id": "9f7bd1bf-a4cd-427a-b65a-5e2fce029212",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "num_re = re.compile('\\d{1,4}(?!\\?)')\n",
    "all_matches = []\n",
    "for row in man_matches['control']:\n",
    "    match = num_re.findall(str(row))\n",
    "    if match:\n",
    "        all_matches.append(match)\n",
    "\n",
    "flat_matches = [el for sublis in all_matches for el in sublis]\n",
    "set_matches = set(flat_matches)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 689,
   "id": "17434971-7462-4f00-8370-d5573f3ea72c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5162 entries out of 9403 entries from the handwritten catalog were matched (at least once)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[2, 4, 7, 9, 11, 12, 18, 19, 20, 28, 32, 34, 35, 37, 39, 40, 43, 44, 45, 48]"
      ]
     },
     "execution_count": 689,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique_matches_int = sorted([int(n) for n in set_matches])\n",
    "\n",
    "print(len(unique_matches_int), 'entries out of', len(entry_df), 'entries from the handwritten catalog were matched (at least once)')\n",
    "unique_matches_int[:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 690,
   "id": "25fcabf9-fb1c-4fe7-838a-8b595f0a2673",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "no_matches_df = entry_df.loc[entry_df.index.difference(unique_matches_int)]\n",
    "matches_df = entry_df.loc[unique_matches_int]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 691,
   "id": "24bb9a74-0e99-4760-a3d5-05f8df71f85a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Historia Nova Europæ': 0.5003300330033004, 'Poëtica': 0.5557038025350234, 'Paralipomena Historica': 0.5592903828197946, 'Theologia': 0.6864197530864198, 'Philologia': 0.6099173553719008, 'Historia Naturalis': 0.7038461538461539, 'Historia Ecclesiastica': 0.6994818652849741, 'Artes': 0.5755968169761273, 'Philosophia': 0.7028571428571428, 'Historia Antiqua': 0.40186915887850466, 'Codices Manuscripti': 0.0034129692832764505, 'Imagines Incisæ': 0.04330708661417323, 'Geographia': 0.5634920634920635, 'Iurisprudentia': 0.6911764705882353, 'Historia Nova extra Europam': 0.5577889447236181, 'Rhetorica': 0.5987654320987654, 'Mathematica': 0.7559055118110236, 'Grammatica': 0.5819672131147541, 'Medicina': 0.6422018348623854, 'Chronologia': 0.5612244897959183, 'Miscellanea Historica': 0.40816326530612246, 'Imagines Variæ Incisæ': 0.0851063829787234, 'Effigierum Incisarum Collectio': 0.0, 'Imaginum Delineatarum Collectio': 0.0}\n"
     ]
    }
   ],
   "source": [
    "all_counts = entry_df['category'].value_counts()\n",
    "match_counts = matches_df['category'].value_counts()\n",
    "no_match_counts = no_matches_df['category'].value_counts()\n",
    "\n",
    "ratios = {}\n",
    "for cat, count in all_counts.items():\n",
    "    matched = 0\n",
    "    if cat in match_counts.index:\n",
    "        matched = match_counts[cat]\n",
    "    ratios[cat] = matched / count\n",
    "\n",
    "print(ratios)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 692,
   "id": "6c952698-2bc7-4511-a688-3bcd30ed8196",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 109364 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sorted_ratios = sorted(ratios.items(), key=lambda x: x[1], reverse=True)\n",
    "n, r = list(zip(*sorted_ratios))\n",
    "\n",
    "fix, ax = plt.subplots()\n",
    "ax.bar(n, [100 * ratio for ratio in r])\n",
    "plt.xticks(rotation=45, ha='right')\n",
    "ax.set_ylabel('Vollständigkeit [%]')\n",
    "ax.set_title('Verbindung von hs. Katalog und mod. Katalog')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b49f3686-efd3-478b-b493-b69b60ce3ad4",
   "metadata": {},
   "source": [
    "## Add new matching data to existing catalogue data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5ef1c335-c990-4f8c-aa47-bd967e73c7f6",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "BE_df = pd.read_excel('../Daten/Vorhersagen/Katalogauszug, Vorhersagen und hs. Katalogverbindungen.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8720472d-c222-45b5-b1af-66d579b0405e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5777"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BE_df['hs. Katalog'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "32d281c0-4015-4913-a5ec-da22c6a9c8ad",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Barcode', 'Titel', 'Autor', 'Mitwirkender',\n",
       "       'Anfang Veröffentlichungsdatum', 'Ende Veröffentlichungsdatum',\n",
       "       'Veröffentlichungsdatum', 'Veröffentlichungsort',\n",
       "       'Veröffentlichungsort (normiert)', 'Sprache', 'Schlagwörter',\n",
       "       'Schlagwörter (mit GND)', 'Vorbesitzer', 'Typ', 'Bemerkungen',\n",
       "       'Gültiger Barcode', 'Dateiname', 'Wappenklassifizierung', 'p_A', 'p_B',\n",
       "       'p_C', 'p_N', 'Farbklassifizierung', 'p_blue', 'p_red', 'p_yellow',\n",
       "       'hs. Katalog', 'hs. Katalog Konfidenz', 'hs. Katalogband',\n",
       "       'hs. Katalogseite Digitalisat', 'Wissensklasse', 'Wissensunterklasse',\n",
       "       'Formatangabe', 'hs. Katalogseite Handschrift', 'hs. Katalogeintrag ID',\n",
       "       'hs. Katalogeintrag', 'hs. Katalog Image URL', 'identifier',\n",
       "       'ABO-Barcode'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# volume \tpage number \tcategory \tsubcategory \tformat \thandwritten page number \tentry_ID \tentry \t\n",
    "BE_df['hs. Katalog'] = 0\n",
    "\n",
    "BE_df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "0ddd0ffe-3546-43fb-90ff-1d7206af138e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['volume', 'page number', 'category', 'subcategory', 'format',\n",
       "       'handwritten page number', 'entry_ID', 'entry', 'cleaned entry'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entry_df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "b8d40359-5eba-49e6-b2a6-3bc37786dd4c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "dod_id = {\n",
    "    '14.376': 51202, \n",
    "    '14.377': 51184,\n",
    "    '14.378': 51219\n",
    "}\n",
    "\n",
    "for i, entry in has_hw_catalog.iterrows():\n",
    "    man_match = str(entry['control'])\n",
    "    match_regex = re.compile('\\d{1,4}')\n",
    "    matches = match_regex.findall(man_match)\n",
    "    if matches:\n",
    "        first_match_id = int(matches[0])\n",
    "        corr_entry = entry_df.loc[first_match_id]\n",
    "        BE_id = entry['input_id']\n",
    "        BE_df.at[BE_id, 'hs. Katalog'] = 1\n",
    "        if '?' not in man_match:\n",
    "            BE_df.at[BE_id, 'hs. Katalog Konfidenz'] = 'sicher'\n",
    "        else:\n",
    "            BE_df.at[BE_id, 'hs. Katalog Konfidenz'] = 'unsicher'\n",
    "        BE_df.at[BE_id, 'hs. Katalogband'] = str(corr_entry['volume'])\n",
    "        BE_df.at[BE_id, 'hs. Katalogseite Digitalisat'] = corr_entry['page number']\n",
    "        BE_df.at[BE_id, 'Wissensklasse'] = corr_entry['category']\n",
    "        BE_df.at[BE_id, 'Wissensunterklasse'] = corr_entry['subcategory']\n",
    "        BE_df.at[BE_id, 'Formatangabe'] = corr_entry['format']\n",
    "        BE_df.at[BE_id, 'hs. Katalogseite Handschrift'] = corr_entry['handwritten page number']\n",
    "        BE_df.at[BE_id, 'hs. Katalogeintrag ID'] = corr_entry['entry_ID']\n",
    "        BE_df.at[BE_id, 'hs. Katalogeintrag'] = corr_entry['entry']\n",
    "        BE_df.at[BE_id, 'hs. Katalog Image URL'] = f\"https://iiif.onb.ac.at/images/DOD/{dod_id[str(corr_entry['volume'])]}/{corr_entry['page number']:08}.jp2/full/full/0/native.jpg\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "id": "4ed3c187-ab7a-419a-8530-386a69143b3d",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "BE_df.to_excel('../Daten/Vorhersagen/Katalogauszug, Vorhersagen und hs. Katalogverbindungen.xlsx', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "7f5dabc1-49bf-469a-9abe-c15fa20204ce",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Signatur', 'Barcode', 'Titel', 'Autor', 'Mitwirkender',\n",
       "       'Anfang Veröffentlichungsdatum', 'Ende Veröffentlichungsdatum',\n",
       "       'Veröffentlichungsdatum', 'Veröffentlichungsort',\n",
       "       'Veröffentlichungsort (normiert)', 'Sprache', 'Schlagwörter',\n",
       "       'Schlagwörter (mit GND)', 'Vorbesitzer', 'Typ', 'Bemerkungen',\n",
       "       'Gültiger Barcode', 'Dateiname', 'Wappenklassifizierung', 'p_A', 'p_B',\n",
       "       'p_C', 'p_N', 'Farbklassifizierung', 'p_blue', 'p_red', 'p_yellow',\n",
       "       'hs. Katalog', 'hs. Katalog Konfidenz', 'hs. Katalogband',\n",
       "       'hs. Katalogseite Digitalisat', 'Wissensklasse', 'Wissensunterklasse',\n",
       "       'Formatangabe', 'hs. Katalogseite Handschrift', 'hs. Katalogeintrag ID',\n",
       "       'hs. Katalogeintrag', 'hs. Katalog Image URL'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BE_df.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88b825b9-8557-441d-b387-697db4ea2a5b",
   "metadata": {},
   "source": [
    "# Eugeniana-Inkunabeln aus dem handschriftlichen Katalog extrahieren"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 513,
   "id": "bc7c8cf5-7afa-43c1-8427-ab7cd58323b3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1661]\n",
      "[1628]\n",
      "[1703, 5926]\n",
      "[1662]\n"
     ]
    }
   ],
   "source": [
    "def extract_four_digit_number(entry):\n",
    "    four_dig_re = re.compile('(?<! [pPnN] )\\d{4}')\n",
    "    match = four_dig_re.findall(entry)\n",
    "    if match:\n",
    "        return [int(x) for x in match]\n",
    "    else:\n",
    "        return []\n",
    "\n",
    "year_samples = [\n",
    "    'Vossij Isaaci Dissertationes de 70 Interpretum tralatione & Chronologia Hagae Comp 1661 Vlacq p 7145 n 1360',\n",
    "    'Biblia Sacra graece ac latine juxta 70 Interpretes 3 Vol charta magna Paris 1628 Nic Buon N 3743',\n",
    "    'Nummi Antiqui Familiarum Romanar cum Ioannis Vaillant Interpretationibus 2 Vol Amsteln 1703 Gallet n 5925 5926',\n",
    "    'Hulsij antonij Authentia absoluta Seu textus hebraei vindicata contra criminationes Isaaci Vossii in libro recens edito de 70 Interpretum tralatione cum binis epistolis Roterod 1662 arn Leers n 2407 P 1234'\n",
    "]\n",
    "\n",
    "for entry in year_samples:\n",
    "    print(extract_four_digit_number(entry))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 497,
   "id": "42988cd3-f87f-46b4-be10-b5d254c286d0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "entry_df['years'] = entry_df['cleaned entry'].apply(lambda x: extract_four_digit_number(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 498,
   "id": "46d0487a-096b-4d41-872a-b9668315ee8a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "years_raw = entry_df['years']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 518,
   "id": "0110a88f-8777-4efd-84c7-b74e6fdd740a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             [1515]\n",
       "1             [1572]\n",
       "2       [1637, 1669]\n",
       "3             [1462]\n",
       "4             [1472]\n",
       "            ...     \n",
       "9398              []\n",
       "9399              []\n",
       "9400              []\n",
       "9401              []\n",
       "9402              []\n",
       "Name: years, Length: 9403, dtype: object"
      ]
     },
     "execution_count": 518,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "years_raw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 519,
   "id": "8f60804d-17fa-4d3a-9ad2-ec4a549bdf50",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "years_cleaned = years_raw.apply(lambda x: list(filter(lambda y: 1400 < int(y) < 1736, x)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 520,
   "id": "08f2d680-91e7-4fa7-8e58-ae2793ad184b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "years_min = years_cleaned.apply(lambda x: int(min(x)) if len(x) else np.nan)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 521,
   "id": "d9d40c18-f7b0-4725-941b-90e1ccf8b974",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "without_years = entry_df.loc[years_raw[years_min.isna()].index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 522,
   "id": "40328321-57d1-4d29-a087-832354f560a8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1515.0\n",
       "1       1572.0\n",
       "2       1637.0\n",
       "3       1462.0\n",
       "4       1472.0\n",
       "         ...  \n",
       "9398       NaN\n",
       "9399       NaN\n",
       "9400       NaN\n",
       "9401       NaN\n",
       "9402       NaN\n",
       "Name: years, Length: 9403, dtype: float64"
      ]
     },
     "execution_count": 522,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "years_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 523,
   "id": "7e083bdd-3aa6-40df-b12c-43238aae5355",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "before_1501 = entry_df.loc[years_min < 1501]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 526,
   "id": "321b9d28-7198-49fd-9f56-290dd6c58950",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume</th>\n",
       "      <th>page number</th>\n",
       "      <th>category</th>\n",
       "      <th>subcategory</th>\n",
       "      <th>format</th>\n",
       "      <th>handwritten page number</th>\n",
       "      <th>entry_ID</th>\n",
       "      <th>entry</th>\n",
       "      <th>cleaned entry</th>\n",
       "      <th>years</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>14.376</td>\n",
       "      <td>25</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1</td>\n",
       "      <td>14.376_025_03</td>\n",
       "      <td>4 Biblia Sacra Latina Moguntina dicta, prima omnium editio in Membranis. 2 Vol. Moguntiæ. 1462.¬ Ioan. Fust, &amp; Petr. Schoiffer de Gerneshem. n. 2088. II.O.5.</td>\n",
       "      <td>Biblia Sacra Latina Moguntina dicta prima omnium editio in Membranis 2 Vol Moguntiae 1462 Ioan Fust &amp; Petr Schoiffer de Gerneshem n 2088 IIO5</td>\n",
       "      <td>[1462]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>14.376</td>\n",
       "      <td>25</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1</td>\n",
       "      <td>14.376_025_04</td>\n",
       "      <td>5 Biblia Sacra Latina Moguntina, editio altera 2 Vol. chartâ Magnâ. Moguntiæ. 1472. Petr. Schoiffer. II.O.7. de Gerneshem. n. 2089.</td>\n",
       "      <td>Biblia Sacra Latina Moguntina editio altera 2 Vol charta Magna Moguntiae 1472 Petr Schoiffer IIO7 de Gerneshem n 2089</td>\n",
       "      <td>[1472]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>14.376</td>\n",
       "      <td>25</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1</td>\n",
       "      <td>14.376_025_06</td>\n",
       "      <td>7 Biblia Sacra latina vulgatæ Editionis. 2 Vol. chartâ III.B.3. Magnâ. 1474. absque loco Editionis n. 2090.</td>\n",
       "      <td>Biblia Sacra latina vulgatae Editionis 2 Vol charta IIIB3 Magna 1474 absque loco Editionis n 2090</td>\n",
       "      <td>[1474]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>14.376</td>\n",
       "      <td>25</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1</td>\n",
       "      <td>14.376_025_07</td>\n",
       "      <td>8 Biblia Sacra Latina cum Evangelistarum Canonibus III.B.7. &amp; concordantiis. chartâ M. Coloniæ. 1479. de Homborch. n. 2093.</td>\n",
       "      <td>Biblia Sacra Latina cum Evangelistarum Canonibus IIIB7 &amp; concordantiis charta M Coloniae 1479 de Homborch n 2093</td>\n",
       "      <td>[1479]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>14.376</td>\n",
       "      <td>26</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>2</td>\n",
       "      <td>14.376_026_00</td>\n",
       "      <td>9. Biblia Sacra Latina. Venetiis. 1481. Leonard Wild de Ratisbonâ n. 2302. III. D. 11.</td>\n",
       "      <td>Biblia Sacra Latina Venetiis 1481 Leonard Wild de Ratisbona n 2302 III D 11</td>\n",
       "      <td>[1481]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9017</th>\n",
       "      <td>14.378</td>\n",
       "      <td>522</td>\n",
       "      <td>Codices Manuscripti</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Quarto</td>\n",
       "      <td>1348</td>\n",
       "      <td>14.378_522_05</td>\n",
       "      <td>53 Tractatus de Matrimonio à Fr. Lùcano Parmensi compilat. anno 1468. Ms. in Membranis. n. CCIX.</td>\n",
       "      <td>Tractatus de Matrimonio a Fr Lucano Parmensi compilat anno 1468 Ms in Membranis n CCIX</td>\n",
       "      <td>[1468]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9033</th>\n",
       "      <td>14.378</td>\n",
       "      <td>523</td>\n",
       "      <td>Codices Manuscripti</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Quarto</td>\n",
       "      <td>1347*</td>\n",
       "      <td>14.378_523_09</td>\n",
       "      <td>68 Monita Agapæti Batilica ad Imper. Iustinian. Ms. græcè  A 1500</td>\n",
       "      <td>Monita Agapaeti Batilica ad Imper Iustinian Ms graece  A 1500</td>\n",
       "      <td>[1500]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9051</th>\n",
       "      <td>14.378</td>\n",
       "      <td>527</td>\n",
       "      <td>Codices Manuscripti</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Octavo und kleiner</td>\n",
       "      <td>1349</td>\n",
       "      <td>14.378_527_05</td>\n",
       "      <td>10 Succineta &amp; accurata de scriptio Civitatis Constantinopol. a Constantino Magno anno 331. ad Sult. Mehemet II. anno 1453. cum descriptione Canalis Maris Nigri.¬ autore Ioan. Adamo Zizla. Ms. in 8.° germanicè.</td>\n",
       "      <td>Succineta &amp; accurata de scriptio Civitatis Constantinopol a Constantino Magno anno 331 ad Sult Mehemet II anno 1453 cum descriptione Canalis Maris Nigri autore Ioan Adamo Zizla Ms in 8° germanice</td>\n",
       "      <td>[1453]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9052</th>\n",
       "      <td>14.378</td>\n",
       "      <td>528</td>\n",
       "      <td>Codices Manuscripti</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Octavo und kleiner</td>\n",
       "      <td>1350</td>\n",
       "      <td>14.378_528_00</td>\n",
       "      <td>84. I.Trionfi di Francesco Petrarca con miniature Ms. 8.° 11. Questo Ms.° è del tempo del medesimo Petrarca n. CCXXXIV. obüt Petrarca an. 1374. &amp; codex in fine habet 1459. p. 519</td>\n",
       "      <td>ITrionfi di Francesco Petrarca con miniature Ms 8° 11 Questo Ms° e del tempo del medesimo Petrarca n CCXXXIV obüt Petrarca an 1374 &amp; codex in fine habet 1459 p 519</td>\n",
       "      <td>[1374, 1459]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9059</th>\n",
       "      <td>14.378</td>\n",
       "      <td>529</td>\n",
       "      <td>Codices Manuscripti</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Octavo und kleiner</td>\n",
       "      <td>1351</td>\n",
       "      <td>14.378_529_03</td>\n",
       "      <td>Descriptio civitatis Constantinopoleos a Constantino M. anno 331. ad Sultanum Mehemet II. anno 1453. cum descriptione Canalis Maris Nigri. autore I. Adamo Zizla. 8.° Ms. germanicè</td>\n",
       "      <td>Descriptio civitatis Constantinopoleos a Constantino M anno 331 ad Sultanum Mehemet II anno 1453 cum descriptione Canalis Maris Nigri autore I Adamo Zizla 8° Ms germanice</td>\n",
       "      <td>[1453]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>366 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      volume  page number             category   \n",
       "3     14.376           25            Theologia  \\\n",
       "4     14.376           25            Theologia   \n",
       "6     14.376           25            Theologia   \n",
       "7     14.376           25            Theologia   \n",
       "8     14.376           26            Theologia   \n",
       "...      ...          ...                  ...   \n",
       "9017  14.378          522  Codices Manuscripti   \n",
       "9033  14.378          523  Codices Manuscripti   \n",
       "9051  14.378          527  Codices Manuscripti   \n",
       "9052  14.378          528  Codices Manuscripti   \n",
       "9059  14.378          529  Codices Manuscripti   \n",
       "\n",
       "                             subcategory              format   \n",
       "3     Textus & Versiones Sacræ Scripturæ               Folio  \\\n",
       "4     Textus & Versiones Sacræ Scripturæ               Folio   \n",
       "6     Textus & Versiones Sacræ Scripturæ               Folio   \n",
       "7     Textus & Versiones Sacræ Scripturæ               Folio   \n",
       "8     Textus & Versiones Sacræ Scripturæ               Folio   \n",
       "...                                  ...                 ...   \n",
       "9017                                 NaN              Quarto   \n",
       "9033                                 NaN              Quarto   \n",
       "9051                                 NaN  Octavo und kleiner   \n",
       "9052                                 NaN  Octavo und kleiner   \n",
       "9059                                 NaN  Octavo und kleiner   \n",
       "\n",
       "     handwritten page number       entry_ID   \n",
       "3                          1  14.376_025_03  \\\n",
       "4                          1  14.376_025_04   \n",
       "6                          1  14.376_025_06   \n",
       "7                          1  14.376_025_07   \n",
       "8                          2  14.376_026_00   \n",
       "...                      ...            ...   \n",
       "9017                    1348  14.378_522_05   \n",
       "9033                   1347*  14.378_523_09   \n",
       "9051                    1349  14.378_527_05   \n",
       "9052                    1350  14.378_528_00   \n",
       "9059                    1351  14.378_529_03   \n",
       "\n",
       "                                                                                                                                                                                                                   entry   \n",
       "3                                                          4 Biblia Sacra Latina Moguntina dicta, prima omnium editio in Membranis. 2 Vol. Moguntiæ. 1462.¬ Ioan. Fust, & Petr. Schoiffer de Gerneshem. n. 2088. II.O.5.  \\\n",
       "4                                                                                    5 Biblia Sacra Latina Moguntina, editio altera 2 Vol. chartâ Magnâ. Moguntiæ. 1472. Petr. Schoiffer. II.O.7. de Gerneshem. n. 2089.   \n",
       "6                                                                                                            7 Biblia Sacra latina vulgatæ Editionis. 2 Vol. chartâ III.B.3. Magnâ. 1474. absque loco Editionis n. 2090.   \n",
       "7                                                                                            8 Biblia Sacra Latina cum Evangelistarum Canonibus III.B.7. & concordantiis. chartâ M. Coloniæ. 1479. de Homborch. n. 2093.   \n",
       "8                                                                                                                                 9. Biblia Sacra Latina. Venetiis. 1481. Leonard Wild de Ratisbonâ n. 2302. III. D. 11.   \n",
       "...                                                                                                                                                                                                                  ...   \n",
       "9017                                                                                                                    53 Tractatus de Matrimonio à Fr. Lùcano Parmensi compilat. anno 1468. Ms. in Membranis. n. CCIX.   \n",
       "9033                                                                                                                                                   68 Monita Agapæti Batilica ad Imper. Iustinian. Ms. græcè  A 1500   \n",
       "9051  10 Succineta & accurata de scriptio Civitatis Constantinopol. a Constantino Magno anno 331. ad Sult. Mehemet II. anno 1453. cum descriptione Canalis Maris Nigri.¬ autore Ioan. Adamo Zizla. Ms. in 8.° germanicè.   \n",
       "9052                                  84. I.Trionfi di Francesco Petrarca con miniature Ms. 8.° 11. Questo Ms.° è del tempo del medesimo Petrarca n. CCXXXIV. obüt Petrarca an. 1374. & codex in fine habet 1459. p. 519   \n",
       "9059                                 Descriptio civitatis Constantinopoleos a Constantino M. anno 331. ad Sultanum Mehemet II. anno 1453. cum descriptione Canalis Maris Nigri. autore I. Adamo Zizla. 8.° Ms. germanicè   \n",
       "\n",
       "                                                                                                                                                                                            cleaned entry   \n",
       "3                                                           Biblia Sacra Latina Moguntina dicta prima omnium editio in Membranis 2 Vol Moguntiae 1462 Ioan Fust & Petr Schoiffer de Gerneshem n 2088 IIO5  \\\n",
       "4                                                                                   Biblia Sacra Latina Moguntina editio altera 2 Vol charta Magna Moguntiae 1472 Petr Schoiffer IIO7 de Gerneshem n 2089   \n",
       "6                                                                                                       Biblia Sacra latina vulgatae Editionis 2 Vol charta IIIB3 Magna 1474 absque loco Editionis n 2090   \n",
       "7                                                                                        Biblia Sacra Latina cum Evangelistarum Canonibus IIIB7 & concordantiis charta M Coloniae 1479 de Homborch n 2093   \n",
       "8                                                                                                                             Biblia Sacra Latina Venetiis 1481 Leonard Wild de Ratisbona n 2302 III D 11   \n",
       "...                                                                                                                                                                                                   ...   \n",
       "9017                                                                                                               Tractatus de Matrimonio a Fr Lucano Parmensi compilat anno 1468 Ms in Membranis n CCIX   \n",
       "9033                                                                                                                                        Monita Agapaeti Batilica ad Imper Iustinian Ms graece  A 1500   \n",
       "9051  Succineta & accurata de scriptio Civitatis Constantinopol a Constantino Magno anno 331 ad Sult Mehemet II anno 1453 cum descriptione Canalis Maris Nigri autore Ioan Adamo Zizla Ms in 8° germanice   \n",
       "9052                                  ITrionfi di Francesco Petrarca con miniature Ms 8° 11 Questo Ms° e del tempo del medesimo Petrarca n CCXXXIV obüt Petrarca an 1374 & codex in fine habet 1459 p 519   \n",
       "9059                           Descriptio civitatis Constantinopoleos a Constantino M anno 331 ad Sultanum Mehemet II anno 1453 cum descriptione Canalis Maris Nigri autore I Adamo Zizla 8° Ms germanice   \n",
       "\n",
       "             years  \n",
       "3           [1462]  \n",
       "4           [1472]  \n",
       "6           [1474]  \n",
       "7           [1479]  \n",
       "8           [1481]  \n",
       "...            ...  \n",
       "9017        [1468]  \n",
       "9033        [1500]  \n",
       "9051        [1453]  \n",
       "9052  [1374, 1459]  \n",
       "9059        [1453]  \n",
       "\n",
       "[366 rows x 10 columns]"
      ]
     },
     "execution_count": 526,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "before_1501"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 527,
   "id": "740e1929-f137-4853-82db-3d90905beed4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume</th>\n",
       "      <th>page number</th>\n",
       "      <th>category</th>\n",
       "      <th>subcategory</th>\n",
       "      <th>format</th>\n",
       "      <th>handwritten page number</th>\n",
       "      <th>entry_ID</th>\n",
       "      <th>entry</th>\n",
       "      <th>cleaned entry</th>\n",
       "      <th>years</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>14.376</td>\n",
       "      <td>25</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>1</td>\n",
       "      <td>14.376_025_05</td>\n",
       "      <td>6 Biblia Sacra Latina cum glossa &amp; Comment. 4 Vol. chartâ Magnâ. Editio perantiqua sine loco &amp; II.O.1. anno n. 2086.</td>\n",
       "      <td>Biblia Sacra Latina cum glossa &amp; Comment 4 Vol charta Magna Editio perantiqua sine loco &amp; IIO1 anno n 2086</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>14.376</td>\n",
       "      <td>27</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>3</td>\n",
       "      <td>14.376_027_02</td>\n",
       "      <td>18 La S.e Bible historiée dite d'Escholatre avec des fig. gravées en bois. 2 Vol. sans datte. Barthel. Verard. n. 165.</td>\n",
       "      <td>La Se Bible historiee dite d'Escholatre avec des fig gravees en bois 2 Vol sans datte Barthel Verard n 165</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>14.376</td>\n",
       "      <td>27</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>3</td>\n",
       "      <td>14.376_027_06</td>\n",
       "      <td>22 Biblia Sacra germanicè Mss. in Membranis cum figuris pictis. n. II.</td>\n",
       "      <td>Biblia Sacra germanice Mss in Membranis cum figuris pictis n II</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>14.376</td>\n",
       "      <td>27</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>3</td>\n",
       "      <td>14.376_027_07</td>\n",
       "      <td>23 Biblia Sacra Hollandicé Mss. in Membranis cum fig. pictis. 2 Vol. n. III.</td>\n",
       "      <td>Biblia Sacra Hollandice Mss in Membranis cum fig pictis 2 Vol n III</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>14.376</td>\n",
       "      <td>27</td>\n",
       "      <td>Theologia</td>\n",
       "      <td>Textus &amp; Versiones Sacræ Scripturæ</td>\n",
       "      <td>Folio</td>\n",
       "      <td>3</td>\n",
       "      <td>14.376_027_09</td>\n",
       "      <td>25 Historia Veteris ac Novi Testamenti MS. in Membranis cum innumeris ferè Imaginibus miniatè depictis. n. 1.</td>\n",
       "      <td>Historia Veteris ac Novi Testamenti MS in Membranis cum innumeris fere Imaginibus miniate depictis n 1</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9398</th>\n",
       "      <td>14.378</td>\n",
       "      <td>582</td>\n",
       "      <td>Imaginum Delineatarum Collectio</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1402</td>\n",
       "      <td>14.378_582_00</td>\n",
       "      <td>CCCXXXI Vn Portefeüilles contenant des Desseins de plusieurs Villes d'Espagne par Ant. Van-den-Wingarde. dont il n'y a pas de Catalogue. n. 990.</td>\n",
       "      <td>Vn Portefeüilles contenant des Desseins de plusieurs Villes d'Espagne par Ant Van-den-Wingarde dont il n'y a pas de Catalogue n 990</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9399</th>\n",
       "      <td>14.378</td>\n",
       "      <td>582</td>\n",
       "      <td>Imaginum Delineatarum Collectio</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1402</td>\n",
       "      <td>14.378_582_01</td>\n",
       "      <td>CCCXXXII  Vn Recueil des Portraits peints en miniature sur velain au nombre de 34. dont le Premier est celuy de Philippe le Hardy. n. CCIV.</td>\n",
       "      <td>Vn Recueil des Portraits peints en miniature sur velain au nombre de 34 dont le Premier est celuy de Philippe le Hardy n CCIV</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9400</th>\n",
       "      <td>14.378</td>\n",
       "      <td>582</td>\n",
       "      <td>Imaginum Delineatarum Collectio</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1402</td>\n",
       "      <td>14.378_582_02</td>\n",
       "      <td>CCCXXXIII  Dix Vol. de Plantes peintes en miniature par Nicol. Robert. vide. Hist. Plantarum</td>\n",
       "      <td>Dix Vol de Plantes peintes en miniature par Nicol Robert vide Hist Plantarum</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9401</th>\n",
       "      <td>14.378</td>\n",
       "      <td>582</td>\n",
       "      <td>Imaginum Delineatarum Collectio</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1402</td>\n",
       "      <td>14.378_582_03</td>\n",
       "      <td>CCCXXXIV  Cinq Vol. d'Oiseaux peints en Miniature par Nic. Robert. vide. Histor. Animalium.</td>\n",
       "      <td>Cinq Vol d'Oiseaux peints en Miniature par Nic Robert vide Histor Animalium</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9402</th>\n",
       "      <td>14.378</td>\n",
       "      <td>582</td>\n",
       "      <td>Imaginum Delineatarum Collectio</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1402</td>\n",
       "      <td>14.378_582_04</td>\n",
       "      <td>CCCXXXV Divers Portraits, Ceremonies, Marches &amp;c. des Turcs &amp; d'autres nations du Levant, peints en miniature n. CCLXX.</td>\n",
       "      <td>Divers Portraits Ceremonies Marches &amp;c des Turcs &amp; d'autres nations du Levant peints en miniature n CCLXX</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1324 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      volume  page number                         category   \n",
       "5     14.376           25                        Theologia  \\\n",
       "17    14.376           27                        Theologia   \n",
       "21    14.376           27                        Theologia   \n",
       "22    14.376           27                        Theologia   \n",
       "24    14.376           27                        Theologia   \n",
       "...      ...          ...                              ...   \n",
       "9398  14.378          582  Imaginum Delineatarum Collectio   \n",
       "9399  14.378          582  Imaginum Delineatarum Collectio   \n",
       "9400  14.378          582  Imaginum Delineatarum Collectio   \n",
       "9401  14.378          582  Imaginum Delineatarum Collectio   \n",
       "9402  14.378          582  Imaginum Delineatarum Collectio   \n",
       "\n",
       "                             subcategory format handwritten page number   \n",
       "5     Textus & Versiones Sacræ Scripturæ  Folio                       1  \\\n",
       "17    Textus & Versiones Sacræ Scripturæ  Folio                       3   \n",
       "21    Textus & Versiones Sacræ Scripturæ  Folio                       3   \n",
       "22    Textus & Versiones Sacræ Scripturæ  Folio                       3   \n",
       "24    Textus & Versiones Sacræ Scripturæ  Folio                       3   \n",
       "...                                  ...    ...                     ...   \n",
       "9398                                 NaN    NaN                    1402   \n",
       "9399                                 NaN    NaN                    1402   \n",
       "9400                                 NaN    NaN                    1402   \n",
       "9401                                 NaN    NaN                    1402   \n",
       "9402                                 NaN    NaN                    1402   \n",
       "\n",
       "           entry_ID   \n",
       "5     14.376_025_05  \\\n",
       "17    14.376_027_02   \n",
       "21    14.376_027_06   \n",
       "22    14.376_027_07   \n",
       "24    14.376_027_09   \n",
       "...             ...   \n",
       "9398  14.378_582_00   \n",
       "9399  14.378_582_01   \n",
       "9400  14.378_582_02   \n",
       "9401  14.378_582_03   \n",
       "9402  14.378_582_04   \n",
       "\n",
       "                                                                                                                                                 entry   \n",
       "5                                 6 Biblia Sacra Latina cum glossa & Comment. 4 Vol. chartâ Magnâ. Editio perantiqua sine loco & II.O.1. anno n. 2086.  \\\n",
       "17                              18 La S.e Bible historiée dite d'Escholatre avec des fig. gravées en bois. 2 Vol. sans datte. Barthel. Verard. n. 165.   \n",
       "21                                                                              22 Biblia Sacra germanicè Mss. in Membranis cum figuris pictis. n. II.   \n",
       "22                                                                        23 Biblia Sacra Hollandicé Mss. in Membranis cum fig. pictis. 2 Vol. n. III.   \n",
       "24                                       25 Historia Veteris ac Novi Testamenti MS. in Membranis cum innumeris ferè Imaginibus miniatè depictis. n. 1.   \n",
       "...                                                                                                                                                ...   \n",
       "9398  CCCXXXI Vn Portefeüilles contenant des Desseins de plusieurs Villes d'Espagne par Ant. Van-den-Wingarde. dont il n'y a pas de Catalogue. n. 990.   \n",
       "9399       CCCXXXII  Vn Recueil des Portraits peints en miniature sur velain au nombre de 34. dont le Premier est celuy de Philippe le Hardy. n. CCIV.   \n",
       "9400                                                      CCCXXXIII  Dix Vol. de Plantes peintes en miniature par Nicol. Robert. vide. Hist. Plantarum   \n",
       "9401                                                       CCCXXXIV  Cinq Vol. d'Oiseaux peints en Miniature par Nic. Robert. vide. Histor. Animalium.   \n",
       "9402                           CCCXXXV Divers Portraits, Ceremonies, Marches &c. des Turcs & d'autres nations du Levant, peints en miniature n. CCLXX.   \n",
       "\n",
       "                                                                                                                            cleaned entry   \n",
       "5                              Biblia Sacra Latina cum glossa & Comment 4 Vol charta Magna Editio perantiqua sine loco & IIO1 anno n 2086  \\\n",
       "17                             La Se Bible historiee dite d'Escholatre avec des fig gravees en bois 2 Vol sans datte Barthel Verard n 165   \n",
       "21                                                                        Biblia Sacra germanice Mss in Membranis cum figuris pictis n II   \n",
       "22                                                                    Biblia Sacra Hollandice Mss in Membranis cum fig pictis 2 Vol n III   \n",
       "24                                 Historia Veteris ac Novi Testamenti MS in Membranis cum innumeris fere Imaginibus miniate depictis n 1   \n",
       "...                                                                                                                                   ...   \n",
       "9398  Vn Portefeüilles contenant des Desseins de plusieurs Villes d'Espagne par Ant Van-den-Wingarde dont il n'y a pas de Catalogue n 990   \n",
       "9399        Vn Recueil des Portraits peints en miniature sur velain au nombre de 34 dont le Premier est celuy de Philippe le Hardy n CCIV   \n",
       "9400                                                         Dix Vol de Plantes peintes en miniature par Nicol Robert vide Hist Plantarum   \n",
       "9401                                                          Cinq Vol d'Oiseaux peints en Miniature par Nic Robert vide Histor Animalium   \n",
       "9402                            Divers Portraits Ceremonies Marches &c des Turcs & d'autres nations du Levant peints en miniature n CCLXX   \n",
       "\n",
       "     years  \n",
       "5       []  \n",
       "17      []  \n",
       "21      []  \n",
       "22      []  \n",
       "24      []  \n",
       "...    ...  \n",
       "9398    []  \n",
       "9399    []  \n",
       "9400    []  \n",
       "9401    []  \n",
       "9402    []  \n",
       "\n",
       "[1324 rows x 10 columns]"
      ]
     },
     "execution_count": 527,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_years"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 530,
   "id": "1bacd9fd-af4a-4f50-b0bc-10a4a5af1ee8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "before_1501.to_excel('data/man_catalog/Vor 1501.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 531,
   "id": "dbd5e8bc-a4a0-46f7-b0ca-8fe84de50e19",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "without_years.to_excel('data/man_catalog/Ohne Jahresangabe.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36866c95-917c-48a6-9c2d-0ce1f9f9f8b2",
   "metadata": {},
   "source": [
    "# Mehrfache matches hinzufuegen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 661,
   "id": "b8870950-aee8-42ab-9cc5-07f9d2e419ab",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup = pd.read_excel('../Daten/Vorhersagen/Complete_BE_Years_Places.xlsx', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 662,
   "id": "2141ab45-491f-4f95-af8e-339a3b9d0a1f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup.drop(['hs. Katalog', 'hs. Katalog Konfidenz', 'hs. Katalogband',\n",
    "       'hs. Katalogseite Digitalisat', 'Wissensklasse', 'Wissensunterklasse',\n",
    "       'Formatangabe', 'hs. Katalogseite Handschrift', 'hs. Katalogeintrag ID',\n",
    "       'hs. Katalogeintrag', 'hs. Katalog Image URL'], axis=1, inplace=True)\n",
    "comp_BE_no_dup['hs. Katalog'] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 663,
   "id": "49a2de57-0529-4f3d-bd54-7ce1665b05f5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(['1234'], ['4564'])\n",
      "([], ['2'])\n",
      "(['234'], ['345'])\n",
      "(['234', '345'], [])\n",
      "(['44'], [])\n",
      "([], ['2', '55'])\n"
     ]
    }
   ],
   "source": [
    "match_examples = ['1234, 4564?', '2?', '345?,234', '234,345', '44', '2?, 55?']\n",
    "\n",
    "def get_matches_from_entry(s):\n",
    "    certain_match = re.compile('\\d{1,4}\\Z|\\d{1,4},')\n",
    "    certs = certain_match.findall(s)\n",
    "    uncertain_match = re.compile('\\d{1,4}\\?')\n",
    "    uncerts = uncertain_match.findall(s)\n",
    "    clean_certs = [s.replace(',', '') for s in certs]\n",
    "    clean_uncerts = [s.replace('?', '') for s in uncerts]\n",
    "    return clean_certs, clean_uncerts\n",
    "\n",
    "for m in match_examples:\n",
    "    print(get_matches_from_entry(m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 694,
   "id": "cef309b5-651d-4ac4-b605-2cb55d0e2468",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22638\n",
      "21039\n",
      "20015\n",
      "22573\n",
      "22574\n",
      "22575\n",
      "22576\n",
      "22577\n",
      "22578\n",
      "22579\n",
      "22580\n",
      "22581\n",
      "22582\n",
      "22583\n"
     ]
    }
   ],
   "source": [
    "def get_new_index(old_id):\n",
    "    old_row = BE_df.loc[old_id]\n",
    "    sig = old_row['Signatur'].replace(';', '')\n",
    "    cand = comp_BE_no_dup[comp_BE_no_dup['Signatur'].str.contains(sig, regex=False)]\n",
    "    try:\n",
    "        new_index = cand.index[0]\n",
    "    except IndexError as e:\n",
    "        print(sig, old_id)\n",
    "        new_index = -1\n",
    "    return new_index\n",
    "    \n",
    "test_indices = [22640, 22503, 22506, 22575, 22576, 22577, 22578, 22579, 22580, 22581, 22582, 22583, 22584, 22585]\n",
    "for idx in test_indices:\n",
    "    print(get_new_index(idx))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 695,
   "id": "64685c07-6cc4-490f-8a56-44798693c039",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "dod_id = {\n",
    "    '14.376': 51202, \n",
    "    '14.377': 51184,\n",
    "    '14.378': 51219\n",
    "}\n",
    "\n",
    "for i, entry in has_hw_catalog.iterrows():\n",
    "    BE_id = get_new_index(entry['input_id'])\n",
    "    if BE_id == -1:\n",
    "        continue\n",
    "    man_match = str(entry['control'])\n",
    "    certain, uncertain = get_matches_from_entry(man_match)\n",
    "    match_dict = {\n",
    "        'hs. Katalog': 1,\n",
    "        'hs. Katalog Konfidenz': [],\n",
    "        'hs. Katalogband': [],\n",
    "        'hs. Katalogseite Digitalisat': [],\n",
    "        'Wissensklasse': [],\n",
    "        'Wissensunterklasse': [],\n",
    "        'Formatangabe': [],\n",
    "        'hs. Katalogseite Handschrift': [],\n",
    "        'hs. Katalogeintrag ID': [],\n",
    "        'hs. Katalogeintrag': [],\n",
    "        'hs. Katalog Image URL': []\n",
    "    }\n",
    "    for m in certain:\n",
    "        match_dict['hs. Katalog Konfidenz'] += ['sicher']\n",
    "    for m in uncertain:\n",
    "        match_dict['hs. Katalog Konfidenz'] += ['unsicher']\n",
    "    \n",
    "    all_matches = certain + uncertain\n",
    "    \n",
    "    for m in all_matches:\n",
    "        hw_entry = entry_df.loc[int(m)]\n",
    "        match_dict['hs. Katalogband'] += [str(hw_entry['volume'])]\n",
    "        match_dict['hs. Katalogseite Digitalisat'] += [str(hw_entry['page number'])]\n",
    "        match_dict['Wissensklasse'] += [hw_entry['category']]\n",
    "        match_dict['Wissensunterklasse'] += [hw_entry['subcategory'] if not pd.isna(hw_entry['subcategory']) else '']\n",
    "        match_dict['Formatangabe'] += [hw_entry['format'] if not pd.isna(hw_entry['format']) else '']\n",
    "        match_dict['hs. Katalogseite Handschrift'] += [hw_entry['handwritten page number']]\n",
    "        match_dict['hs. Katalogeintrag ID'] += [hw_entry['entry_ID']]\n",
    "        match_dict['hs. Katalogeintrag'] += [hw_entry['entry']]\n",
    "        match_dict['hs. Katalog Image URL'] += [f\"https://iiif.onb.ac.at/images/DOD/{dod_id[str(hw_entry['volume'])]}/{hw_entry['page number']:08}.jp2/full/full/0/native.jpg\"]\n",
    "    \n",
    "    for key, val in match_dict.items():\n",
    "        if key != 'hs. Katalog':\n",
    "            val = ' | '.join(val)\n",
    "        comp_BE_no_dup.at[BE_id, key] = val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 696,
   "id": "32f8736c-3c87-464b-ba0b-289d902d00d8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "\n",
    "comp_BE_no_dup.drop(['Schlagwörter', 'Schlagwörter (mit GND)', 'Vorbesitzer', 'Typ', 'Bemerkungen', 'Gültiger Barcode', 'identifier', 'ABO-Barcode', 'Barcode category'], axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 698,
   "id": "df0fe094-4af0-4dcc-be9f-e0164f46a792",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "ink_corrections = [\n",
    "    {'id': 23610, 'Signatur': 'Ink 4.H.15', 'Titel': 'Epistolae [Italian] (Tr: Bartholomaeus Fontius, from the Latin version of Franciscus Griffolinus (Aretinus))', 'Autor': 'Phalaris [VerfasserIn]', 'Mitwirkender': 'Laurentius Canozius, de Lendenaria] [DruckerIn]', 'Veröffentlichungsdatum': '1471', 'Veröffentlichungsort': 'Padua', 'Veröffentlichungsort (normiert)': 'Padua', 'Sprache': 'Italian'},\n",
    "    {'id': 23621, 'Signatur': 'Ink 12.F.23', 'Titel': 'Miscellaneorum centuria prima', 'Autor': 'Politianus, Angelus [VerfasserIn]', 'Mitwirkender': 'Antonio di Bartolommeo Miscomini [DruckerIn]', 'Veröffentlichungsdatum': '19 Sept. 1489', 'Veröffentlichungsort': 'Florence', 'Veröffentlichungsort (normiert)': 'Florenz', 'Sprache': 'Latin'}\n",
    "]\n",
    "\n",
    "for ink_dict in ink_corrections:\n",
    "    BE_id = ink_dict['id']\n",
    "    for key, value in ink_dict.items():\n",
    "        if key != 'id':\n",
    "            comp_BE_no_dup.at[BE_id, key] = value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 700,
   "id": "000dd820-71f0-4b7a-bb4d-39f34a1dde6b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Latin\n"
     ]
    }
   ],
   "source": [
    "test_str = 'Latin; Latin'\n",
    "\n",
    "def take_up_to_semicolon(s):\n",
    "    if not pd.isna(s) and ';' in s:\n",
    "        return s[:s.index(';')]\n",
    "    else:\n",
    "        return s\n",
    "\n",
    "print(take_up_to_semicolon(test_str))\n",
    "\n",
    "comp_BE_no_dup['Sprache'] = comp_BE_no_dup['Sprache'].apply(lambda x: take_up_to_semicolon(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 701,
   "id": "631a3a3e-122c-4578-abf1-9528d71f3999",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup['Veröffentlichungsort'] = comp_BE_no_dup['Veröffentlichungsort'].apply(lambda x: take_up_to_semicolon(x))\n",
    "comp_BE_no_dup['Veröffentlichungsort (normiert)'] = comp_BE_no_dup['Veröffentlichungsort (normiert)'].apply(lambda x: take_up_to_semicolon(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 702,
   "id": "26350fd8-8511-4ec5-97f4-4fe4d14e1c38",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup['Signatur'] = comp_BE_no_dup['Signatur'].str.replace('Be.', 'BE.')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be4664e0-239b-4995-a92f-5514c607d828",
   "metadata": {},
   "source": [
    "# IIIF Manifeste checken"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 604,
   "id": "c141bbb6-d11b-4b9f-8548-4bac19aa9943",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ac6e38d0a07c4031ab8d3a20c008ae51",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "  0%|          | 0/22861 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def get_iiif_manifest_url(bc):\n",
    "    if not pd.isna(bc):\n",
    "        abo_match = re.search('Z\\d{8,9}X?', bc)\n",
    "        dtl_match = re.search('dtl_(\\d+)', bc)\n",
    "        if abo_match:\n",
    "            url = f'https://iiif.onb.ac.at/presentation/ABO/{abo_match[0]}/manifest'\n",
    "        elif dtl_match:\n",
    "            url = f'https://iiif.onb.ac.at/presentation/REPO/{dtl_match[0]}/manifest'\n",
    "        else:\n",
    "            url = ''\n",
    "    else:\n",
    "        url = ''\n",
    "    if len(url):\n",
    "        resp = requests.get(url)\n",
    "        if resp.status_code != 200:\n",
    "            url = ''\n",
    "    return url\n",
    "\n",
    "iiif_manifests = []\n",
    "barcodes = comp_BE_no_dup['Barcode']\n",
    "for bc in tqdm(barcodes):\n",
    "    iiif_manifests.append(get_iiif_manifest_url(bc))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 703,
   "id": "6321941f-31b9-48f3-ad50-35b9171d0d0d",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup['IIIF Manifest'] = iiif_manifests"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4542b9de-c865-4671-aec7-79f3dba425c2",
   "metadata": {},
   "source": [
    "# Duplikate mit hs. Matches nachtragen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 708,
   "id": "91592e14-b2a5-42ea-8cef-4b526fbcf8d1",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup['dup_title'] = comp_BE_no_dup['Titel'].duplicated(keep=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 711,
   "id": "82fda755-67c5-459e-81fd-f3ace6ebc905",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Zwischenstand speichern\n",
    "comp_BE_no_dup.to_excel('../Daten/Vorhersagen/WIP_final_BE.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d2c80bbc-a1e5-4eed-90a7-b060229ce635",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Zwischenstand abrufen\n",
    "comp_BE_no_dup = pd.read_excel('../Daten/Vorhersagen/WIP_final_BE.xlsx', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "62e868eb-4442-4e86-8e3f-43f3bc0cb741",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from thefuzz import fuzz\n",
    "\n",
    "dup_candidates = comp_BE_no_dup[comp_BE_no_dup['dup_title'] & comp_BE_no_dup['hs. Katalog']]\n",
    "comp_BE_no_dup['copy_from'] = -1\n",
    "\n",
    "for i, row in dup_candidates.iterrows():\n",
    "    title = row['Titel']\n",
    "    sig = row['Signatur']\n",
    "    dup_group = comp_BE_no_dup[(comp_BE_no_dup['Titel'] == title) & ~comp_BE_no_dup['hs. Katalog']]\n",
    "    for j, dup in dup_group.iterrows():\n",
    "        sim_score = fuzz.ratio(sig, dup['Signatur'])\n",
    "        if sim_score > 80: # Signatur ähnlich\n",
    "            comp_BE_no_dup.at[j, 'copy_from'] = i\n",
    "        else: # Signatur nicht ähnlich genug\n",
    "            comp_BE_no_dup.at[j, 'copy_from'] = -2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9cdc5f3-b379-4645-ad9f-bccab2aed5b5",
   "metadata": {},
   "source": [
    "## Für unähnliche Signaturen müssen die Titel manuell getrennt werden"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "94a92e39-e2d3-44b1-a705-6b7a78781017",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "journal_des_scavans = comp_BE_no_dup[(comp_BE_no_dup['Titel'] == 'Le Journal des Scavans') & (comp_BE_no_dup['copy_from'] == -2)]\n",
    "\n",
    "for i, row in journal_des_scavans.iterrows():\n",
    "    comp_BE_no_dup.at[i, 'copy_from'] = 1721"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "a42e53d9-8b5c-4184-a728-3ca74808bbb8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "journal_des_scavans_2 = comp_BE_no_dup[(comp_BE_no_dup['Titel'] == 'Le Journal des scavans ... [Annee 1665-1732]') & (comp_BE_no_dup['copy_from'] == -2)]\n",
    "\n",
    "for i, row in journal_des_scavans_2.iterrows():\n",
    "    comp_BE_no_dup.at[i, 'copy_from'] = 4656"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "a193a3e6-c9da-4865-a82d-534bec26b3f5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "acad_scienc = comp_BE_no_dup[(comp_BE_no_dup['Titel'] == \"Histoire De L'Academie Royale Des Sciences Avec les Memoires de Mathematique & de Physique\") \\\n",
    "                             & (comp_BE_no_dup['copy_from'] == -2)]\n",
    "\n",
    "for i, row in acad_scienc.iterrows():\n",
    "    comp_BE_no_dup.at[i, 'copy_from'] = 3395"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "7f91840a-d28e-42c5-a9f7-9052106be568",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "not_similar = comp_BE_no_dup[comp_BE_no_dup['copy_from'] == -2]\n",
    "\n",
    "for i, row in not_similar.iterrows():\n",
    "    dup_group = comp_BE_no_dup[(comp_BE_no_dup['Titel'] == row['Titel']) & (comp_BE_no_dup['copy_from'] == -2 | comp_BE_no_dup['hs. Katalog'])]\n",
    "    print('Checking entry', i)\n",
    "    display(dup_group)\n",
    "    copy_from = input('Copy from where?')\n",
    "    comp_BE_no_dup.at[i, 'copy_from'] = copy_from"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27416f47-65de-40cb-9f8a-868c4890d1df",
   "metadata": {},
   "source": [
    "## Kopieren der hs. Katalogeinträge"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "be7ab409-d7d4-4fd0-9768-08037e9a20b3",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup['copy_from'] = comp_BE_no_dup['copy_from'].apply(lambda x: int(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "8a32bfe0-b019-4098-a66c-480bcfeda317",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "to_be_copied = comp_BE_no_dup[(comp_BE_no_dup['copy_from'] != -1) & (comp_BE_no_dup['copy_from'] != -3)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "a0ced607-f6e4-4a78-bbb7-be8d9889445c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "for i, row in to_be_copied.iterrows():\n",
    "    j = row['copy_from']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalog'] = comp_BE_no_dup.at[j, 'hs. Katalog']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalog Konfidenz'] = comp_BE_no_dup.at[j, 'hs. Katalog Konfidenz']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogband'] = comp_BE_no_dup.at[j, 'hs. Katalogband']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogseite Digitalisat'] = comp_BE_no_dup.at[j, 'hs. Katalogseite Digitalisat']\n",
    "    comp_BE_no_dup.at[i, 'Wissensklasse'] = comp_BE_no_dup.at[j, 'Wissensklasse']\n",
    "    comp_BE_no_dup.at[i, 'Wissensunterklasse'] = comp_BE_no_dup.at[j, 'Wissensunterklasse']\n",
    "    comp_BE_no_dup.at[i, 'Formatangabe'] = comp_BE_no_dup.at[j, 'Formatangabe']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogseite Handschrift'] = comp_BE_no_dup.at[j, 'hs. Katalogseite Handschrift']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogeintrag ID'] = comp_BE_no_dup.at[j, 'hs. Katalogeintrag ID']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogeintrag'] = comp_BE_no_dup.at[j, 'hs. Katalogeintrag']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalog Image URL'] = comp_BE_no_dup.at[j, 'hs. Katalog Image URL']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "0bd4b034-90f3-4289-83ba-0396a0cf0646",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Signatur', 'Barcode', 'Titel', 'Autor', 'Mitwirkender',\n",
       "       'Anfang Veröffentlichungsdatum', 'Ende Veröffentlichungsdatum',\n",
       "       'Veröffentlichungsdatum', 'Veröffentlichungsort',\n",
       "       'Veröffentlichungsort (normiert)', 'Sprache', 'Dateiname',\n",
       "       'Wappenklassifizierung', 'p_A', 'p_B', 'p_C', 'p_N',\n",
       "       'Farbklassifizierung', 'p_blue', 'p_red', 'p_yellow', 'IIIF Manifest',\n",
       "       'hs. Katalog', 'hs. Katalog Konfidenz', 'hs. Katalogband',\n",
       "       'hs. Katalogseite Digitalisat', 'Wissensklasse', 'Wissensunterklasse',\n",
       "       'Formatangabe', 'hs. Katalogseite Handschrift', 'hs. Katalogeintrag ID',\n",
       "       'hs. Katalogeintrag', 'hs. Katalog Image URL', 'dup_title',\n",
       "       'copy_from'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comp_BE_no_dup.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "a5507d98-a6be-4108-a70f-c09404f8de79",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Zwischenstand speichern\n",
    "comp_BE_no_dup.to_excel('../Daten/Vorhersagen/WIP_final_BE_2.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 724,
   "id": "315500ea-0225-4b2c-b568-082f5250dd4e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "comp_BE_no_dup = pd.read_excel('../Daten/Vorhersagen/WIP_final_BE_2.xlsx', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 772,
   "id": "ef48a633-fb96-4ae2-b024-9f8e6f7beb01",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Signatur', 'Barcode', 'Titel', 'Autor', 'Mitwirkender',\n",
       "       'Anfang Veröffentlichungsdatum', 'Ende Veröffentlichungsdatum',\n",
       "       'Veröffentlichungsdatum', 'Veröffentlichungsort',\n",
       "       'Veröffentlichungsort (normiert)', 'Sprache', 'Dateiname',\n",
       "       'Wappenklassifizierung', 'p_A', 'p_B', 'p_C', 'p_N',\n",
       "       'Farbklassifizierung', 'p_blue', 'p_red', 'p_yellow', 'IIIF Manifest',\n",
       "       'hs. Katalog', 'hs. Katalog Konfidenz', 'hs. Katalogband',\n",
       "       'hs. Katalogseite Digitalisat', 'Wissensklasse', 'Wissensunterklasse',\n",
       "       'Formatangabe', 'hs. Katalogseite Handschrift', 'hs. Katalogeintrag ID',\n",
       "       'hs. Katalogeintrag', 'hs. Katalog Image URL', 'dup_title',\n",
       "       'copy_from'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 772,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comp_BE_no_dup.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 870,
   "id": "ffc781e2-21f4-48c8-9e01-f57f677b11a6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22614    https://iiif.onb.ac.at/presentation/ABO/Z22196790X/manifest\n",
       "897      https://iiif.onb.ac.at/presentation/ABO/Z165135008/manifest\n",
       "898      https://iiif.onb.ac.at/presentation/ABO/Z165135100/manifest\n",
       "900      https://iiif.onb.ac.at/presentation/ABO/Z165135203/manifest\n",
       "901      https://iiif.onb.ac.at/presentation/ABO/Z165135306/manifest\n",
       "                                    ...                             \n",
       "22236    https://iiif.onb.ac.at/presentation/ABO/Z200809106/manifest\n",
       "22237    https://iiif.onb.ac.at/presentation/ABO/Z200809209/manifest\n",
       "22238    https://iiif.onb.ac.at/presentation/ABO/Z200809301/manifest\n",
       "22239    https://iiif.onb.ac.at/presentation/ABO/Z200809404/manifest\n",
       "22240    https://iiif.onb.ac.at/presentation/ABO/Z200809507/manifest\n",
       "Name: IIIF Manifest, Length: 3364, dtype: object"
      ]
     },
     "execution_count": 870,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comp_BE_no_dup[comp_BE_no_dup['hs. Katalogeintrag ID'].isin(entry_df[entry_df['format'] == 'Octavo und kleiner']['entry_ID'])]['IIIF Manifest'].dropna()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67d13156-4cc6-4db4-92f3-41031203ce7c",
   "metadata": {},
   "source": [
    "# Cluster im Regal ermitteln"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 882,
   "id": "3c414e9c-021d-4172-87ce-32fb6a08c9a6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7950\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_4673/1024163498.py:6: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  has_hw_catalog['first_num'] = has_hw_catalog['control'].apply(lambda x: int(match.search(str(x))[0]))\n"
     ]
    }
   ],
   "source": [
    "s = '7950, 9247'\n",
    "\n",
    "match = re.compile('\\d{1,4}\\Z|\\d{1,4}|\\d{1,4}\\?,')\n",
    "print(match.search(s)[0])\n",
    "\n",
    "has_hw_catalog['first_num'] = has_hw_catalog['control'].apply(lambda x: int(match.search(str(x))[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 905,
   "id": "cc5e0d88-a88e-4926-8f1a-65d0415ea3dc",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "no_sort_m = has_hw_catalog['first_num'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1060,
   "id": "acff6cc5-e585-47b2-a91f-f1191d47de04",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def get_longest_sequence(lis):\n",
    "    differences = [abs(lis[n+1] - lis[n]) for n in range(len(lis) - 1)]\n",
    "    ids = [entry_df.loc[n]['entry_ID'] for n in lis]\n",
    "    \n",
    "    is_nearby = [n < 10 for n in differences]\n",
    "    \n",
    "    c = 0\n",
    "    seq_length = []\n",
    "    for i, num in enumerate(is_nearby):\n",
    "        if num:\n",
    "            c += 1\n",
    "        else:\n",
    "            c = 0\n",
    "        seq_length.append((i, c))\n",
    "    \n",
    "    sort_seq = sorted(seq_length, key=lambda x: x[1], reverse=True)\n",
    "    places = pd.Series([n[0] - n[1] + 1  for n in sort_seq], name='location')\n",
    "    places_no_dup = places.drop_duplicates()\n",
    "    seq_df = pd.DataFrame(places_no_dup)\n",
    "    seq_df['length'] = [sort_seq[x][1] for x in seq_df.index]\n",
    "    seq_df['first_BE_location'] = seq_df['location'].apply(lambda x: has_hw_catalog.iloc[x]['input_id'])\n",
    "    seq_df['last_location'] = seq_df['location'] + seq_df['length']\n",
    "    seq_df['last_BE_location'] = seq_df['last_location'].apply(lambda x: has_hw_catalog.iloc[x]['input_id'])\n",
    "    seq_df['first_hw_id'] = seq_df['location'].apply(lambda x: ids[x])\n",
    "    seq_df['last_hw_id'] = seq_df['last_location'].apply(lambda x: ids[x])\n",
    "    \n",
    "    return seq_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1061,
   "id": "bbb4d50a-72f8-4368-9966-0d0ea590c06f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "seq = get_longest_sequence(no_sort_m)\n",
    "seq['erste Signatur'] = seq['first_BE_location'].apply(lambda x: BE_df.loc[x]['Signatur'])\n",
    "seq['letzte Signatur'] = seq['last_BE_location'].apply(lambda x: BE_df.loc[x]['Signatur'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1089,
   "id": "81ed055b-34f7-420f-8391-9ffc8f8efc89",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>location</th>\n",
       "      <th>length</th>\n",
       "      <th>first_BE_location</th>\n",
       "      <th>last_location</th>\n",
       "      <th>last_BE_location</th>\n",
       "      <th>first_hw_id</th>\n",
       "      <th>last_hw_id</th>\n",
       "      <th>erste Signatur</th>\n",
       "      <th>letzte Signatur</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>931</td>\n",
       "      <td>24</td>\n",
       "      <td>4261</td>\n",
       "      <td>955</td>\n",
       "      <td>4285</td>\n",
       "      <td>14.377_079_01</td>\n",
       "      <td>14.377_079_23</td>\n",
       "      <td>BE.11.L.31</td>\n",
       "      <td>BE.11.L.35.(4)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4116</td>\n",
       "      <td>22</td>\n",
       "      <td>15231</td>\n",
       "      <td>4138</td>\n",
       "      <td>15275</td>\n",
       "      <td>14.378_211_03</td>\n",
       "      <td>14.378_215_01</td>\n",
       "      <td>BE.6.M.1-16.(Vol.1)</td>\n",
       "      <td>BE.6.M.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>907</td>\n",
       "      <td>19</td>\n",
       "      <td>4237</td>\n",
       "      <td>926</td>\n",
       "      <td>4256</td>\n",
       "      <td>14.377_078_01</td>\n",
       "      <td>14.377_078_19</td>\n",
       "      <td>BE.11.L.18</td>\n",
       "      <td>BE.11.L.22.(3)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>3524</td>\n",
       "      <td>18</td>\n",
       "      <td>13400</td>\n",
       "      <td>3542</td>\n",
       "      <td>13418</td>\n",
       "      <td>14.376_325_03</td>\n",
       "      <td>14.376_328_01</td>\n",
       "      <td>BE.5.N.30</td>\n",
       "      <td>BE.5.N.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2599</td>\n",
       "      <td>17</td>\n",
       "      <td>10388</td>\n",
       "      <td>2616</td>\n",
       "      <td>10405</td>\n",
       "      <td>14.376_259_05</td>\n",
       "      <td>14.376_262_01</td>\n",
       "      <td>BE.3.W.14</td>\n",
       "      <td>BE.3.W.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>3674</td>\n",
       "      <td>17</td>\n",
       "      <td>13828</td>\n",
       "      <td>3691</td>\n",
       "      <td>13846</td>\n",
       "      <td>14.376_435_04</td>\n",
       "      <td>14.376_438_01</td>\n",
       "      <td>BE.5.R.30</td>\n",
       "      <td>BE.5.R.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>4240</td>\n",
       "      <td>17</td>\n",
       "      <td>15600</td>\n",
       "      <td>4257</td>\n",
       "      <td>15618</td>\n",
       "      <td>14.377_080_00</td>\n",
       "      <td>14.377_081_08</td>\n",
       "      <td>BE.6.Q.21</td>\n",
       "      <td>BE.6.Q.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1536</td>\n",
       "      <td>16</td>\n",
       "      <td>6440</td>\n",
       "      <td>1552</td>\n",
       "      <td>6456</td>\n",
       "      <td>14.378_425_01</td>\n",
       "      <td>14.378_426_06</td>\n",
       "      <td>BE.12.Q.27</td>\n",
       "      <td>BE.12.Q.41.(Adl)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2508</td>\n",
       "      <td>16</td>\n",
       "      <td>10085</td>\n",
       "      <td>2524</td>\n",
       "      <td>10139</td>\n",
       "      <td>14.378_109_02</td>\n",
       "      <td>14.378_111_05</td>\n",
       "      <td>BE.3.S.10-12.(Vol.1)</td>\n",
       "      <td>BE.3.S.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>701</td>\n",
       "      <td>15</td>\n",
       "      <td>3500</td>\n",
       "      <td>716</td>\n",
       "      <td>3515</td>\n",
       "      <td>14.377_158_06</td>\n",
       "      <td>14.377_161_06</td>\n",
       "      <td>BE.10.X.39</td>\n",
       "      <td>BE.10.X.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>1942</td>\n",
       "      <td>15</td>\n",
       "      <td>8153</td>\n",
       "      <td>1957</td>\n",
       "      <td>8177</td>\n",
       "      <td>14.377_433_09</td>\n",
       "      <td>14.377_435_04</td>\n",
       "      <td>BE.2.R.27-32.(Vol.1)</td>\n",
       "      <td>BE.2.R.48-53.(Vol.1)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>3094</td>\n",
       "      <td>15</td>\n",
       "      <td>12064</td>\n",
       "      <td>3109</td>\n",
       "      <td>12084</td>\n",
       "      <td>14.376_385_02</td>\n",
       "      <td>14.376_387_05</td>\n",
       "      <td>BE.4.S.28</td>\n",
       "      <td>BE.4.S.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>339</td>\n",
       "      <td>14</td>\n",
       "      <td>1455</td>\n",
       "      <td>353</td>\n",
       "      <td>1469</td>\n",
       "      <td>14.376_110_02</td>\n",
       "      <td>14.376_107_02</td>\n",
       "      <td>BE.1.X.35</td>\n",
       "      <td>BE.1.X.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>3226</td>\n",
       "      <td>14</td>\n",
       "      <td>12534</td>\n",
       "      <td>3240</td>\n",
       "      <td>12650</td>\n",
       "      <td>14.377_164_00</td>\n",
       "      <td>14.377_166_03</td>\n",
       "      <td>BE.4.Y.1.(Vol.1)</td>\n",
       "      <td>BE.4.Z.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>3906</td>\n",
       "      <td>14</td>\n",
       "      <td>14472</td>\n",
       "      <td>3920</td>\n",
       "      <td>14490</td>\n",
       "      <td>14.377_170_02</td>\n",
       "      <td>14.377_171_04</td>\n",
       "      <td>BE.5.Y.10</td>\n",
       "      <td>BE.5.Y.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>4900</td>\n",
       "      <td>14</td>\n",
       "      <td>19260</td>\n",
       "      <td>4914</td>\n",
       "      <td>19275</td>\n",
       "      <td>14.377_279_01</td>\n",
       "      <td>14.377_283_01</td>\n",
       "      <td>BE.8.N.15.(Vol.1)</td>\n",
       "      <td>BE.8.N.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>5360</td>\n",
       "      <td>14</td>\n",
       "      <td>20942</td>\n",
       "      <td>5374</td>\n",
       "      <td>20973</td>\n",
       "      <td>14.377_349_02</td>\n",
       "      <td>14.377_352_04</td>\n",
       "      <td>BE.9.K.10.11.(Vol.1)</td>\n",
       "      <td>BE.9.K.36.37.(Vol.1)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>3188</td>\n",
       "      <td>13</td>\n",
       "      <td>12443</td>\n",
       "      <td>3201</td>\n",
       "      <td>12466</td>\n",
       "      <td>14.377_120_05</td>\n",
       "      <td>14.377_122_03</td>\n",
       "      <td>BE.4.X.17</td>\n",
       "      <td>BE.4.X.29.(Vol.1)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>1108</td>\n",
       "      <td>12</td>\n",
       "      <td>4822</td>\n",
       "      <td>1120</td>\n",
       "      <td>4835</td>\n",
       "      <td>14.378_480_06</td>\n",
       "      <td>14.378_481_06</td>\n",
       "      <td>BE.11.Q.10</td>\n",
       "      <td>BE.11.Q.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>2170</td>\n",
       "      <td>12</td>\n",
       "      <td>8764</td>\n",
       "      <td>2182</td>\n",
       "      <td>8777</td>\n",
       "      <td>14.376_234_04</td>\n",
       "      <td>14.376_238_01</td>\n",
       "      <td>BE.2.X.52</td>\n",
       "      <td>BE.2.X.65-68.(Vol.1)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    location  length  first_BE_location  last_location  last_BE_location   \n",
       "0        931      24               4261            955              4285  \\\n",
       "3       4116      22              15231           4138             15275   \n",
       "8        907      19               4237            926              4256   \n",
       "13      3524      18              13400           3542             13418   \n",
       "17      2599      17              10388           2616             10405   \n",
       "19      3674      17              13828           3691             13846   \n",
       "21      4240      17              15600           4257             15618   \n",
       "24      1536      16               6440           1552              6456   \n",
       "25      2508      16              10085           2524             10139   \n",
       "31       701      15               3500            716              3515   \n",
       "35      1942      15               8153           1957              8177   \n",
       "38      3094      15              12064           3109             12084   \n",
       "43       339      14               1455            353              1469   \n",
       "52      3226      14              12534           3240             12650   \n",
       "55      3906      14              14472           3920             14490   \n",
       "58      4900      14              19260           4914             19275   \n",
       "59      5360      14              20942           5374             20973   \n",
       "69      3188      13              12443           3201             12466   \n",
       "82      1108      12               4822           1120              4835   \n",
       "85      2170      12               8764           2182              8777   \n",
       "\n",
       "      first_hw_id     last_hw_id        erste Signatur       letzte Signatur  \n",
       "0   14.377_079_01  14.377_079_23            BE.11.L.31        BE.11.L.35.(4)  \n",
       "3   14.378_211_03  14.378_215_01   BE.6.M.1-16.(Vol.1)             BE.6.M.39  \n",
       "8   14.377_078_01  14.377_078_19            BE.11.L.18        BE.11.L.22.(3)  \n",
       "13  14.376_325_03  14.376_328_01             BE.5.N.30             BE.5.N.39  \n",
       "17  14.376_259_05  14.376_262_01             BE.3.W.14             BE.3.W.29  \n",
       "19  14.376_435_04  14.376_438_01             BE.5.R.30             BE.5.R.48  \n",
       "21  14.377_080_00  14.377_081_08             BE.6.Q.21             BE.6.Q.29  \n",
       "24  14.378_425_01  14.378_426_06            BE.12.Q.27      BE.12.Q.41.(Adl)  \n",
       "25  14.378_109_02  14.378_111_05  BE.3.S.10-12.(Vol.1)             BE.3.S.44  \n",
       "31  14.377_158_06  14.377_161_06            BE.10.X.39            BE.10.X.54  \n",
       "35  14.377_433_09  14.377_435_04  BE.2.R.27-32.(Vol.1)  BE.2.R.48-53.(Vol.1)  \n",
       "38  14.376_385_02  14.376_387_05             BE.4.S.28             BE.4.S.49  \n",
       "43  14.376_110_02  14.376_107_02             BE.1.X.35             BE.1.X.48  \n",
       "52  14.377_164_00  14.377_166_03      BE.4.Y.1.(Vol.1)             BE.4.Z.37  \n",
       "55  14.377_170_02  14.377_171_04             BE.5.Y.10             BE.5.Y.29  \n",
       "58  14.377_279_01  14.377_283_01     BE.8.N.15.(Vol.1)             BE.8.N.25  \n",
       "59  14.377_349_02  14.377_352_04  BE.9.K.10.11.(Vol.1)  BE.9.K.36.37.(Vol.1)  \n",
       "69  14.377_120_05  14.377_122_03             BE.4.X.17     BE.4.X.29.(Vol.1)  \n",
       "82  14.378_480_06  14.378_481_06            BE.11.Q.10            BE.11.Q.19  \n",
       "85  14.376_234_04  14.376_238_01             BE.2.X.52  BE.2.X.65-68.(Vol.1)  "
      ]
     },
     "execution_count": 1089,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "seq[:20]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d5632b9-5446-44ef-9590-0592641018c0",
   "metadata": {},
   "source": [
    "# Nacharbeiten bei duplizierten Titeln"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1196,
   "id": "dd3fd2d0-1558-4505-afe8-7af70c49cb0e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "dup_candidates = comp_BE_no_dup[comp_BE_no_dup['dup_title'] & (comp_BE_no_dup['hs. Katalog'] == 1) & (comp_BE_no_dup['copy_from'] == -1)]\n",
    "low_sim = []\n",
    "\n",
    "for i, row in dup_candidates.iterrows():\n",
    "    title = row['Titel']\n",
    "    sig = row['Signatur']\n",
    "    dup_group = comp_BE_no_dup[(comp_BE_no_dup['Titel'] == title) & (comp_BE_no_dup['copy_from'] != -1)]\n",
    "    for j, dup in dup_group.iterrows():\n",
    "        sim_score = fuzz.ratio(sig, dup['Signatur'])\n",
    "        if 80 < sim_score < 90: # Signatur ähnlich\n",
    "            dup['sim_score'] = sim_score\n",
    "            dup['other_sig'] = sig\n",
    "            low_sim.append(dup)\n",
    "\n",
    "low_sim_df = pd.DataFrame(low_sim)\n",
    "\n",
    "dod_id = {\n",
    "    '14.376': 51202, \n",
    "    '14.377': 51184,\n",
    "    '14.378': 51219\n",
    "}\n",
    "\n",
    "lettres_edifiantes = comp_BE_no_dup[comp_BE_no_dup['Titel'] == 'Lettres Edifiantes Et Curieuses, Ecrites Des Missions Etrangeres, par quelques Missionaires de la Compagnie de Jesus']\n",
    "l_m = entry_df.loc[4652]\n",
    "\n",
    "for i, row in lettres_edifiantes.iterrows():\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalog'] = 1\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalog Konfidenz'] = 'sicher'\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogband'] = l_m['volume']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogseite Digitalisat'] = str(l_m['page number'])\n",
    "    comp_BE_no_dup.at[i, 'Wissensklasse'] = l_m['category']\n",
    "    comp_BE_no_dup.at[i, 'Wissensunterklasse'] = l_m['subcategory']\n",
    "    comp_BE_no_dup.at[i, 'Formatangabe'] = l_m['format']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogseite Handschrift'] = l_m['handwritten page number']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogeintrag ID'] = l_m['entry_ID']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalogeintrag'] = l_m['entry']\n",
    "    comp_BE_no_dup.at[i, 'hs. Katalog Image URL'] = f\"https://iiif.onb.ac.at/images/DOD/{dod_id[str(l_m['volume'])]}/{l_m['page number']:08}.jp2/full/full/0/native.jpg\"\n",
    "\n",
    "delete_hw_match_for = [14220, 13616, 15587]\n",
    "take_from_entry_df = [3411, '-', 3247]\n",
    "\n",
    "for i, num in enumerate(delete_hw_match_for):\n",
    "    if take_from_entry_df[i] != '-':\n",
    "        entry = entry_df.loc[take_from_entry_df[i]]\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalog'] = 1\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalog Konfidenz'] = 'sicher'\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogband'] = entry['volume']\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogseite Digitalisat'] = str(entry['page number'])\n",
    "        comp_BE_no_dup.at[num, 'Wissensklasse'] = entry['category']\n",
    "        comp_BE_no_dup.at[num, 'Wissensunterklasse'] = entry['subcategory']\n",
    "        comp_BE_no_dup.at[num, 'Formatangabe'] = entry['format']\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogseite Handschrift'] = entry['handwritten page number']\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogeintrag ID'] = entry['entry_ID']\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogeintrag'] = entry['entry']\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalog Image URL'] = f\"https://iiif.onb.ac.at/images/DOD/{dod_id[str(entry['volume'])]}/{entry['page number']:08}.jp2/full/full/0/native.jpg\"\n",
    "    else:\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalog'] = 0\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalog Konfidenz'] = ''\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogband'] = ''\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogseite Digitalisat'] = ''\n",
    "        comp_BE_no_dup.at[num, 'Wissensklasse'] = ''\n",
    "        comp_BE_no_dup.at[num, 'Wissensunterklasse'] = ''\n",
    "        comp_BE_no_dup.at[num, 'Formatangabe'] = ''\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogseite Handschrift'] = ''\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogeintrag ID'] = ''\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalogeintrag'] = ''\n",
    "        comp_BE_no_dup.at[num, 'hs. Katalog Image URL'] = ''\n",
    "        comp_BE_no_dup.at[num, 'copy_from'] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd067c70-ba6d-4d82-9489-3e9b332dad3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "comp_BE_no_dup.to_excel('../Daten/Vorhersagen/WIP_final_BE_3.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6a3910b6-8488-4af0-bab6-a04af623a786",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "tmp = pd.read_excel('../Daten/Vorhersagen/WIP_final_BE_3.xlsx', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1261,
   "id": "12fcd3ad-222e-4afe-baea-7be69b3ae5cc",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Signatur</th>\n",
       "      <th>Barcode</th>\n",
       "      <th>Titel</th>\n",
       "      <th>Autor</th>\n",
       "      <th>Mitwirkender</th>\n",
       "      <th>Anfang Veröffentlichungsdatum</th>\n",
       "      <th>Ende Veröffentlichungsdatum</th>\n",
       "      <th>Veröffentlichungsdatum</th>\n",
       "      <th>Veröffentlichungsort</th>\n",
       "      <th>Veröffentlichungsort (normiert)</th>\n",
       "      <th>...</th>\n",
       "      <th>hs. Katalogseite Digitalisat</th>\n",
       "      <th>Wissensklasse</th>\n",
       "      <th>Wissensunterklasse</th>\n",
       "      <th>Formatangabe</th>\n",
       "      <th>hs. Katalogseite Handschrift</th>\n",
       "      <th>hs. Katalogeintrag ID</th>\n",
       "      <th>hs. Katalogeintrag</th>\n",
       "      <th>hs. Katalog Image URL</th>\n",
       "      <th>dup_title</th>\n",
       "      <th>copy_from</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23376</th>\n",
       "      <td>*28.A.79.(Vol.1)</td>\n",
       "      <td>Z222907107</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23383</th>\n",
       "      <td>*28.A.79.(Vol.10)</td>\n",
       "      <td>Z222908100</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23384</th>\n",
       "      <td>*28.A.79.(Vol.12)</td>\n",
       "      <td>Z222908306</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23385</th>\n",
       "      <td>*28.A.79.(Vol.13)</td>\n",
       "      <td>Z222908409</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23386</th>\n",
       "      <td>*28.A.79.(Vol.14)</td>\n",
       "      <td>Z222908501</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22638</th>\n",
       "      <td>Ink 9.D.5</td>\n",
       "      <td>+Z35095803</td>\n",
       "      <td>Thesaurus Cornu copiae et Horti Adonidis &lt;griech.&gt; Mit lat. und griech. Brief an Guarinus Favorinus von Angelus Politianus bzw. von Scipione Fortiguerra. Mit griech. Gedichten von Angelus Politianus, Aristobulos Apostolides, Scipione Fortiguerra und Aldus Manutius. Mit lat. Brief an die Gelehrten hrsg. von Aldus Manutius unter Mitarbeit von Urbanus Bolzanius</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Manuzio, Aldo Pio; Bolzanio, Urbano 1443-1524; Manuzio, Aldo Pio 1450-1515</td>\n",
       "      <td>1496.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Aug. 1496; [1496.08]</td>\n",
       "      <td>Venedig</td>\n",
       "      <td>Venedig</td>\n",
       "      <td>...</td>\n",
       "      <td>423</td>\n",
       "      <td>Grammatica</td>\n",
       "      <td>Tractatus Grammatici generalis cum Lexicographis</td>\n",
       "      <td>Folio</td>\n",
       "      <td>375</td>\n",
       "      <td>14.376_423_03</td>\n",
       "      <td>755 Thesaurus Cornucopiæ ac Horti Adonidis græcè. Venetiis 1496. Aldus. n. 2179</td>\n",
       "      <td>https://iiif.onb.ac.at/images/DOD/51202/00000423.jp2/full/full/0/native.jpg</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22639</th>\n",
       "      <td>Ink 9.F.22</td>\n",
       "      <td>+Z96101306</td>\n",
       "      <td>Comoediae ; Francesco Petrarca: Vita Terentii</td>\n",
       "      <td>Terentius Afer, Publius v195-v159</td>\n",
       "      <td>Zarotto, Antonio</td>\n",
       "      <td>1476.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>23. Feb. 1476; [1476.02.23]</td>\n",
       "      <td>Mailand</td>\n",
       "      <td>Mailand</td>\n",
       "      <td>...</td>\n",
       "      <td>31</td>\n",
       "      <td>Poëtica</td>\n",
       "      <td>Poëtæ Latini Antiqui</td>\n",
       "      <td>Folio</td>\n",
       "      <td>439</td>\n",
       "      <td>14.377_031_11</td>\n",
       "      <td>857....... Ejusdem Comoediæ. Mediolani. 1476. An. Za. n. 2336.</td>\n",
       "      <td>https://iiif.onb.ac.at/images/DOD/51184/00000031.jp2/full/full/0/native.jpg</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22650</th>\n",
       "      <td>SA.71.E.58</td>\n",
       "      <td>Z252861302</td>\n",
       "      <td>Dialogue sur la musique des anciens</td>\n",
       "      <td>Chateauneuf, Francois abbe de</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1725.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1725</td>\n",
       "      <td>Paris</td>\n",
       "      <td>Paris</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22651</th>\n",
       "      <td>SA.71.F.74</td>\n",
       "      <td>Z252867808</td>\n",
       "      <td>Friderici Adolfi Lampe De Cymbalis Veterum Libri Tres</td>\n",
       "      <td>Ember, Paul</td>\n",
       "      <td>Hase, Cornelius &lt;&lt;von&gt;&gt;; Röell, Herman Alexander</td>\n",
       "      <td>1703.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1703</td>\n",
       "      <td>Trajecti Ad Rhenum</td>\n",
       "      <td>Utrecht</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23439</th>\n",
       "      <td>SA.73.B.48</td>\n",
       "      <td>Z25920770X</td>\n",
       "      <td>Claudii Ptolomaei harmonicorum libri tres. Ex Codd. Mss. Undecim, nunc primum graece editus. Johannes Wallis ... recensuit, ed. (etc.)</td>\n",
       "      <td>Ptolemaeus, Claudius</td>\n",
       "      <td>Wallis, Johannes</td>\n",
       "      <td>1682.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1682</td>\n",
       "      <td>Oxford</td>\n",
       "      <td>Oxford</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9591 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Signatur     Barcode   \n",
       "23376   *28.A.79.(Vol.1)  Z222907107  \\\n",
       "23383  *28.A.79.(Vol.10)  Z222908100   \n",
       "23384  *28.A.79.(Vol.12)  Z222908306   \n",
       "23385  *28.A.79.(Vol.13)  Z222908409   \n",
       "23386  *28.A.79.(Vol.14)  Z222908501   \n",
       "...                  ...         ...   \n",
       "22638          Ink 9.D.5  +Z35095803   \n",
       "22639         Ink 9.F.22  +Z96101306   \n",
       "22650         SA.71.E.58  Z252861302   \n",
       "22651         SA.71.F.74  Z252867808   \n",
       "23439         SA.73.B.48  Z25920770X   \n",
       "\n",
       "                                                                                                                                                                                                                                                                                                                                                                          Titel   \n",
       "23376                                                                                                                                                                                                                                                                                                                                         Histoire des ouvrages des scavans  \\\n",
       "23383                                                                                                                                                                                                                                                                                                                                         Histoire des ouvrages des scavans   \n",
       "23384                                                                                                                                                                                                                                                                                                                                         Histoire des ouvrages des scavans   \n",
       "23385                                                                                                                                                                                                                                                                                                                                         Histoire des ouvrages des scavans   \n",
       "23386                                                                                                                                                                                                                                                                                                                                         Histoire des ouvrages des scavans   \n",
       "...                                                                                                                                                                                                                                                                                                                                                                         ...   \n",
       "22638  Thesaurus Cornu copiae et Horti Adonidis <griech.> Mit lat. und griech. Brief an Guarinus Favorinus von Angelus Politianus bzw. von Scipione Fortiguerra. Mit griech. Gedichten von Angelus Politianus, Aristobulos Apostolides, Scipione Fortiguerra und Aldus Manutius. Mit lat. Brief an die Gelehrten hrsg. von Aldus Manutius unter Mitarbeit von Urbanus Bolzanius   \n",
       "22639                                                                                                                                                                                                                                                                                                                             Comoediae ; Francesco Petrarca: Vita Terentii   \n",
       "22650                                                                                                                                                                                                                                                                                                                                       Dialogue sur la musique des anciens   \n",
       "22651                                                                                                                                                                                                                                                                                                                     Friderici Adolfi Lampe De Cymbalis Veterum Libri Tres   \n",
       "23439                                                                                                                                                                                                                                    Claudii Ptolomaei harmonicorum libri tres. Ex Codd. Mss. Undecim, nunc primum graece editus. Johannes Wallis ... recensuit, ed. (etc.)   \n",
       "\n",
       "                                   Autor   \n",
       "23376          Basnage de Beauval, Henri  \\\n",
       "23383          Basnage de Beauval, Henri   \n",
       "23384          Basnage de Beauval, Henri   \n",
       "23385          Basnage de Beauval, Henri   \n",
       "23386          Basnage de Beauval, Henri   \n",
       "...                                  ...   \n",
       "22638                                NaN   \n",
       "22639  Terentius Afer, Publius v195-v159   \n",
       "22650      Chateauneuf, Francois abbe de   \n",
       "22651                        Ember, Paul   \n",
       "23439               Ptolemaeus, Claudius   \n",
       "\n",
       "                                                                     Mitwirkender   \n",
       "23376                                                                         NaN  \\\n",
       "23383                                                                         NaN   \n",
       "23384                                                                         NaN   \n",
       "23385                                                                         NaN   \n",
       "23386                                                                         NaN   \n",
       "...                                                                           ...   \n",
       "22638  Manuzio, Aldo Pio; Bolzanio, Urbano 1443-1524; Manuzio, Aldo Pio 1450-1515   \n",
       "22639                                                            Zarotto, Antonio   \n",
       "22650                                                                         NaN   \n",
       "22651                            Hase, Cornelius <<von>>; Röell, Herman Alexander   \n",
       "23439                                                            Wallis, Johannes   \n",
       "\n",
       "       Anfang Veröffentlichungsdatum  Ende Veröffentlichungsdatum   \n",
       "23376                         1687.0                       1709.0  \\\n",
       "23383                         1687.0                       1709.0   \n",
       "23384                         1687.0                       1709.0   \n",
       "23385                         1687.0                       1709.0   \n",
       "23386                         1687.0                       1709.0   \n",
       "...                              ...                          ...   \n",
       "22638                         1496.0                          NaN   \n",
       "22639                         1476.0                          NaN   \n",
       "22650                         1725.0                          NaN   \n",
       "22651                         1703.0                          NaN   \n",
       "23439                         1682.0                          NaN   \n",
       "\n",
       "            Veröffentlichungsdatum Veröffentlichungsort   \n",
       "23376                    1687-1709            Rotterdam  \\\n",
       "23383                    1687-1709            Rotterdam   \n",
       "23384                    1687-1709            Rotterdam   \n",
       "23385                    1687-1709            Rotterdam   \n",
       "23386                    1687-1709            Rotterdam   \n",
       "...                            ...                  ...   \n",
       "22638         Aug. 1496; [1496.08]              Venedig   \n",
       "22639  23. Feb. 1476; [1476.02.23]              Mailand   \n",
       "22650                         1725                Paris   \n",
       "22651                         1703   Trajecti Ad Rhenum   \n",
       "23439                         1682               Oxford   \n",
       "\n",
       "      Veröffentlichungsort (normiert)  ... hs. Katalogseite Digitalisat   \n",
       "23376                       Rotterdam  ...                          NaN  \\\n",
       "23383                       Rotterdam  ...                          NaN   \n",
       "23384                       Rotterdam  ...                          NaN   \n",
       "23385                       Rotterdam  ...                          NaN   \n",
       "23386                       Rotterdam  ...                          NaN   \n",
       "...                               ...  ...                          ...   \n",
       "22638                         Venedig  ...                          423   \n",
       "22639                         Mailand  ...                           31   \n",
       "22650                           Paris  ...                          NaN   \n",
       "22651                         Utrecht  ...                          NaN   \n",
       "23439                          Oxford  ...                          NaN   \n",
       "\n",
       "      Wissensklasse                                Wissensunterklasse   \n",
       "23376           NaN                                               NaN  \\\n",
       "23383           NaN                                               NaN   \n",
       "23384           NaN                                               NaN   \n",
       "23385           NaN                                               NaN   \n",
       "23386           NaN                                               NaN   \n",
       "...             ...                                               ...   \n",
       "22638    Grammatica  Tractatus Grammatici generalis cum Lexicographis   \n",
       "22639       Poëtica                              Poëtæ Latini Antiqui   \n",
       "22650           NaN                                               NaN   \n",
       "22651           NaN                                               NaN   \n",
       "23439           NaN                                               NaN   \n",
       "\n",
       "       Formatangabe  hs. Katalogseite Handschrift  hs. Katalogeintrag ID   \n",
       "23376           NaN                           NaN                    NaN  \\\n",
       "23383           NaN                           NaN                    NaN   \n",
       "23384           NaN                           NaN                    NaN   \n",
       "23385           NaN                           NaN                    NaN   \n",
       "23386           NaN                           NaN                    NaN   \n",
       "...             ...                           ...                    ...   \n",
       "22638         Folio                           375          14.376_423_03   \n",
       "22639         Folio                           439          14.377_031_11   \n",
       "22650           NaN                           NaN                    NaN   \n",
       "22651           NaN                           NaN                    NaN   \n",
       "23439           NaN                           NaN                    NaN   \n",
       "\n",
       "                                                                    hs. Katalogeintrag   \n",
       "23376                                                                              NaN  \\\n",
       "23383                                                                              NaN   \n",
       "23384                                                                              NaN   \n",
       "23385                                                                              NaN   \n",
       "23386                                                                              NaN   \n",
       "...                                                                                ...   \n",
       "22638  755 Thesaurus Cornucopiæ ac Horti Adonidis græcè. Venetiis 1496. Aldus. n. 2179   \n",
       "22639                   857....... Ejusdem Comoediæ. Mediolani. 1476. An. Za. n. 2336.   \n",
       "22650                                                                              NaN   \n",
       "22651                                                                              NaN   \n",
       "23439                                                                              NaN   \n",
       "\n",
       "                                                             hs. Katalog Image URL   \n",
       "23376                                                                          NaN  \\\n",
       "23383                                                                          NaN   \n",
       "23384                                                                          NaN   \n",
       "23385                                                                          NaN   \n",
       "23386                                                                          NaN   \n",
       "...                                                                            ...   \n",
       "22638  https://iiif.onb.ac.at/images/DOD/51202/00000423.jp2/full/full/0/native.jpg   \n",
       "22639  https://iiif.onb.ac.at/images/DOD/51184/00000031.jp2/full/full/0/native.jpg   \n",
       "22650                                                                          NaN   \n",
       "22651                                                                          NaN   \n",
       "23439                                                                          NaN   \n",
       "\n",
       "       dup_title  copy_from  \n",
       "23376       True         -1  \n",
       "23383       True         -1  \n",
       "23384       True         -1  \n",
       "23385       True         -1  \n",
       "23386       True         -1  \n",
       "...          ...        ...  \n",
       "22638      False         -1  \n",
       "22639      False         -1  \n",
       "22650      False         -1  \n",
       "22651      False         -1  \n",
       "23439      False         -1  \n",
       "\n",
       "[9591 rows x 35 columns]"
      ]
     },
     "execution_count": 1261,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comp_BE_no_dup[comp_BE_no_dup['Wappenklassifizierung'].isin(['A', 'B', 'C']) | (comp_BE_no_dup['hs. Katalog'] == 1)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f58126a0-fd9e-40d7-a224-60522655fd2c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Signatur</th>\n",
       "      <th>Barcode</th>\n",
       "      <th>Titel</th>\n",
       "      <th>Autor</th>\n",
       "      <th>Mitwirkender</th>\n",
       "      <th>Anfang Veröffentlichungsdatum</th>\n",
       "      <th>Ende Veröffentlichungsdatum</th>\n",
       "      <th>Veröffentlichungsdatum</th>\n",
       "      <th>Veröffentlichungsort</th>\n",
       "      <th>Veröffentlichungsort (normiert)</th>\n",
       "      <th>...</th>\n",
       "      <th>hs. Katalogseite Digitalisat</th>\n",
       "      <th>Wissensklasse</th>\n",
       "      <th>Wissensunterklasse</th>\n",
       "      <th>Formatangabe</th>\n",
       "      <th>hs. Katalogseite Handschrift</th>\n",
       "      <th>hs. Katalogeintrag ID</th>\n",
       "      <th>hs. Katalogeintrag</th>\n",
       "      <th>hs. Katalog Image URL</th>\n",
       "      <th>dup_title</th>\n",
       "      <th>copy_from</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23633</th>\n",
       "      <td>Ink 3.E.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Fasciculus temporum</td>\n",
       "      <td>Rolewinck, Werner</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1474.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[not before 1474]</td>\n",
       "      <td>[Cologne]</td>\n",
       "      <td>Köln</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Signatur Barcode                Titel              Autor Mitwirkender   \n",
       "23633  Ink 3.E.3     NaN  Fasciculus temporum  Rolewinck, Werner          NaN  \\\n",
       "\n",
       "       Anfang Veröffentlichungsdatum  Ende Veröffentlichungsdatum   \n",
       "23633                         1474.0                          NaN  \\\n",
       "\n",
       "      Veröffentlichungsdatum Veröffentlichungsort   \n",
       "23633      [not before 1474]            [Cologne]  \\\n",
       "\n",
       "      Veröffentlichungsort (normiert)  ... hs. Katalogseite Digitalisat   \n",
       "23633                            Köln  ...                          NaN  \\\n",
       "\n",
       "      Wissensklasse Wissensunterklasse  Formatangabe   \n",
       "23633           NaN                NaN           NaN  \\\n",
       "\n",
       "       hs. Katalogseite Handschrift  hs. Katalogeintrag ID   \n",
       "23633                           NaN                    NaN  \\\n",
       "\n",
       "       hs. Katalogeintrag hs. Katalog Image URL  dup_title  copy_from  \n",
       "23633                 NaN                   NaN       True         -1  \n",
       "\n",
       "[1 rows x 35 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comp_BE_no_dup[comp_BE_no_dup['Signatur'].str.contains('Ink 3.E.3')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e260aa23-0d34-4290-8db1-9aec69b8f591",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Signatur</th>\n",
       "      <th>Barcode</th>\n",
       "      <th>Titel</th>\n",
       "      <th>Autor</th>\n",
       "      <th>Mitwirkender</th>\n",
       "      <th>Anfang Veröffentlichungsdatum</th>\n",
       "      <th>Ende Veröffentlichungsdatum</th>\n",
       "      <th>Veröffentlichungsdatum</th>\n",
       "      <th>Veröffentlichungsort</th>\n",
       "      <th>Veröffentlichungsort (normiert)</th>\n",
       "      <th>...</th>\n",
       "      <th>hs. Katalogseite Digitalisat</th>\n",
       "      <th>Wissensklasse</th>\n",
       "      <th>Wissensunterklasse</th>\n",
       "      <th>Formatangabe</th>\n",
       "      <th>hs. Katalogseite Handschrift</th>\n",
       "      <th>hs. Katalogeintrag ID</th>\n",
       "      <th>hs. Katalogeintrag</th>\n",
       "      <th>hs. Katalog Image URL</th>\n",
       "      <th>dup_title</th>\n",
       "      <th>copy_from</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23376</th>\n",
       "      <td>*28.A.79.(Vol.1)</td>\n",
       "      <td>Z222907107</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23383</th>\n",
       "      <td>*28.A.79.(Vol.10)</td>\n",
       "      <td>Z222908100</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23384</th>\n",
       "      <td>*28.A.79.(Vol.12)</td>\n",
       "      <td>Z222908306</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23385</th>\n",
       "      <td>*28.A.79.(Vol.13)</td>\n",
       "      <td>Z222908409</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23386</th>\n",
       "      <td>*28.A.79.(Vol.14)</td>\n",
       "      <td>Z222908501</td>\n",
       "      <td>Histoire des ouvrages des scavans</td>\n",
       "      <td>Basnage de Beauval, Henri</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1687.0</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>1687-1709</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23636</th>\n",
       "      <td>Ink 9.F.4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Opera</td>\n",
       "      <td>Sallustius Crispus, Gaius</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1481.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>23 Dec. 1481</td>\n",
       "      <td>Venice</td>\n",
       "      <td>Venedig</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22640</th>\n",
       "      <td>Ink 9.F.5</td>\n",
       "      <td>1460328-10</td>\n",
       "      <td>Biblia ; Interpretationes Hebraicorum nominum</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Wild, Leonhard</td>\n",
       "      <td>1481.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1481</td>\n",
       "      <td>Venedig</td>\n",
       "      <td>Venedig</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22650</th>\n",
       "      <td>SA.71.E.58</td>\n",
       "      <td>Z252861302</td>\n",
       "      <td>Dialogue sur la musique des anciens</td>\n",
       "      <td>Chateauneuf, Francois abbe de</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1725.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1725</td>\n",
       "      <td>Paris</td>\n",
       "      <td>Paris</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22651</th>\n",
       "      <td>SA.71.F.74</td>\n",
       "      <td>Z252867808</td>\n",
       "      <td>Friderici Adolfi Lampe De Cymbalis Veterum Libri Tres</td>\n",
       "      <td>Ember, Paul</td>\n",
       "      <td>Hase, Cornelius &lt;&lt;von&gt;&gt;; Röell, Herman Alexander</td>\n",
       "      <td>1703.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1703</td>\n",
       "      <td>Trajecti Ad Rhenum</td>\n",
       "      <td>Utrecht</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23439</th>\n",
       "      <td>SA.73.B.48</td>\n",
       "      <td>Z25920770X</td>\n",
       "      <td>Claudii Ptolomaei harmonicorum libri tres. Ex Codd. Mss. Undecim, nunc primum graece editus. Johannes Wallis ... recensuit, ed. (etc.)</td>\n",
       "      <td>Ptolemaeus, Claudius</td>\n",
       "      <td>Wallis, Johannes</td>\n",
       "      <td>1682.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1682</td>\n",
       "      <td>Oxford</td>\n",
       "      <td>Oxford</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>22861 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Signatur     Barcode   \n",
       "23376   *28.A.79.(Vol.1)  Z222907107  \\\n",
       "23383  *28.A.79.(Vol.10)  Z222908100   \n",
       "23384  *28.A.79.(Vol.12)  Z222908306   \n",
       "23385  *28.A.79.(Vol.13)  Z222908409   \n",
       "23386  *28.A.79.(Vol.14)  Z222908501   \n",
       "...                  ...         ...   \n",
       "23636          Ink 9.F.4         NaN   \n",
       "22640          Ink 9.F.5  1460328-10   \n",
       "22650         SA.71.E.58  Z252861302   \n",
       "22651         SA.71.F.74  Z252867808   \n",
       "23439         SA.73.B.48  Z25920770X   \n",
       "\n",
       "                                                                                                                                        Titel   \n",
       "23376                                                                                                       Histoire des ouvrages des scavans  \\\n",
       "23383                                                                                                       Histoire des ouvrages des scavans   \n",
       "23384                                                                                                       Histoire des ouvrages des scavans   \n",
       "23385                                                                                                       Histoire des ouvrages des scavans   \n",
       "23386                                                                                                       Histoire des ouvrages des scavans   \n",
       "...                                                                                                                                       ...   \n",
       "23636                                                                                                                                   Opera   \n",
       "22640                                                                                           Biblia ; Interpretationes Hebraicorum nominum   \n",
       "22650                                                                                                     Dialogue sur la musique des anciens   \n",
       "22651                                                                                   Friderici Adolfi Lampe De Cymbalis Veterum Libri Tres   \n",
       "23439  Claudii Ptolomaei harmonicorum libri tres. Ex Codd. Mss. Undecim, nunc primum graece editus. Johannes Wallis ... recensuit, ed. (etc.)   \n",
       "\n",
       "                               Autor   \n",
       "23376      Basnage de Beauval, Henri  \\\n",
       "23383      Basnage de Beauval, Henri   \n",
       "23384      Basnage de Beauval, Henri   \n",
       "23385      Basnage de Beauval, Henri   \n",
       "23386      Basnage de Beauval, Henri   \n",
       "...                              ...   \n",
       "23636      Sallustius Crispus, Gaius   \n",
       "22640                            NaN   \n",
       "22650  Chateauneuf, Francois abbe de   \n",
       "22651                    Ember, Paul   \n",
       "23439           Ptolemaeus, Claudius   \n",
       "\n",
       "                                           Mitwirkender   \n",
       "23376                                               NaN  \\\n",
       "23383                                               NaN   \n",
       "23384                                               NaN   \n",
       "23385                                               NaN   \n",
       "23386                                               NaN   \n",
       "...                                                 ...   \n",
       "23636                                               NaN   \n",
       "22640                                    Wild, Leonhard   \n",
       "22650                                               NaN   \n",
       "22651  Hase, Cornelius <<von>>; Röell, Herman Alexander   \n",
       "23439                                  Wallis, Johannes   \n",
       "\n",
       "       Anfang Veröffentlichungsdatum  Ende Veröffentlichungsdatum   \n",
       "23376                         1687.0                       1709.0  \\\n",
       "23383                         1687.0                       1709.0   \n",
       "23384                         1687.0                       1709.0   \n",
       "23385                         1687.0                       1709.0   \n",
       "23386                         1687.0                       1709.0   \n",
       "...                              ...                          ...   \n",
       "23636                         1481.0                          NaN   \n",
       "22640                         1481.0                          NaN   \n",
       "22650                         1725.0                          NaN   \n",
       "22651                         1703.0                          NaN   \n",
       "23439                         1682.0                          NaN   \n",
       "\n",
       "      Veröffentlichungsdatum Veröffentlichungsort   \n",
       "23376              1687-1709            Rotterdam  \\\n",
       "23383              1687-1709            Rotterdam   \n",
       "23384              1687-1709            Rotterdam   \n",
       "23385              1687-1709            Rotterdam   \n",
       "23386              1687-1709            Rotterdam   \n",
       "...                      ...                  ...   \n",
       "23636           23 Dec. 1481               Venice   \n",
       "22640                   1481              Venedig   \n",
       "22650                   1725                Paris   \n",
       "22651                   1703   Trajecti Ad Rhenum   \n",
       "23439                   1682               Oxford   \n",
       "\n",
       "      Veröffentlichungsort (normiert)  ... hs. Katalogseite Digitalisat   \n",
       "23376                       Rotterdam  ...                          NaN  \\\n",
       "23383                       Rotterdam  ...                          NaN   \n",
       "23384                       Rotterdam  ...                          NaN   \n",
       "23385                       Rotterdam  ...                          NaN   \n",
       "23386                       Rotterdam  ...                          NaN   \n",
       "...                               ...  ...                          ...   \n",
       "23636                         Venedig  ...                          NaN   \n",
       "22640                         Venedig  ...                          NaN   \n",
       "22650                           Paris  ...                          NaN   \n",
       "22651                         Utrecht  ...                          NaN   \n",
       "23439                          Oxford  ...                          NaN   \n",
       "\n",
       "      Wissensklasse Wissensunterklasse  Formatangabe   \n",
       "23376           NaN                NaN           NaN  \\\n",
       "23383           NaN                NaN           NaN   \n",
       "23384           NaN                NaN           NaN   \n",
       "23385           NaN                NaN           NaN   \n",
       "23386           NaN                NaN           NaN   \n",
       "...             ...                ...           ...   \n",
       "23636           NaN                NaN           NaN   \n",
       "22640           NaN                NaN           NaN   \n",
       "22650           NaN                NaN           NaN   \n",
       "22651           NaN                NaN           NaN   \n",
       "23439           NaN                NaN           NaN   \n",
       "\n",
       "       hs. Katalogseite Handschrift  hs. Katalogeintrag ID   \n",
       "23376                           NaN                    NaN  \\\n",
       "23383                           NaN                    NaN   \n",
       "23384                           NaN                    NaN   \n",
       "23385                           NaN                    NaN   \n",
       "23386                           NaN                    NaN   \n",
       "...                             ...                    ...   \n",
       "23636                           NaN                    NaN   \n",
       "22640                           NaN                    NaN   \n",
       "22650                           NaN                    NaN   \n",
       "22651                           NaN                    NaN   \n",
       "23439                           NaN                    NaN   \n",
       "\n",
       "       hs. Katalogeintrag hs. Katalog Image URL  dup_title  copy_from  \n",
       "23376                 NaN                   NaN       True         -1  \n",
       "23383                 NaN                   NaN       True         -1  \n",
       "23384                 NaN                   NaN       True         -1  \n",
       "23385                 NaN                   NaN       True         -1  \n",
       "23386                 NaN                   NaN       True         -1  \n",
       "...                   ...                   ...        ...        ...  \n",
       "23636                 NaN                   NaN       True         -3  \n",
       "22640                 NaN                   NaN       True         -3  \n",
       "22650                 NaN                   NaN      False         -1  \n",
       "22651                 NaN                   NaN      False         -1  \n",
       "23439                 NaN                   NaN      False         -1  \n",
       "\n",
       "[22861 rows x 35 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comp_BE_no_dup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "38688d20-39e4-4f79-a509-c145c24eeace",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1901"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(BE_df[BE_df['Signatur'].str.contains('BE.11.')])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "3bffc3af-3213-435c-b5a0-6b3b8589c61e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 123964 characters]",
      "text/plain": [
       "<Figure size 900x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cats = entry_df['category'].value_counts()\n",
    "\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(9,5))\n",
    "\n",
    "bar = ax.bar(cats.index, cats.values, 0.7, color='#ffb66d')\n",
    "ax.bar_label(bar, labels=cats.values, rotation=90, padding=5, fontsize=10)\n",
    "ax.set_xticks(ax.get_xticks(), ax.get_xticklabels(), rotation=45, rotation_mode='anchor', ha='right', va='center_baseline', fontsize=10)\n",
    "ax.set_ylim(top=1700)\n",
    "plt.margins(x=0.02, tight=True)\n",
    "ax.spines['top'].set_visible(False)\n",
    "ax.spines['right'].set_visible(False)\n",
    "ax.spines['bottom'].set_visible(True)\n",
    "ax.spines['left'].set_visible(True)\n",
    "# plt.xticks(rotation=45, ha='right')\n",
    "# ax.set_title('Anzahl der Einträge im hs. Katalog nach Wissensklasse')\n",
    "plt.savefig('img/Wissensklassen.png', bbox_inches='tight', dpi=300)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75b3839d-585f-4974-9558-395a470c3dc2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
