Bladeren bron

new_tests

Francesco 2 jaren geleden
bovenliggende
commit
60ea0fc561
2 gewijzigde bestanden met toevoegingen van 313 en 477 verwijderingen
  1. 1 0
      .gitignore
  2. 312 477
      ASPO/EAD_to_CSV/EAD_to_CSV_ospedale_newTest.ipynb

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
  
  
 tempWork/
 tempWork/
+.vscode/

+ 312 - 477
ASPO/EAD_to_CSV/EAD_to_CSV_ospedale_newTest.ipynb

@@ -122,8 +122,8 @@
    "metadata": {},
    "metadata": {},
    "outputs": [],
    "outputs": [],
    "source": [
    "source": [
-    "import_dir = '/Users/federicaspinelli/Google Drive/OVI:CNR/LAVORO 2020/SELEZIONE CONTENUTI/01_ASPO/XDAMS/'\n",
-    "export_dir = '/Users/federicaspinelli/Google Drive/OVI:CNR/CSV/ASPO/ospedale/'"
+    "import_dir = '../../Data/DallASPO/'\n",
+    "export_dir = './'"
    ]
    ]
   },
   },
   {
   {
@@ -142,7 +142,7 @@
      "name": "stdout",
      "name": "stdout",
      "output_type": "stream",
      "output_type": "stream",
      "text": [
      "text": [
-      "1.052720069885254\n"
+      "1.2158260345458984\n"
      ]
      ]
     }
     }
    ],
    ],
@@ -173,7 +173,7 @@
      "name": "stdout",
      "name": "stdout",
      "output_type": "stream",
      "output_type": "stream",
      "text": [
      "text": [
-      "{'subseries', 'series', 'file', 'subgrp', 'otherlevel', 'recordgrp', 'collection', 'fonds', 'subfonds'}\n"
+      "{'otherlevel', 'fonds', 'series', 'collection', 'subfonds', 'file', 'subgrp', 'recordgrp', 'subseries'}\n"
      ]
      ]
     }
     }
    ],
    ],
@@ -200,17 +200,17 @@
      "name": "stdout",
      "name": "stdout",
      "output_type": "stream",
      "output_type": "stream",
      "text": [
      "text": [
-      "# di tag \"c\", livello subseries, primo passaggio: 151\n",
+      "# di tag \"c\", livello otherlevel, primo passaggio: 321\n",
+      "# di tag \"c\", livello fonds, primo passaggio: 1\n",
       "# di tag \"c\", livello series, primo passaggio: 254\n",
       "# di tag \"c\", livello series, primo passaggio: 254\n",
+      "# di tag \"c\", livello collection, primo passaggio: 1\n",
+      "# di tag \"c\", livello subfonds, primo passaggio: 3\n",
       "# di tag \"c\", livello file, primo passaggio: 7199\n",
       "# di tag \"c\", livello file, primo passaggio: 7199\n",
       "# di tag \"c\", livello subgrp, primo passaggio: 10\n",
       "# di tag \"c\", livello subgrp, primo passaggio: 10\n",
-      "# di tag \"c\", livello otherlevel, primo passaggio: 321\n",
       "# di tag \"c\", livello recordgrp, primo passaggio: 7\n",
       "# di tag \"c\", livello recordgrp, primo passaggio: 7\n",
-      "# di tag \"c\", livello collection, primo passaggio: 1\n",
-      "# di tag \"c\", livello fonds, primo passaggio: 1\n",
-      "# di tag \"c\", livello subfonds, primo passaggio: 3\n",
+      "# di tag \"c\", livello subseries, primo passaggio: 151\n",
       "\n",
       "\n",
-      "Tempo trascorso: 0.7257428169250488\n"
+      "Tempo trascorso: 0.6825399398803711\n"
      ]
      ]
     }
     }
    ],
    ],
@@ -251,26 +251,26 @@
      "name": "stdout",
      "name": "stdout",
      "output_type": "stream",
      "output_type": "stream",
      "text": [
      "text": [
-      "# di tag \"c\", livello subseries, primo passaggio: 151\n",
-      "# di tag \"c\", livello subseries, totali: 163\n",
+      "# di tag \"c\", livello otherlevel, primo passaggio: 321\n",
+      "# di tag \"c\", livello otherlevel, totali: 321\n",
+      "# di tag \"c\", livello fonds, primo passaggio: 1\n",
+      "# di tag \"c\", livello fonds, totali: 11\n",
       "# di tag \"c\", livello series, primo passaggio: 254\n",
       "# di tag \"c\", livello series, primo passaggio: 254\n",
       "# di tag \"c\", livello series, totali: 254\n",
       "# di tag \"c\", livello series, totali: 254\n",
+      "# di tag \"c\", livello collection, primo passaggio: 1\n",
+      "# di tag \"c\", livello collection, totali: 1\n",
+      "# di tag \"c\", livello subfonds, primo passaggio: 3\n",
+      "# di tag \"c\", livello subfonds, totali: 3\n",
       "# di tag \"c\", livello file, primo passaggio: 7199\n",
       "# di tag \"c\", livello file, primo passaggio: 7199\n",
       "# di tag \"c\", livello file, totali: 7199\n",
       "# di tag \"c\", livello file, totali: 7199\n",
       "# di tag \"c\", livello subgrp, primo passaggio: 10\n",
       "# di tag \"c\", livello subgrp, primo passaggio: 10\n",
       "# di tag \"c\", livello subgrp, totali: 10\n",
       "# di tag \"c\", livello subgrp, totali: 10\n",
-      "# di tag \"c\", livello otherlevel, primo passaggio: 321\n",
-      "# di tag \"c\", livello otherlevel, totali: 321\n",
       "# di tag \"c\", livello recordgrp, primo passaggio: 7\n",
       "# di tag \"c\", livello recordgrp, primo passaggio: 7\n",
       "# di tag \"c\", livello recordgrp, totali: 7\n",
       "# di tag \"c\", livello recordgrp, totali: 7\n",
-      "# di tag \"c\", livello collection, primo passaggio: 1\n",
-      "# di tag \"c\", livello collection, totali: 1\n",
-      "# di tag \"c\", livello fonds, primo passaggio: 1\n",
-      "# di tag \"c\", livello fonds, totali: 11\n",
-      "# di tag \"c\", livello subfonds, primo passaggio: 3\n",
-      "# di tag \"c\", livello subfonds, totali: 3\n",
+      "# di tag \"c\", livello subseries, primo passaggio: 151\n",
+      "# di tag \"c\", livello subseries, totali: 163\n",
       "\n",
       "\n",
-      "Tempo trascorso: 1.1849439144134521\n"
+      "Tempo trascorso: 1.0391268730163574\n"
      ]
      ]
     }
     }
    ],
    ],
@@ -360,7 +360,7 @@
       "\n",
       "\n",
       "[('c', {'level': 'otherlevel', 'otherlevel': 'subfile', 'id': 'IT-ASPO-ST00005-0002653', 'audience': 'external'}, ''), ('did', {}, ''), ('physdesc', {'encodinganalog': 'ISAD 3-1-5 extent and medium of the unit of description'}, '')]\n",
       "[('c', {'level': 'otherlevel', 'otherlevel': 'subfile', 'id': 'IT-ASPO-ST00005-0002653', 'audience': 'external'}, ''), ('did', {}, ''), ('physdesc', {'encodinganalog': 'ISAD 3-1-5 extent and medium of the unit of description'}, '')]\n",
       "[0, 2, 3]\n",
       "[0, 2, 3]\n",
-      "('physfacet', {'type': 'note'}, 'Legatura�origiale�i�cartoe')\n",
+      "('physfacet', {'type': 'note'}, 'Legatura\\xa0origiale\\xa0i\\xa0cartoe')\n",
       "# of children: 0\n",
       "# of children: 0\n",
       "\n",
       "\n",
       "[('c', {'level': 'otherlevel', 'otherlevel': 'subfile', 'id': 'IT-ASPO-ST00005-0002653', 'audience': 'external'}, ''), ('processinfo', {}, ''), ('list', {}, ''), ('item', {}, 'iserimeto i Ariaa 3.2')]\n",
       "[('c', {'level': 'otherlevel', 'otherlevel': 'subfile', 'id': 'IT-ASPO-ST00005-0002653', 'audience': 'external'}, ''), ('processinfo', {}, ''), ('list', {}, ''), ('item', {}, 'iserimeto i Ariaa 3.2')]\n",
@@ -422,7 +422,7 @@
    "cell_type": "markdown",
    "cell_type": "markdown",
    "metadata": {},
    "metadata": {},
    "source": [
    "source": [
-    "(*NOTA X ME:* **'did' = 'Descriptive IDentification'**)"
+    "## QUI SI INIZIA"
    ]
    ]
   },
   },
   {
   {
@@ -431,7 +431,7 @@
    "source": [
    "source": [
     "A questo punto, quello che devo fare è scrivere un **traduttore** -- una funzione che scorra l'output degli elementi esaminati e trasformi le info in modo da poterle esportare in formato csv (o in qualunque altro formato vogliamo).\n",
     "A questo punto, quello che devo fare è scrivere un **traduttore** -- una funzione che scorra l'output degli elementi esaminati e trasformi le info in modo da poterle esportare in formato csv (o in qualunque altro formato vogliamo).\n",
     "\n",
     "\n",
-    "La mia attuale versione di **traduttore per gli item** è data nella prossima cella; accetta come argomento un nodo (che è supposto essere di tipo item) e restituisce un dict."
+    "La veccia versione di **traduttore per gli item**  dell'Ospedale è data nella prossima cella; accetta come argomento un nodo (che è supposto essere di tipo item) e restituisce un dict."
    ]
    ]
   },
   },
   {
   {
@@ -728,7 +728,7 @@
       "\n",
       "\n",
       "titolo_aspo: \"N.2 1420. Testamento di mona Margherita Buri moglie di Paolo Saccagnini con obbligo a' suoi figliuoli eredi di fare ogni anno in S. Francesco la festa di S. Antonio da Padova\"\n",
       "titolo_aspo: \"N.2 1420. Testamento di mona Margherita Buri moglie di Paolo Saccagnini con obbligo a' suoi figliuoli eredi di fare ogni anno in S. Francesco la festa di S. Antonio da Padova\"\n",
       "\n",
       "\n",
-      "data_periodo: 1420�nov.�19\n",
+      "data_periodo: 1420 nov. 19\n",
       "\n",
       "\n",
       "segnatura_attuale: 1\n",
       "segnatura_attuale: 1\n",
       "\n",
       "\n",
@@ -759,535 +759,370 @@
    "cell_type": "markdown",
    "cell_type": "markdown",
    "metadata": {},
    "metadata": {},
    "source": [
    "source": [
-    "# Export\n",
-    "\n",
-    "Produciamo il CSV per gli item tracciando, al solito, il tempo impiegato."
+    "L'idea è di definire un **nuovo** traduttore che lavora tramite file di configurazione e dà lo stesso output."
    ]
    ]
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 12,
-   "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 1.894237995147705\n"
-     ]
-    }
-   ],
-   "source": [
-    "# Do it! Export del CSV - items.\n",
-    "\n",
-    "ts1 = datetime.timestamp(datetime.now())\n",
-    "\n",
-    "# Apro il file per l'export\n",
-    "with open(export_dir + \"data_file.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    # Definisco la classe-motore per l'export\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(itemHeader.keys()))\n",
-    "    # Scrivo l'intestazione\n",
-    "    writer.writeheader()\n",
-    "    # Scrivo la seconda riga, esplicativa\n",
-    "    writer.writerow(itemHeader)\n",
-    "    # Scrivo gli item tradotti, uno a uno\n",
-    "    for ii in range(len(allCs2['file'])):\n",
-    "        test = allCs2['file'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
-    "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# Altri livelli"
-   ]
-  },
-  {
-   "cell_type": "markdown",
+   "execution_count": null,
    "metadata": {},
    "metadata": {},
-   "source": [
-    "Definisco un dizionario ridotto per l'header delle *subseries*, poi esporto -- per il momento con lo stesso traduttore usato per gli *item*"
-   ]
+   "outputs": [],
+   "source": []
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": null,
    "metadata": {},
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 0.009209156036376953\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
    "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
+    "def traduttoreNew(elem):\n",
+    "    # Variabile che contiene l'output della traduzione:\n",
+    "    csvProt = {}\n",
     "\n",
     "\n",
-    "subSeriesKeys = set()\n",
-    "for ii in range(len(allCs2['subgrp'])):\n",
-    "    test = allCs2['subgrp'][ii]\n",
-    "    subSeriesKeys = subSeriesKeys.union( traduttoreItem(test).keys() )\n",
+    "    # Processo i nodi-parent di 'elem'\n",
+    "    par_tags = list(map(lambda a: a.tag, elem['a_par']))\n",
+    "    par_attributes = list(map(lambda a: a.attrib, elem['a_par']))\n",
+    "    \n",
+    "    # e0: Le varie id dei nodi parent\n",
+    "    for ii in indices(par_tags, 'c'):\n",
+    "        key = 'id_' + par_attributes[ii]['level']\n",
+    "        csvProt[key] = par_attributes[ii]['id']\n",
     "\n",
     "\n",
-    "subSeriesHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in subSeriesKeys):\n",
-    "        subSeriesHeader[key] = itemHeader[key]\n",
+    "    # Processo i nodi-child di 'elem'\n",
+    "    childrenNodes = traceElems(elem['child'], isLeafOrC)\n",
+    "    first = True\n",
+    "    for node in childrenNodes:\n",
+    "        tags = [ a.tag for a in node['a_par'] ].append(node['child'].tag)\n",
+    "        attributes = [ a.attrib for a in node['a_par'] ].append(node['child'].attrib)\n",
+    "        nodeContent = node['child'].text\n",
     "\n",
     "\n",
+    "        # Da controllare solo per il primo nodo\n",
+    "        # (informazioni a livello del nodo, uguali per tutti i figli)\n",
+    "        if(first):\n",
+    "            # e1 ID della item\n",
+    "            csvProt['id'] = attributes[tags.index('c')]['id']\n",
+    "            # e2 Audience: external o internal\n",
+    "            try:\n",
+    "                csvProt['audience'] = attributes[tags.index('c')]['audience']\n",
+    "            except:\n",
+    "                pass\n",
+    "            # e3 Otherlevel\n",
+    "            try:\n",
+    "                csvProt['altro_livello'] = attributes[tags.index('c')]['otherlevel']\n",
+    "            except:\n",
+    "                pass\n",
+    "            first = False\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_subgrp.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(subSeriesHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(subSeriesHeader)\n",
-    "    for ii in range(len(allCs2['subgrp'])):\n",
-    "        test = allCs2['subgrp'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "        # La 'ciccia': si processa il contenuto vero e proprio\n",
+    "        # e4 Repository (qui dovrebbe essere sempre l'Archivio di Prato)\n",
+    "        if('repository' in tags):\n",
+    "            csvProt['repository'] = nodeContent  \n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 14,
-   "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 0.14556884765625\n"
-     ]
-    }
-   ],
-   "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
+    "        # e8 Tipologia\n",
+    "        try:\n",
+    "            ii = tags.index('materialspec')\n",
+    "            if(attributes[ii]['label']=='tipologia'): \n",
+    "                csvProt['tipologia'] = nodeContent\n",
+    "        except:\n",
+    "            pass\n",
     "\n",
     "\n",
-    "subSeriesKeys = set()\n",
-    "for ii in range(len(allCs2['subseries'])):\n",
-    "    test = allCs2['subseries'][ii]\n",
-    "    subSeriesKeys = subSeriesKeys.union( traduttoreItem(test).keys() )\n",
+    "        # e9 Segnatura attuale\n",
+    "        try:\n",
+    "            ii = tags.index('num')\n",
+    "            type1 = attributes[ii]['type']\n",
+    "            if(type1=='nuovo ordinamento'):\n",
+    "               csvProt['segnatura_attuale'] = nodeContent\n",
+    "        except:\n",
+    "            pass\n",
+    "        # e9 Segnatura precedente ('odd')\n",
+    "        if('odd' in tags):\n",
+    "            csvProt['segnatura_precedente'] = nodeContent       \n",
+    "        \n",
+    "        # e11 Il titolo da unittitle\n",
+    "        try:\n",
+    "            aa = csvProt['titolo_aspo']\n",
+    "        except:\n",
+    "            try:\n",
+    "                ii = tags.index('unittitle')\n",
+    "                try:\n",
+    "                    csvProt['titolo_aspo'] = str(node['a_par'][ii].text).replace('\\t','').replace('\\n','').strip()\n",
+    "                except:\n",
+    "                    csvProt['titolo_aspo'] = str(nodeContent).replace('\\t','').replace('\\n','').strip()\n",
+    "            except:\n",
+    "                pass\n",
+    "        \n",
+    "        # e12 Scope-content head & body\n",
+    "        if('scopecontent' in tags):\n",
+    "            if('p' in tags):\n",
+    "                csvProt['scope-content_body'] = nodeContent\n",
     "\n",
     "\n",
-    "subSeriesHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in subSeriesKeys):\n",
-    "        subSeriesHeader[key] = itemHeader[key]\n",
+    "        # e14 Nome della compagnia\n",
+    "        try:\n",
+    "            ii = tags.index('corpname')\n",
+    "            if(attributes[ii]['authfilenumber']):\n",
+    "                try:\n",
+    "                    authId = attributes[ii]['authfilenumber']\n",
+    "                    csvProt['compagnia'] = '{\"nome\": ' + \"\\\"\" + nodeContent + \"\\\"\" + ', \"authID\": ' + \"\\\"\" + authId + \"\\\"\" + '}'\n",
+    "                except:\n",
+    "                    csvProt['compagnia'] = '{\"nome\": ' + \"\\\"\" + nodeContent + \"\\\"\" + '}'\n",
+    "        except:\n",
+    "            pass\n",
+    "        \n",
+    "        # e16 Persona\n",
+    "        if ('controlaccess' in tags):\n",
+    "            try: \n",
+    "                ii=tags.index('persname')       \n",
+    "                key='persona'  \n",
+    "                authId = attributes[ii]['authfilenumber']\n",
+    "                try:       \n",
+    "                    csvProt[key] = csvProt[key] + ' | {\"nome\": ' + \"\\\"\" + nodeContent + \"\\\"\" + ', \"authID\": ' + \"\\\"\" + authId + \"\\\"\" +'}'\n",
+    "                except:                         \n",
+    "                    csvProt[key] = '{\"nome\": ' + \"\\\"\" + nodeContent + \"\\\"\" + ', \"authID\": ' + \"\\\"\" + authId + \"\\\"\" +'}'\n",
+    "            except:                \n",
+    "                try:\n",
+    "                    csvProt[key] = csvProt[key] + ' | {\"nome\": ' + \"\\\"\" + nodeContent + \"\\\"\" + '}'\n",
+    "                except:\n",
+    "                    csvProt[key] = '{\"nome\": ' + \"\\\"\" + nodeContent + \"\\\"\" + '}'\n",
     "\n",
     "\n",
+    "        # e17 Date\n",
+    "        if ('unittitle' in tags):\n",
+    "            try:\n",
+    "                ii = tags.index('date')\n",
+    "                key = 'data'\n",
+    "                csvProt[key] = nodeContent\n",
+    "            except:\n",
+    "                pass\n",
+    "       \n",
+    "        # e18 Data 1: periodo\n",
+    "        if('unitdate' in tags):\n",
+    "            csvProt['data_periodo'] = nodeContent\n",
+    "        \n",
+    "        # e20 Supporto fisico\n",
+    "        try:\n",
+    "            ii = tags.index('physfacet')\n",
+    "            if(attributes[ii]['type']=='supporto'):\n",
+    "                csvProt['supporto'] = nodeContent\n",
+    "        except:\n",
+    "            pass\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_subseries.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(subSeriesHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(subSeriesHeader)\n",
-    "    for ii in range(len(allCs2['subseries'])):\n",
-    "        test = allCs2['subseries'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "        # e21 Physdesc \n",
+    "        if('extent' in tags):\n",
+    "            csvProt['numero'] = nodeContent\n",
+    "        if('genreform' in tags):\n",
+    "            csvProt['genere'] = nodeContent\n",
+    "        \n",
+    "        # e21 Dimensions\n",
+    "        try:\n",
+    "            ii = tags.index('dimensions')\n",
+    "            try:\n",
+    "                csvProt['dimensione_altezza_larghezza_spessore'] = csvProt['dimensione_altezza_larghezza_spessore'] + ' | ' + nodeContent\n",
+    "            except:\n",
+    "                csvProt['dimensione_altezza_larghezza_spessore'] = nodeContent\n",
+    "        except:\n",
+    "            pass\n",
+    "        \n",
+    "        # e22 Phystech  \n",
+    "        try:\n",
+    "            ii = tags.index('phystech')\n",
+    "            try:\n",
+    "                csvProt['conservazione'] = csvProt['conservazione'] + ' | ' + nodeContent\n",
+    "            except:\n",
+    "                csvProt['conservazione'] = nodeContent\n",
+    "        except:\n",
+    "            pass\n",
+    "        \n",
+    "        # e24 Note\n",
+    "        if('note' in tags):\n",
+    "            csvProt['nota'] = nodeContent\n",
+    "        \n",
+    "        # e26 Oggetto digitale allegato (nome)\n",
+    "        try:\n",
+    "            ii = tags.index('daoloc')\n",
+    "            out = attributes[ii]['title']\n",
+    "            try:\n",
+    "                csvProt['oggetto_digitale'] = csvProt['oggetto_digitale'] + ' | ' + out\n",
+    "            except:\n",
+    "                csvProt['oggetto_digitale'] = out\n",
+    "        except:\n",
+    "            pass\n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "*Rinse & Repeat* con i livelli *series*, *subfonds* e *fonds*"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 15,
-   "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 0.14042901992797852\n"
-     ]
-    }
-   ],
-   "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
+    "    return csvProt\n",
     "\n",
     "\n",
-    "seriesKeys = set()\n",
-    "for ii in range(len(allCs2['series'])):\n",
-    "    test = allCs2['series'][ii]\n",
-    "    seriesKeys = seriesKeys.union( traduttoreItem(test).keys() )\n",
     "\n",
     "\n",
-    "seriesHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in seriesKeys):\n",
-    "        seriesHeader[key] = itemHeader[key]\n",
+    "# Di pari passo alla funzione, definisco un dict contenente tutti gli header;\n",
+    "# servirà per il CSV.\n",
+    "itemHeader = OrderedDict()\n",
     "\n",
     "\n",
+    "# e1 ID dell'entità\n",
+    "itemHeader.update({'id': '<c level=\"X\" id=#>'})\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_series.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(seriesHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(seriesHeader)\n",
-    "    for ii in range(len(allCs2['series'])):\n",
-    "        test = allCs2['series'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "# e2 Audience: external o internal\n",
+    "itemHeader.update({'audience': '<c level=\"#\" audience=#>'})\n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 16,
-   "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 0.004575967788696289\n"
-     ]
-    }
-   ],
-   "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
+    "# e3 Otherlevel\n",
+    "itemHeader.update({'altro_livello': '<c otherlevel=#>'})\n",
     "\n",
     "\n",
-    "subfondsKeys = set()\n",
-    "for ii in range(len(allCs2['subfonds'])):\n",
-    "    test = allCs2['subfonds'][ii]\n",
-    "    subfondsKeys = subfondsKeys.union( traduttoreItem(test).keys() )\n",
+    "# e4 Repository (qui dovrebbe essere sempre l'Archivio di Prato)\n",
+    "itemHeader.update({'repository': '<repository>#'})\n",
     "\n",
     "\n",
-    "subfondsHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in subfondsKeys):\n",
-    "        subfondsHeader[key] = itemHeader[key]\n",
+    "# e8 Tipologia\n",
+    "itemHeader.update({'tipologia': '<materialspec label=\"tipologia\">#'})\n",
     "\n",
     "\n",
+    "# e9 Segnatura attuale\n",
+    "itemHeader.update({'segnatura_attuale': '<num type=\"nuovo ordinamento\">#'})\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_subfonds.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(subfondsHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(subfondsHeader)\n",
-    "    for ii in range(len(allCs2['subfonds'])):\n",
-    "        test = allCs2['subfonds'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "# e9 Segnatura precedente\n",
+    "itemHeader.update({'segnatura_precedente': '<odd>#'})\n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 17,
-   "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 0.006090879440307617\n"
-     ]
-    }
-   ],
-   "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
+    "# e11 Titolo ASPO\n",
+    "itemHeader.update({'titolo_aspo': '<unittitle>#'})\n",
     "\n",
     "\n",
-    "fondsKeys = set()\n",
-    "for ii in range(len(allCs2['fonds'])):\n",
-    "    test = allCs2['fonds'][ii]\n",
-    "    fondsKeys = fondsKeys.union( traduttoreItem(test).keys() )\n",
+    "# e12 Scope content, head & body\n",
+    "itemHeader.update(\n",
+    "{'scope-content_head': '<scopecontent><head>#',\n",
+    " 'scope-content_body': '<scopecontent><p>#'})\n",
     "\n",
     "\n",
-    "fondsHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in fondsKeys):\n",
-    "        fondsHeader[key] = itemHeader[key]\n",
+    "# e14 Nome della compagnia\n",
+    "itemHeader.update({'compagnia': '<corpname>#'})\n",
     "\n",
     "\n",
+    "# e15 Soggetto\n",
+    "itemHeader.update({'soggetto': '<subject>#'})\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_fonds.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(fondsHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(fondsHeader)\n",
-    "    for ii in range(len(allCs2['fonds'])):\n",
-    "        test = allCs2['fonds'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "# e16 Persona\n",
+    "itemHeader.update({'persona': '<persname authfilenumber=#>#'})\n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 18,
-   "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Tempo trascorso: 0.001628875732421875\n"
-     ]
-    }
-   ],
-   "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
+    "# e17 Date\n",
+    "itemHeader.update(\n",
+    "{'data': '<date>#'})\n",
     "\n",
     "\n",
-    "collectionKeys = set()\n",
-    "for ii in range(len(allCs2['collection'])):\n",
-    "    test = allCs2['collection'][ii]\n",
-    "    collectionKeys = collectionKeys.union( traduttoreItem(test).keys() )\n",
+    "# e18 Data 1: periodo\n",
+    "itemHeader.update({'data_periodo': '<unitdate>#'})\n",
+    "\n",
+    "# e20 Supporto fisico\n",
+    "itemHeader.update({'supporto': '<physfacet type=\"supporto\">#'})\n",
     "\n",
     "\n",
-    "collectionHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in collectionKeys):\n",
-    "        collectionHeader[key] = itemHeader[key]\n",
+    "# e21 descrizione fisica\n",
+    "itemHeader.update({'numero': '<extent>#'})\n",
+    "itemHeader.update({'genere': '<genreform>#'})\n",
+    "# e21 dimensions\n",
+    "itemHeader.update({'dimensione_altezza_larghezza_spessore': '<dimensions>#'})\n",
     "\n",
     "\n",
+    "# e22 Phystech\n",
+    "itemHeader.update({'conservazione': '<phystech>#'})\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_collection.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(collectionHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(collectionHeader)\n",
-    "    for ii in range(len(allCs2['collection'])):\n",
-    "        test = allCs2['collection'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "# e23 Consistenza\n",
+    "itemHeader.update({'consistenza': '<extent unit=#1>#2, #1: #2'})\n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
+    "# 24 Note\n",
+    "itemHeader.update({'nota': '<note>#'})\n",
+    "\n",
+    "# e26 Oggetto digitale allegato (nome)\n",
+    "itemHeader.update({'oggetto_digitale': '<daoloc title=#>'})\n",
+    "\n",
+    "#0: Le varie id dei nodi parent\n",
+    "itemHeader.update(\n",
+    "{'id_subfonds': '<c level=\"subfonds\" id=#>',\n",
+    " 'id_fonds': '<c level=\"fonds\" id=#>',\n",
+    " 'id_series': '<c level=\"series\" id=#>',\n",
+    " 'id_subseries': '<c level=\"subseries\" id=#>',\n",
+    " 'id_recordgrp': '<c level=\"recordgrp\" id=#>',\n",
+    " 'id_otherlevel': '<c level=\"otherlevel\" id=# otherlevel=\"subfile\">',\n",
+    " 'id_collection': '<c level=\"collection\" id=#>',\n",
+    " 'id_subgrp': '<c level=\"subgrp\" id=#>',\n",
+    " 'id_collection': '<c level=\"collection\" id=#>',\n",
+    " 'id_file': '<c level=\"file\" id=#>'})"
    ]
    ]
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 19,
+   "execution_count": 12,
    "metadata": {},
    "metadata": {},
    "outputs": [
    "outputs": [
     {
     {
      "name": "stdout",
      "name": "stdout",
      "output_type": "stream",
      "output_type": "stream",
      "text": [
      "text": [
-      "Tempo trascorso: 0.003462076187133789\n"
+      "id_fonds: IT-ASPO-ST00005-0000002\n",
+      "\n",
+      "id_series: IT-ASPO-ST00005-0000003\n",
+      "\n",
+      "id: IT-ASPO-ST00005-0000004\n",
+      "\n",
+      "audience: external\n",
+      "\n",
+      "titolo_aspo: \"N.2 1420. Testamento di mona Margherita Buri moglie di Paolo Saccagnini con obbligo a' suoi figliuoli eredi di fare ogni anno in S. Francesco la festa di S. Antonio da Padova\"\n",
+      "\n",
+      "data_periodo: 1420 nov. 19\n",
+      "\n",
+      "segnatura_attuale: 1\n",
+      "\n",
+      "genere: pergamena\n",
+      "\n",
+      "dimensione_altezza_larghezza_spessore: 370 | 255 | 20\n",
+      "\n",
+      "persona: {\"nome\": \"Buri Margherita di Bartolomeo\", \"authID\": \"IT-ASPO-AU00002-0001222\"} | {\"nome\": \"Saccagnini Paolo di Vanni da Pratolino\", \"authID\": \"IT-ASPO-AU00002-0001014\"} | {\"nome\": \"Bandini Paolo di ser Vannozzo\", \"authID\": \"IT-ASPO-AU00002-0001330\"}\n",
+      "\n",
+      "scope-content_body: Atto rogato da Paolo di ser Vannozzo Bandini da Prato.\n",
+      "\n",
+      "conservazione: buona\n",
+      "\n",
+      "segnatura_precedente: 2996/5\n",
+      "\n"
      ]
      ]
     }
     }
    ],
    ],
    "source": [
    "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
-    "\n",
-    "subSeriesKeys = set()\n",
-    "for ii in range(len(allCs2['recordgrp'])):\n",
-    "    test = allCs2['recordgrp'][ii]\n",
-    "    subSeriesKeys = subSeriesKeys.union( traduttoreItem(test).keys() )\n",
-    "\n",
-    "subSeriesHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in subSeriesKeys):\n",
-    "        subSeriesHeader[key] = itemHeader[key]\n",
-    "\n",
+    "test = allCs2['file'][0]\n",
+    "toShow = traduttoreItem(test)\n",
+    "for key in toShow.keys():\n",
+    "    print(key + ': ' + str(toShow[key]))\n",
+    "    print()"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# Export\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_recordgrp.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(subSeriesHeader.keys()))\n",
-    "    writer.writeheader()\n",
-    "    writer.writerow(subSeriesHeader)\n",
-    "    for ii in range(len(allCs2['recordgrp'])):\n",
-    "        test = allCs2['recordgrp'][ii]\n",
-    "        writer.writerow(traduttoreItem(test))\n",
+    "### -- questo serve **dopo**\n",
     "\n",
     "\n",
-    "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
+    "Produciamo il CSV per gli item tracciando, al solito, il tempo impiegato."
    ]
    ]
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 20,
+   "execution_count": 12,
    "metadata": {},
    "metadata": {},
    "outputs": [
    "outputs": [
     {
     {
      "name": "stdout",
      "name": "stdout",
      "output_type": "stream",
      "output_type": "stream",
      "text": [
      "text": [
-      "Tempo trascorso: 0.1351768970489502\n"
+      "Tempo trascorso: 1.894237995147705\n"
      ]
      ]
     }
     }
    ],
    ],
    "source": [
    "source": [
-    "ts1 = datetime.timestamp(datetime.now())\n",
-    "\n",
-    "otherlevelKeys = set()\n",
-    "for ii in range(len(allCs2['otherlevel'])):\n",
-    "    test = allCs2['otherlevel'][ii]\n",
-    "    otherlevelKeys = otherlevelKeys.union( traduttoreItem(test).keys() )\n",
-    "\n",
-    "otherlevelHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in otherlevelKeys):\n",
-    "        otherlevelHeader[key] = itemHeader[key]\n",
+    "# Do it! Export del CSV - items.\n",
     "\n",
     "\n",
+    "ts1 = datetime.timestamp(datetime.now())\n",
     "\n",
     "\n",
-    "with open(export_dir + \"data_otherlevel.csv\", \"w\", newline=\"\") as csv_file:\n",
-    "    writer = csv.DictWriter(csv_file, fieldnames=list(otherlevelHeader.keys()))\n",
+    "# Apro il file per l'export\n",
+    "with open(export_dir + \"data_file.csv\", \"w\", newline=\"\") as csv_file:\n",
+    "    # Definisco la classe-motore per l'export\n",
+    "    writer = csv.DictWriter(csv_file, fieldnames=list(itemHeader.keys()))\n",
+    "    # Scrivo l'intestazione\n",
     "    writer.writeheader()\n",
     "    writer.writeheader()\n",
-    "    writer.writerow(otherlevelHeader)\n",
-    "    for ii in range(len(allCs2['otherlevel'])):\n",
-    "        test = allCs2['otherlevel'][ii]\n",
+    "    # Scrivo la seconda riga, esplicativa\n",
+    "    writer.writerow(itemHeader)\n",
+    "    # Scrivo gli item tradotti, uno a uno\n",
+    "    for ii in range(len(allCs2['file'])):\n",
+    "        test = allCs2['file'][ii]\n",
     "        writer.writerow(traduttoreItem(test))\n",
     "        writer.writerow(traduttoreItem(test))\n",
     "\n",
     "\n",
     "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
     "print('Tempo trascorso:', datetime.timestamp(datetime.now()) - ts1)"
    ]
    ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 21,
-   "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "{'altro_livello',\n",
-       " 'audience',\n",
-       " 'conservazione',\n",
-       " 'data_periodo',\n",
-       " 'dimensione_altezza_larghezza_spessore',\n",
-       " 'genere',\n",
-       " 'id',\n",
-       " 'id_file',\n",
-       " 'id_fonds',\n",
-       " 'id_recordgrp',\n",
-       " 'id_series',\n",
-       " 'id_subfonds',\n",
-       " 'id_subgrp',\n",
-       " 'id_subseries',\n",
-       " 'nota',\n",
-       " 'numero',\n",
-       " 'persona',\n",
-       " 'scope-content_body',\n",
-       " 'segnatura_attuale',\n",
-       " 'segnatura_precedente',\n",
-       " 'supporto',\n",
-       " 'titolo_aspo'}"
-      ]
-     },
-     "execution_count": 21,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
-   "source": [
-    "otherlevelKeys = set()\n",
-    "for ii in range(len(allCs2['otherlevel'])):\n",
-    "    test = allCs2['otherlevel'][ii]\n",
-    "    otherlevelKeys = otherlevelKeys.union( traduttoreItem(test).keys() )\n",
-    "\n",
-    "otherlevelKeys"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 22,
-   "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "odict_keys(['id', 'audience', 'altro_livello', 'repository', 'tipologia', 'segnatura_attuale', 'segnatura_precedente', 'titolo_aspo', 'scope-content_head', 'scope-content_body', 'compagnia', 'soggetto', 'persona', 'data', 'data_periodo', 'supporto', 'numero', 'genere', 'dimensione_altezza_larghezza_spessore', 'conservazione', 'consistenza', 'nota', 'oggetto_digitale', 'id_subfonds', 'id_fonds', 'id_series', 'id_subseries', 'id_recordgrp', 'id_otherlevel', 'id_collection', 'id_subgrp', 'id_file'])"
-      ]
-     },
-     "execution_count": 22,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
-   "source": [
-    "otherlevelHeader = OrderedDict()\n",
-    "for key in itemHeader:\n",
-    "    if(key in otherlevelKeys):\n",
-    "        otherlevelHeader[key] = itemHeader[key]\n",
-    "\n",
-    "otherlevelHeader\n",
-    "\n",
-    "itemHeader.keys()"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 23,
-   "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "OrderedDict([('id', '<c level=\"X\" id=#>'),\n",
-       "             ('audience', '<c level=\"#\" audience=#>'),\n",
-       "             ('altro_livello', '<c otherlevel=#>'),\n",
-       "             ('segnatura_attuale', '<num type=\"nuovo ordinamento\">#'),\n",
-       "             ('segnatura_precedente', '<odd>#'),\n",
-       "             ('titolo_aspo', '<unittitle>#'),\n",
-       "             ('scope-content_body', '<scopecontent><p>#'),\n",
-       "             ('persona', '<persname authfilenumber=#>#'),\n",
-       "             ('data_periodo', '<unitdate>#'),\n",
-       "             ('supporto', '<physfacet type=\"supporto\">#'),\n",
-       "             ('numero', '<extent>#'),\n",
-       "             ('genere', '<genreform>#'),\n",
-       "             ('dimensione_altezza_larghezza_spessore', '<dimensions>#'),\n",
-       "             ('conservazione', '<phystech>#'),\n",
-       "             ('nota', '<note>#'),\n",
-       "             ('id_subfonds', '<c level=\"subfonds\" id=#>'),\n",
-       "             ('id_fonds', '<c level=\"fonds\" id=#>'),\n",
-       "             ('id_series', '<c level=\"series\" id=#>'),\n",
-       "             ('id_subseries', '<c level=\"subseries\" id=#>'),\n",
-       "             ('id_recordgrp', '<c level=\"recordgrp\" id=#>'),\n",
-       "             ('id_subgrp', '<c level=\"subgrp\" id=#>'),\n",
-       "             ('id_file', '<c level=\"file\" id=#>')])"
-      ]
-     },
-     "execution_count": 23,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
-   "source": [
-    "otherlevelHeader"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 24,
-   "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "OrderedDict([('id', '<c level=\"X\" id=#>'),\n",
-       "             ('audience', '<c level=\"#\" audience=#>'),\n",
-       "             ('altro_livello', '<c otherlevel=#>'),\n",
-       "             ('repository', '<repository>#'),\n",
-       "             ('tipologia', '<materialspec label=\"tipologia\">#'),\n",
-       "             ('segnatura_attuale', '<num type=\"nuovo ordinamento\">#'),\n",
-       "             ('segnatura_precedente', '<odd>#'),\n",
-       "             ('titolo_aspo', '<unittitle>#'),\n",
-       "             ('scope-content_head', '<scopecontent><head>#'),\n",
-       "             ('scope-content_body', '<scopecontent><p>#'),\n",
-       "             ('compagnia', '<corpname>#'),\n",
-       "             ('soggetto', '<subject>#'),\n",
-       "             ('persona', '<persname authfilenumber=#>#'),\n",
-       "             ('data', '<date>#'),\n",
-       "             ('data_periodo', '<unitdate>#'),\n",
-       "             ('supporto', '<physfacet type=\"supporto\">#'),\n",
-       "             ('numero', '<extent>#'),\n",
-       "             ('genere', '<genreform>#'),\n",
-       "             ('dimensione_altezza_larghezza_spessore', '<dimensions>#'),\n",
-       "             ('conservazione', '<phystech>#'),\n",
-       "             ('consistenza', '<extent unit=#1>#2, #1: #2'),\n",
-       "             ('nota', '<note>#'),\n",
-       "             ('oggetto_digitale', '<daoloc title=#>'),\n",
-       "             ('id_subfonds', '<c level=\"subfonds\" id=#>'),\n",
-       "             ('id_fonds', '<c level=\"fonds\" id=#>'),\n",
-       "             ('id_series', '<c level=\"series\" id=#>'),\n",
-       "             ('id_subseries', '<c level=\"subseries\" id=#>'),\n",
-       "             ('id_recordgrp', '<c level=\"recordgrp\" id=#>'),\n",
-       "             ('id_otherlevel',\n",
-       "              '<c level=\"otherlevel\" id=# otherlevel=\"subfile\">'),\n",
-       "             ('id_collection', '<c level=\"collection\" id=#>'),\n",
-       "             ('id_subgrp', '<c level=\"subgrp\" id=#>'),\n",
-       "             ('id_file', '<c level=\"file\" id=#>')])"
-      ]
-     },
-     "execution_count": 24,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
-   "source": [
-    "itemHeader"
-   ]
   }
   }
  ],
  ],
  "metadata": {
  "metadata": {