소스 검색

Add new parsers Datini

federicaspinelli 2 년 전
부모
커밋
dd4748b680
28개의 변경된 파일6564개의 추가작업 그리고 0개의 파일을 삭제
  1. 232 0
      ASPO/CSV_to_RDF/datini/ASPO_CSV_to_RDF_datini_all.ipynb
  2. 270 0
      ASPO/CSV_to_RDF/datini/ASPO_CSV_to_RDF_onomastica_datini.py
  3. 273 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_date.ipynb
  4. 230 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_eac.ipynb
  5. 227 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_file.ipynb
  6. 221 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item.ipynb
  7. 249 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_creation.ipynb
  8. 286 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_creation_actor.ipynb
  9. 257 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_creation_date.ipynb
  10. 258 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange.ipynb
  11. 273 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_date.ipynb
  12. 262 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_place.ipynb
  13. 263 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_receiver.ipynb
  14. 262 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_sender.ipynb
  15. 225 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_extent.ipynb
  16. 215 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_note.ipynb
  17. 205 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_permanent_location.ipynb
  18. 214 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_phydesc.ipynb
  19. 208 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_physfacet.ipynb
  20. 216 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_phystech.ipynb
  21. 207 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_repository.ipynb
  22. 218 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_scopecontent.ipynb
  23. 213 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_segnatura.ipynb
  24. 215 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_title.ipynb
  25. 218 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_series.ipynb
  26. 203 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_subfonds_genreform.ipynb
  27. 236 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_subseries.ipynb
  28. 208 0
      ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_type.ipynb

+ 232 - 0
ASPO/CSV_to_RDF/datini/ASPO_CSV_to_RDF_datini_all.ipynb

@@ -0,0 +1,232 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 49,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "# Utilities to handle character encodings\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 50,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 51,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 52,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 53,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 54,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'subfonds'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasTypeCoords.prefix, manMadeObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(datiniCoords.prefix + row['id'], labelCoords.prefix, '\\\"Documento fisico: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "        line = triple(datiniCoords.prefix + row['id'], carriesCoords.prefix, e73placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, hasTypeCoords.prefix, informationObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, labelCoords.prefix, '\\\"Contenuto informativo: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "\n",
+    "        # If the 'titolo_aspo' property is not empty for the given entry, write down title-related triples\n",
+    "        if(row['titolo_aspo'] != 'None'):\n",
+    "            e35placeHolder1 = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + titleCoords.code + \">\"\n",
+    "            line = triple(e73placeHolder, identifiedByCoords.prefix, e35placeHolder1) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, hasTypeCoords.prefix, titleCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, labelCoords.prefix, '\\\"' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        \n",
+    "        if(row['tipologia'] != ''):\n",
+    "            tipologie = []\n",
+    "            pipe = \"|\" \n",
+    "            if pipe in row['tipologia']:\n",
+    "                tipologie = row['tipologia'].split('|')\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + tipologie.replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "            else:\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "        \n",
+    "        #Genreform disponibile solo per subfonds \n",
+    "        if(row['genere'] != ''):\n",
+    "            tipologie = []\n",
+    "            pipe = \"|\" \n",
+    "            if pipe in row['genere']:\n",
+    "                tipologie = row['genere'].split('|')\n",
+    "                for type in tipologie:\n",
+    "                    tipo = type\n",
+    "                    e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + tipo.replace(\" \", \"\") + \">\"\n",
+    "                    line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                    output.write(line)\n",
+    "            else:\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['genere'].replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.7.3 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 270 - 0
ASPO/CSV_to_RDF/datini/ASPO_CSV_to_RDF_onomastica_datini.py

@@ -0,0 +1,270 @@
+#Parser to convert the Datini onomastics CSV file into TTL format
+
+# Utilities to read/write csv files
+import csv
+# Utilities to handle character encodings
+import unicodedata
+# Ordered Dicts
+from collections import OrderedDict
+
+import json
+import re
+
+
+# OPZIONAL IMPORTS
+
+# For timestamping/simple speed tests
+from datetime import datetime
+# Random number generator
+from random import *
+# System & command line utilities
+import sys
+# Json for the dictionary
+import json
+
+import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/ospedale/'
+export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/ospedale/'
+
+# Custom class to store URIs + related infos for the ontologies/repositories
+
+class RDFcoords:
+    def __init__(self, uri, prefix, code = None):
+        self.uri = uri
+        self.prefix = prefix
+        self.code = code
+
+# Repositories
+aspoCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/>', 'aspo:')
+foafCoords = RDFcoords('<http://xmlns.com/foaf/0.1/>', 'foaf:')
+cidocCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/>', 'crm:')
+schemaCoords = RDFcoords('<http://schema.org/>', 'schema:')
+personCoords = RDFcoords('<http://www.w3.org/ns/person#>', 'person:')
+nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')
+rdfsCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')
+
+
+# Basic functions for triples / shortened triples in TTL format
+
+def triple(subject, predicate, object1):
+    line = subject + ' ' + predicate + ' ' + object1
+    return line
+
+def doublet(predicate, object1):
+    line = '    ' + predicate + ' ' + object1
+    return line
+
+def singlet(object1):
+    line = '        ' + object1
+    return line
+
+# Line endings in TTL format
+continueLine1 = ' ;\n'
+continueLine2 = ' ,\n'
+closeLine = ' .\n'
+
+def writeTTLHeader(output):
+    output.write('@prefix ' + aspoCoords.prefix + ' ' + aspoCoords.uri + closeLine)
+    output.write('@prefix ' + foafCoords.prefix + ' ' + foafCoords.uri + closeLine)
+    output.write('@prefix ' + cidocCoords.prefix + ' ' + cidocCoords.uri + closeLine)
+    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)
+    output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)
+    output.write('@prefix ' + nsCoords.prefix + ' ' + nsCoords.uri + closeLine)
+    output.write('@prefix ' + rdfsCoords.prefix + ' ' + rdfsCoords.uri + closeLine)
+
+    output.write('\n')
+
+
+filePrefix = 'onomastica_'
+fileType = 'ospedale'
+max_entries = 1000000000
+
+with open(import_dir + filePrefix + fileType + '.csv', newline="") as csv_file, open(
+        export_dir + filePrefix + fileType + '.ttl', 'w') as output:
+    reader = csv.DictReader(csv_file)
+    writeTTLHeader(output)
+    first = True
+    ii = 0
+    for row in reader:
+        # The index ii is used to process a limited number of entries for testing purposes
+        ii = ii + 1
+        if row['entityType'] == 'person':
+
+            id_aspo = row['recordId']
+            #placeHolders
+            aspoPlaceHolder = aspoCoords.prefix + id_aspo
+            line = triple(aspoPlaceHolder, 
+                          nsCoords.prefix + 'type', 
+                          cidocCoords.prefix + 'E21_Person') + closeLine
+            output.write(line)
+
+            line = triple(aspoPlaceHolder, 
+                          nsCoords.prefix + 'type', 
+                          personCoords.prefix + 'Person') + closeLine
+            output.write(line)
+
+            line = triple(aspoPlaceHolder,
+                          nsCoords.prefix + 'type',
+                          foafCoords.prefix + 'person') + closeLine
+            output.write(line)
+
+            line = triple(aspoPlaceHolder,
+                          cidocCoords.prefix + 'P1_is_identified_by',
+                          aspoPlaceHolder + "_E42") + closeLine
+            output.write(line)
+
+            line = triple(aspoPlaceHolder + "_E42",
+                          nsCoords.prefix + 'type',
+                          cidocCoords.prefix + 'E42_Identifier') + closeLine
+            output.write(line)
+            line = triple(aspoPlaceHolder + "_E42",
+                          rdfsCoords.prefix + 'label',
+                          '\"' + id_aspo + '\"') + closeLine
+            output.write(line)
+
+            line = triple(aspoPlaceHolder,
+                          foafCoords.prefix + 'name',
+                          '\"' + row['nameEntry@normal'] + '\"') + closeLine
+            output.write(line)
+
+            line = triple(aspoPlaceHolder,
+                          rdfsCoords.prefix + 'label',
+                          '\"' + row['nameEntry@normal'] + '\"') + closeLine
+            output.write(line)
+
+            if row['nome proprio'] != '':
+                #Remove all white-space characters:
+                txt = row['nome proprio']
+                x = re.sub(" \n", "", txt)
+                y = re.sub("\s\s", "", x)
+                line = triple(aspoPlaceHolder,
+                              foafCoords.prefix + 'givenName',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+
+            if row['nome di famiglia'] != '':
+                #Remove all white-space characters:
+                txt = row['nome di famiglia']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", "", x)
+                line = triple(aspoPlaceHolder,
+                              foafCoords.prefix + 'familyName',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+            
+            if row['Alias'] != '' and row['Alias'] != ' ':
+                #Remove all white-space characters:
+                txt = row['Alias']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", "", x)
+                line = triple(aspoPlaceHolder,
+                              schemaCoords.prefix + 'alternateName',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+
+            if row['genere'] != '':
+                #Remove all white-space characters:
+                txt = row['genere']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", "", x)
+                line = triple(aspoPlaceHolder,
+                              foafCoords.prefix + 'gender',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+
+            if row['patronimico/matronimico'] != '':
+                #Remove all white-space characters:
+                txt = row['patronimico/matronimico']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", "", x)
+                line = triple(aspoPlaceHolder,
+                              personCoords.prefix + 'patronymicName',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+
+            if row['occupation'] != '' and row['occupation'] != ' ' :
+                #Remove all white-space characters:
+                txt = row['occupation']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", "", x)
+                occ = re.sub(r'[^A-Za-z]','', y)
+                occupationPlaceHolder = '<http://www.archiviodistato.prato.it/' + occ.replace(" ","_") + '>'
+                line = triple(aspoPlaceHolder,
+                              schemaCoords.prefix + 'hasOccupation',
+                              occupationPlaceHolder) + closeLine
+                output.write(line)
+                line = triple(occupationPlaceHolder,
+                              nsCoords.prefix + 'type',
+                              schemaCoords.prefix + 'Occupation') + closeLine
+                output.write(line)
+                line = triple(occupationPlaceHolder,
+                              rdfsCoords.prefix + 'label',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+
+            if row['avo 1'] != '':
+                avo1 = '<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/' + id_aspo + "/avo1>"
+                line = triple(aspoPlaceHolder,
+                              schemaCoords.prefix + 'relatedTo',
+                              avo1) + closeLine
+                output.write(line)
+                line = triple(avo1,
+                              nsCoords.prefix + 'type',
+                              foafCoords.prefix + 'Person') + closeLine
+                output.write(line)
+                line = triple(avo1,
+                              rdfsCoords.prefix + 'label',
+                              '\"' + row['avo 1'] + '\"') + closeLine
+                output.write(line)
+
+            if row['avo 2'] != '':
+                avo2 = '<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/' + id_aspo + "/avo2>"
+                line = triple(aspoPlaceHolder,
+                              schemaCoords.prefix + 'relatedTo',
+                              avo2) + closeLine
+                output.write(line)
+                line = triple(avo2,
+                              nsCoords.prefix + 'type',
+                              foafCoords.prefix + 'Person') + closeLine
+                output.write(line)
+                line = triple(avo2,
+                              rdfsCoords.prefix + 'label',
+                              '\"' + row['avo 2'] + '\"') + closeLine
+                output.write(line)
+
+            if row['Qualifica'] != '':
+                #Remove all white-space characters:
+                txt = row['Qualifica']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", " ", x)
+                line = triple(aspoPlaceHolder,
+                              schemaCoords.prefix + 'honorificPrefix',
+                              '\"' + y + '\"') + closeLine
+                output.write(line)
+
+            #if row['place_occupation_Qualifica'] != '':
+                #Remove all white-space characters:
+            #    txt = row['place_occupation_Qualifica']
+            #    x = re.sub("\n", " ", txt)
+            #    y = re.sub("\s\s", "", x)
+            #    line = triple(aspoPlaceHolder,
+            #                  schemaCoords.prefix + 'workLocation',
+            #                  '\"' + row['place_occupation_Qualifica'].replace('\\','\\\\').replace('"','\\"') + '\"') + closeLine
+            #    output.write(line)
+
+            if row['biogHist p'] != '':
+                #Remove all white-space characters:
+                txt = row['biogHist p']
+                x = re.sub("\n", " ", txt)
+                y = re.sub("\s\s", " ", x)
+                note = re.sub("\"", "", x)
+                line = triple(aspoPlaceHolder,
+                              cidocCoords.prefix + 'P3_has_note',
+                              '\"' + note + '\"') + closeLine
+                output.write(line)
+
+        output.write('\n')
+        #
+        #
+        # Limit number of entries processed (if desired)
+        if (ii > max_entries):
+            break

+ 273 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_date.ipynb

@@ -0,0 +1,273 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "movedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P25i_moved_by>', 'mb:')\n",
+    "movedToCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P26_moved_to>', 'mt:')\n",
+    "movedFromCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P27_moved_from>', 'mf:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "onGoingTCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P81_ongoing_throughout>', 'gt:')\n",
+    "nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')\n",
+    "schemaCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')\n",
+    "# CIDOC Objects\n",
+    "moveCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E9_Move>', 'mv:', 'E9')\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "# New classes (subclasses of E7 Activity) - Exchange, Sending, Recive Letters\n",
+    "exchangeLettersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL1_Exchange_Letters>', 'el:', 'EL1')\n",
+    "sendLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL2_Send_Letter>', 'sl:', 'EL2')\n",
+    "receiveLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL3_Receive_Letter>', 'rl:', 'EL3')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedByCoords.prefix + ' ' + movedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedToCoords.prefix + ' ' + movedToCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedFromCoords.prefix + ' ' + movedFromCoords.uri + closeLine)     \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + moveCoords.prefix + ' ' + moveCoords.uri + closeLine) \n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + exchangeLettersCoords.prefix + ' ' + exchangeLettersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + sendLetterCoords.prefix + ' ' + sendLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + receiveLetterCoords.prefix + ' ' + receiveLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + onGoingTCoords.prefix + ' ' + onGoingTCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + nsCoords.prefix + ' ' + nsCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_date.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Evento send letter\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \">\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \">\"\n",
+    "\n",
+    "        # Data invio\n",
+    "        if(row['data_inizio'] != ''):\n",
+    "            e52PplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + timeSpanCoords.code + \">\"\n",
+    "            line = triple(el2placeHolder, e52PplaceHolder, '\\\"'+ row['data_inizio'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        if(row['data_fine'] != ''):\n",
+    "            e52AplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + timeSpanCoords.code + \">\"\n",
+    "            line = triple(el3placeHolder, e52AplaceHolder, '\\\"' + row['data_fine'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 230 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_eac.ipynb

@@ -0,0 +1,230 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "noteCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3_has_note>', 'nt:')\n",
+    "subClassOfCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#subClassOf>', 'so:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "groupCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E74_Group>', 'gp:', 'E74')\n",
+    "legalBodyCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E40_Legal_Body>', 'ly:', 'E40')\n",
+    "stringCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E62_String>', 'st:', 'E62')\n",
+    "actorCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E39_Actor>', 'ac:', 'E39')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + noteCoords.prefix + ' ' + noteCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + actorCoords.prefix + ' ' + actorCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + groupCoords.prefix + ' ' + groupCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + legalBodyCoords.prefix + ' ' + legalBodyCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + stringCoords.prefix + ' ' + stringCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + subClassOfCoords.prefix + ' ' + subClassOfCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'eacAuth03'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "            \n",
+    "        # Add by FS Person \n",
+    "        # <URL dell'archivio di stato alla persona/gruppo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E39_Actor> .\n",
+    "        actorplaceHolder = personAuthCoords.prefix + row[\"recordId\"].replace('IT-ASPO-AU00003-','')\n",
+    "        # <URL dell'archivio di stato alla persona/gruppo> <http://www.w3.org/2000/01/rdf-schema#label> \"Pippo Pandolfi\"\n",
+    "        nome_actor = row[\"nameEntry@normal\"].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')\n",
+    "        line = triple(actorplaceHolder, labelCoords.prefix, '\\\"' + nome_actor.strip() + '\\\"') +  closeLine\n",
+    "        output.write(line)\n",
+    "        # <URL dell'archivio di stato alla persona/gruppo> <has note> \"e62placeHolder:\"\n",
+    "        e62placeHolder = \"<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/\" + row[\"recordId\"] + '/' + stringCoords.code + \">\"\n",
+    "        line = triple(actorplaceHolder, noteCoords.prefix, e62placeHolder) +  closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e62placeHolder, hasTypeCoords.prefix, stringCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e62placeHolder, labelCoords.prefix, '\\\"Fonte: Archivio di Stato di Prato - Fondo Datini \\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        # If the entityType is 'person' the CIDOC class is E21 Person\n",
+    "        if(row['entityType'] == 'person'):\n",
+    "            line = triple(actorplaceHolder, hasTypeCoords.prefix, personCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "        # If the entityType is 'corporateBody' the CIDOC class is E74 Group\n",
+    "        if(row['entityType'] == 'corporateBody'):\n",
+    "            line = triple(actorplaceHolder, hasTypeCoords.prefix, groupCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "        # If the entityType is 'family' the CIDOC class is E74 Group\n",
+    "        if(row['entityType'] == 'family'):\n",
+    "            line = triple(actorplaceHolder, hasTypeCoords.prefix, groupCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 227 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_file.ipynb

@@ -0,0 +1,227 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 25,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "# Utilities to handle character encodings\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 26,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 27,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 28,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 29,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 30,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'file'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasTypeCoords.prefix, manMadeObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(datiniCoords.prefix + row['id'], labelCoords.prefix, '\\\"Documento fisico: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e73placeHolder =  \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\" \n",
+    "        line = triple(datiniCoords.prefix + row['id'], carriesCoords.prefix, e73placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, hasTypeCoords.prefix, informationObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, labelCoords.prefix, '\\\"Contenuto informativo: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        \n",
+    "        # If the 'titolo_aspo' property is not empty for the given entry, write down title-related triples\n",
+    "        if(row['titolo_aspo'] != 'None'):\n",
+    "            e35placeHolder1 = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + titleCoords.code + \">\"\n",
+    "            line = triple(e73placeHolder, identifiedByCoords.prefix, e35placeHolder1) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, hasTypeCoords.prefix, titleCoords.prefix) +  closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, labelCoords.prefix, '\\\"' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        #\n",
+    "        # Triplify the 'segnatura' -- should exist for every entry\n",
+    "        if(row['segnatura_parent'] != ''):\n",
+    "            e42placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + identifierCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], identifiedByCoords.prefix, e42placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e42placeHolder, hasTypeCoords.prefix, identifierCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e42placeHolder, labelCoords.prefix, '\\\"Segnatura: Fondo Datini, ' + row['segnatura_parent'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        \n",
+    "        if(row['tipologia'] != ''):\n",
+    "            tipologie = []\n",
+    "            pipe = \"|\" \n",
+    "            if pipe in row['tipologia']:\n",
+    "                tipologie = row['tipologia'].split('|')\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + tipologie.replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "            else:\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)    \n",
+    "        \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.7.3 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 221 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item.ipynb

@@ -0,0 +1,221 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 25,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 26,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 27,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# Added by FS CIDOC properties for person\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "# Added by FS CIDOC entity\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 28,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 29,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 30,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasTypeCoords.prefix, manMadeObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(datiniCoords.prefix + row['id'], labelCoords.prefix, '\\\"Documento fisico: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "        line = triple(datiniCoords.prefix + row['id'], carriesCoords.prefix, e73placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, hasTypeCoords.prefix, informationObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, labelCoords.prefix, '\\\"Contenuto informativo: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line) \n",
+    "             \n",
+    "        if(row['tipologia'] != ''):\n",
+    "            tipologie = []\n",
+    "            pipe = \"|\" \n",
+    "            if pipe in row['tipologia']:\n",
+    "                tipologie = row['tipologia'].split('|')\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + tipologie.replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "            else:\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 249 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_creation.ipynb

@@ -0,0 +1,249 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 31,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 32,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 33,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "# CIDOC Objects\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 34,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 35,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)   \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 36,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_creation.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Evento creazione\n",
+    "        if(row['tipologia'] != 'carteggio'):\n",
+    "            e22placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \">\"\n",
+    "            e65placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \">\"\n",
+    "            e65FplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \"F>\"\n",
+    "            line = triple(e22placeHolder, wasBroughtCoords.prefix, e65placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e65placeHolder, hasTypeCoords.prefix, creationCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e65placeHolder, labelCoords.prefix, '\\\"Inizio creazione di ' + row['titolo_aspo'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e65placeHolder, hasTypePCoords.prefix, '\\\"Inizio\\\"^^xsd:string') + closeLine\n",
+    "            output.write(line)\n",
+    "            e65FplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \"F>\"\n",
+    "            line = triple(e22placeHolder, wasBroughtCoords.prefix, e65FplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e65FplaceHolder, hasTypeCoords.prefix, creationCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e65FplaceHolder, labelCoords.prefix, '\\\"Fine creazione di ' + row['titolo_aspo'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e65FplaceHolder, hasTypePCoords.prefix, '\\\"Fine\\\"^^xsd:string') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "            #Luogo creazione\n",
+    "            if(row['luogo_luogo'] != ''):\n",
+    "                auth_luogo = row['luogo_luogo']\n",
+    "                authcode_luogo = re.sub('{luogo: .* ', '', auth_luogo)\n",
+    "                authcodeprefix_luogo = authcode_luogo.replace('\"', '').replace('}', '').strip()\n",
+    "                e53placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + placeCoords.code + \">\"\n",
+    "                line = triple(e65placeHolder, tookPlaceCoords.prefix, e53placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e65FplaceHolder, tookPlaceCoords.prefix, e53placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e53placeHolder, hasTypeCoords.prefix, placeCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                geogname = row['luogo_luogo'].replace('{luogo:', '').replace(',', '').replace('authID:', '')\n",
+    "                place = re.sub('}', '', geogname).strip()\n",
+    "                line = triple(e53placeHolder, labelCoords.prefix, '\\\"' + place + '\\\"') + closeLine\n",
+    "                output.write(line)          \n",
+    "                                \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 286 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_creation_actor.ipynb

@@ -0,0 +1,286 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "# CIDOC Objects\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "pcarriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/PC14_carried_out_by>', 'cy:', 'PC14')\n",
+    "roleOfCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14.1_in_the_role_of>', 'ro:')\n",
+    "hasDomainCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P01_has_domain>', 'hd:')\n",
+    "hasRangeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P02_has_range>', 'hr:')\n",
+    "actorCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E39_Actor>', 'ac:', 'E39')\n",
+    "hadParticipantCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P11_had_participant>', 'pt:')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)   \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasDomainCoords.prefix + ' ' + hasDomainCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + pcarriedByCoords.prefix + ' ' + pcarriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasRangeCoords.prefix + ' ' + hasRangeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + actorCoords.prefix + ' ' + actorCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hadParticipantCoords.prefix + ' ' + hadParticipantCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' +  roleOfCoords.prefix + ' ' +  roleOfCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_creation_actor.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Autore della creazione del documento\n",
+    "        if(row['tipologia'] != 'carteggio'):\n",
+    "            e65placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \">\"\n",
+    "            e65FplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \"F>\"\n",
+    "            e22placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \">\"        \n",
+    "            PC14placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + pcarriedByCoords.code + \">\"   \n",
+    "            E55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + pcarriedByCoords.code + \"_\" + typeCoords.code + \">\"       \n",
+    "            P11placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/P11\" + \">\"   \n",
+    "            P11E55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/P11\" + \"_\" + typeCoords.code + \">\"\n",
+    "            if(row['persona_tenutario'] != '' and row['tipologia'] != 'carteggio'):\n",
+    "                auth = row['persona_tenutario']\n",
+    "                authcode = re.sub('{\"nome\": .* ', '', auth)\n",
+    "                authcodeprefix= authcode.replace('IT-ASPO-AU00003-', '').replace('\"', '').replace('}', '').strip()\n",
+    "                e39placeHolder = personAuthCoords.prefix + authcodeprefix\n",
+    "                line = triple(e65placeHolder, hasDomainCoords.prefix, PC14placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e65FplaceHolder, hasDomainCoords.prefix, PC14placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, labelCoords.prefix, \"\\\"Responsabilità della creazione\\\"\") + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, hasTypeCoords.prefix, pcarriedByCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, hasRangeCoords.prefix, e39placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, roleOfCoords.prefix, E55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(E55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(E55placeHolder, labelCoords.prefix, \"\\\"Responsabile del documento\\\"\" ) + closeLine\n",
+    "                output.write(line)\n",
+    "            if(row['persona_mano'] != '' and row['tipologia'] != 'carteggio'):\n",
+    "                auth = row['persona_mano']\n",
+    "                authcode = re.sub('{\"nome\": .* ', '', auth)\n",
+    "                authcodeprefix= authcode.replace('IT-ASPO-AU00003-', '').replace('\"', '').replace('}', '').strip()\n",
+    "                e39placeHolder = personAuthCoords.prefix + authcodeprefix\n",
+    "                line = triple(e65placeHolder, hasDomainCoords.prefix, PC14placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e65FplaceHolder, hasDomainCoords.prefix, PC14placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, hasTypeCoords.prefix, pcarriedByCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, hasRangeCoords.prefix, e39placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(PC14placeHolder, roleOfCoords.prefix, E55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(E55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(E55placeHolder, labelCoords.prefix, \"\\\"Mano\\\"\" ) + closeLine\n",
+    "                output.write(line)   \n",
+    "            if(row['compagnia'] != '' and row['tipologia'] != 'carteggio'):\n",
+    "                auth = row['compagnia']\n",
+    "                authcode = re.sub('{nome: .* ', '', auth)\n",
+    "                authcodeprefix= authcode.replace('IT-ASPO-AU00003-', '').replace('\"', '').replace('}', '').strip()\n",
+    "                e39placeHolder = personAuthCoords.prefix + authcodeprefix\n",
+    "                line = triple(e65placeHolder, hadParticipantCoords.prefix, P11placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e65FplaceHolder, hadParticipantCoords.prefix, P11placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(P11placeHolder, hasRangeCoords.prefix, e39placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(P11placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(P11placeHolder, labelCoords.prefix, \"\\\"Compagnia\\\"\" ) + closeLine\n",
+    "                output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 257 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_creation_date.ipynb

@@ -0,0 +1,257 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "onGoingTCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P81_ongoing_throughout>', 'gt:')\n",
+    "nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')\n",
+    "schemaCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')\n",
+    "# CIDOC Objects\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)   \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + onGoingTCoords.prefix + ' ' + onGoingTCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + nsCoords.prefix + ' ' + nsCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_creation_date.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Periodo creazione\n",
+    "        if(row['tipologia'] != 'carteggio'):\n",
+    "            e65placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \">\"\n",
+    "            e65FplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \"F>\"\n",
+    "            e22placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \">\"        \n",
+    "            if(row['data_inizio'] != ''):            \n",
+    "                e52placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \"_\" + timeSpanCoords.code + \">\"\n",
+    "                line = triple(e65placeHolder, hasTimeSpanCoords.prefix, e52placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e52placeHolder, hasTypeCoords.prefix, timeSpanCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                #e55placeHolder = \"<\" + row['URL'] + \"_\" + timeSpanCoords.code + \"_ETI_E55>\"\n",
+    "                #line = triple(e52ETIplaceHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                #output.write(line)\n",
+    "                #line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "                #output.write(line)\n",
+    "                #line = triple(e52ETIplaceHolder, onGoingTCoords.prefix, '\\\"'+row['ETI'] +'\\\"^^rdfs:Literal') + closeLine\n",
+    "                #output.write(line)\n",
+    "                line = triple(e52placeHolder, labelCoords.prefix, '\\\"'+row['data_inizio'] +'\\\"') + closeLine\n",
+    "                output.write(line)\n",
+    "                #line = triple(e55placeHolder, labelCoords.prefix, '\\\"Estremo temporale inferiore\\\"') + closeLine\n",
+    "                #output.write(line)\n",
+    "\n",
+    "            if(row['data_fine'] != ''):\n",
+    "                e52FplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + creationCoords.code + \"_\" + timeSpanCoords.code + \"F>\"\n",
+    "                line = triple(e65FplaceHolder, hasTimeSpanCoords.prefix, e52FplaceHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                line = triple(e52FplaceHolder, hasTypeCoords.prefix, timeSpanCoords.prefix) + closeLine\n",
+    "                output.write(line)\n",
+    "                #e55placeHolder = \"<\" + row['URL'] + \"_\" + timeSpanCoords.code + \"_ETS_E55>\"\n",
+    "                #line = triple(e52ETSplaceHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                #output.write(line)\n",
+    "                #line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "                #output.write(line)\n",
+    "                #line = triple(e52ETSplaceHolder, onGoingTCoords.prefix, '\\\"'+row['ETS'] +'\\\"^^rdfs:Literal') + closeLine\n",
+    "                #output.write(line)\n",
+    "                line = triple(e52FplaceHolder, labelCoords.prefix, '\\\"'+row['data_fine'] +'\\\"') + closeLine\n",
+    "                output.write(line)\n",
+    "                #line = triple(e55placeHolder, labelCoords.prefix, '\\\"Estremo temporale superiore\\\"') + closeLine\n",
+    "                #output.write(line)\n",
+    "\n",
+    "            output.write('\\n')\n",
+    "            #\n",
+    "            #\n",
+    "            # Limit number of entries processed (if desired)\n",
+    "            if(ii>max_entries):\n",
+    "                break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 258 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange.ipynb

@@ -0,0 +1,258 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "subClassOfCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#subClassOf>', 'so:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "movedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P25i_moved_by>', 'mb:')\n",
+    "movedToCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P26_moved_to>', 'mt:')\n",
+    "movedFromCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P27_moved_from>', 'mf:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "# CIDOC Objects\n",
+    "moveCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E9_Move>', 'mv:', 'E9')\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "pcarriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/PC14_carried_out_by>', 'cy:')\n",
+    "\n",
+    "# New classes (subclasses of E7 Activity) - Exchange, Sending, Recive Letters\n",
+    "exchangeLettersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL1_Exchange_Letters>', 'el:', 'EL1')\n",
+    "sendLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL2_Send_Letter>', 'sl:', 'EL2')\n",
+    "receiveLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL3_Receive_Letter>', 'rl:', 'EL3')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedByCoords.prefix + ' ' + movedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedToCoords.prefix + ' ' + movedToCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedFromCoords.prefix + ' ' + movedFromCoords.uri + closeLine)     \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + moveCoords.prefix + ' ' + moveCoords.uri + closeLine) \n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + exchangeLettersCoords.prefix + ' ' + exchangeLettersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + sendLetterCoords.prefix + ' ' + sendLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + receiveLetterCoords.prefix + ' ' + receiveLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + subClassOfCoords.prefix + ' ' + subClassOfCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_exchange.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue   \n",
+    "\n",
+    "        el1placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + exchangeLettersCoords.code + \">\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \">\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \">\"\n",
+    "        \n",
+    "        if(row['luogo_partenza'] != '' and row['luogo_arrivo'] != ''):\n",
+    "            line = triple(exchangeLettersCoords.prefix, labelCoords.prefix, '\\\"Exchange of letters\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(sendLetterCoords.prefix, labelCoords.prefix, '\\\"Send letter\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(receiveLetterCoords.prefix, labelCoords.prefix, '\\\"Receive letter\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el2placeHolder, subClassOfCoords.prefix, el1placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el3placeHolder, subClassOfCoords.prefix, el1placeHolder) + closeLine\n",
+    "            output.write(line)    \n",
+    "            line = triple(datiniCoords.prefix + row['id'], movedByCoords.prefix, el1placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el1placeHolder, labelCoords.prefix, '\\\"' + row['tipologia'] + ': ' + row['titolo_aspo'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el1placeHolder, hasTypeCoords.prefix, exchangeLettersCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el2placeHolder, labelCoords.prefix, '\\\"Invio\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el2placeHolder, hasTypeCoords.prefix, sendLetterCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el3placeHolder, labelCoords.prefix, '\\\"Ricezione\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(el3placeHolder, hasTypeCoords.prefix, receiveLetterCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 273 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_date.ipynb

@@ -0,0 +1,273 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "movedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P25i_moved_by>', 'mb:')\n",
+    "movedToCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P26_moved_to>', 'mt:')\n",
+    "movedFromCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P27_moved_from>', 'mf:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "onGoingTCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P81_ongoing_throughout>', 'gt:')\n",
+    "nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')\n",
+    "schemaCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')\n",
+    "# CIDOC Objects\n",
+    "moveCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E9_Move>', 'mv:', 'E9')\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "# New classes (subclasses of E7 Activity) - Exchange, Sending, Recive Letters\n",
+    "exchangeLettersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL1_Exchange_Letters>', 'el:', 'EL1')\n",
+    "sendLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL2_Send_Letter>', 'sl:', 'EL2')\n",
+    "receiveLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL3_Receive_Letter>', 'rl:', 'EL3')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedByCoords.prefix + ' ' + movedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedToCoords.prefix + ' ' + movedToCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedFromCoords.prefix + ' ' + movedFromCoords.uri + closeLine)     \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + moveCoords.prefix + ' ' + moveCoords.uri + closeLine) \n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + exchangeLettersCoords.prefix + ' ' + exchangeLettersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + sendLetterCoords.prefix + ' ' + sendLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + receiveLetterCoords.prefix + ' ' + receiveLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + onGoingTCoords.prefix + ' ' + onGoingTCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + nsCoords.prefix + ' ' + nsCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_exchange_date.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Evento send letter\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \">\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \">\"\n",
+    "\n",
+    "        # Data invio\n",
+    "        if(row['data_inizio'] != ''):\n",
+    "            e52PplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + timeSpanCoords.code + \">\"\n",
+    "            line = triple(el2placeHolder, hasTimeSpanCoords.prefix, e52PplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e52PplaceHolder, hasTypeCoords.prefix, timeSpanCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e52PplaceHolder, labelCoords.prefix, '\\\"'+ row['data_inizio'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            #e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + timeSpanCoords.code + \"/ETI>\"\n",
+    "            #line = triple(e52PplaceHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "            #output.write(line)\n",
+    "            #line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "            #output.write(line)\n",
+    "            #line = triple(e52PplaceHolder, onGoingTCoords.prefix, '\\\"'+row['data_inizio'] +'\\\"^^rdfs:Literal') + closeLine\n",
+    "            #output.write(line)\n",
+    "            #line = triple(e55placeHolder, labelCoords.prefix, '\\\"Estremo temporale inferiore\\\"') + closeLine\n",
+    "            #output.write(line)\n",
+    "\n",
+    "\n",
+    "        if(row['data_fine'] != ''):\n",
+    "            e52AplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + timeSpanCoords.code + \">\"\n",
+    "            line = triple(el3placeHolder, hasTimeSpanCoords.prefix, e52AplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e52AplaceHolder, hasTypeCoords.prefix, timeSpanCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e52AplaceHolder, labelCoords.prefix, '\\\"' + row['data_fine'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            #e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + timeSpanCoords.code + \"/ETS>\"\n",
+    "            #line = triple(e52AplaceHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "            #output.write(line)\n",
+    "            #line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "            #output.write(line)\n",
+    "            #line = triple(e52AplaceHolder, onGoingTCoords.prefix, '\\\"'+row['data_fine'] +'\\\"^^rdfs:Literal') + closeLine\n",
+    "            #output.write(line)\n",
+    "            #line = triple(e55placeHolder, labelCoords.prefix, '\\\"Estremo temporale superiore\\\"') + closeLine\n",
+    "            #output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 262 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_place.ipynb

@@ -0,0 +1,262 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "subClassOfCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#subClassOf>', 'so:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasDomainCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P01_has_domain>', 'hd:')\n",
+    "hasRangeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P02_has_range>', 'hr:')\n",
+    "movedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P25i_moved_by>', 'mb:')\n",
+    "movedToCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P26_moved_to>', 'mt:')\n",
+    "movedFromCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P27_moved_from>', 'mf:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "# CIDOC Objects\n",
+    "moveCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E9_Move>', 'mv:', 'E9')\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "pcarriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/PC14_carried_out_by>', 'cy:', 'PC14')\n",
+    "\n",
+    "# New classes (subclasses of E7 Activity) - Exchange, Sending, Recive Letters\n",
+    "exchangeLettersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL1_Exchange_Letters>', 'el:', 'EL1')\n",
+    "sendLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL2_Send_Letter>', 'sl:', 'EL2')\n",
+    "receiveLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL3_Receive_Letter>', 'rl:', 'EL3')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedByCoords.prefix + ' ' + movedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedToCoords.prefix + ' ' + movedToCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedFromCoords.prefix + ' ' + movedFromCoords.uri + closeLine)     \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + moveCoords.prefix + ' ' + moveCoords.uri + closeLine) \n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + exchangeLettersCoords.prefix + ' ' + exchangeLettersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + sendLetterCoords.prefix + ' ' + sendLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + receiveLetterCoords.prefix + ' ' + receiveLetterCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_exchange_place.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Evento exchange letters\n",
+    "        el1placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + exchangeLettersCoords.code + \">\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \">\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \">\"\n",
+    "          \n",
+    "        if(row['luogo_partenza'] != '' and row['luogo_arrivo'] != ''):\n",
+    "            partenza = row['luogo_partenza'].replace('{luogo:', '').replace(',', '').replace('authID:', '')\n",
+    "            place_partenza = re.sub('IT-ASPO-GEO0001-[0-9]*}', '', partenza).strip()\n",
+    "            arrivo = row['luogo_arrivo'].replace('{luogo:', '').replace(',', '').replace('authID:', '')\n",
+    "            place_arrivo = re.sub('IT-ASPO-GEO0001-[0-9]*}', '', arrivo).strip()\n",
+    "            auth_partenza = row['luogo_partenza']\n",
+    "            authcode_partenza = re.sub('{luogo: .* ', '', auth_partenza)\n",
+    "            authcodeprefix_partenza = authcode_partenza.replace('IT-ASPO-GEO0001-', '').replace('\"', '').replace('}', '').strip()\n",
+    "            auth_arrivo = row['luogo_arrivo']\n",
+    "            authcode_arrivo = re.sub('{luogo: .* ', '', auth_arrivo)\n",
+    "            authcodeprefix_arrivo = authcode_arrivo.replace('IT-ASPO-GEO0001-', '').replace('\"', '').replace('}', '').strip()\n",
+    "            #Luogo partenza\n",
+    "            e53placeHolder = \"<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-GEO0001-\" + authcodeprefix_partenza +  \">\"\n",
+    "            line = triple(el2placeHolder, movedFromCoords.prefix, e53placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e53placeHolder, hasTypeCoords.prefix, placeCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e53placeHolder, labelCoords.prefix, '\\\"' + place_partenza + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            #Luogo arrivo\n",
+    "            e53placeHolder = \"<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-GEO0001-\" + authcodeprefix_arrivo +  \">\"\n",
+    "            line = triple(el3placeHolder, movedToCoords.prefix, e53placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e53placeHolder, hasTypeCoords.prefix, placeCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e53placeHolder, labelCoords.prefix, '\\\"' + place_arrivo + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 263 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_receiver.ipynb

@@ -0,0 +1,263 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "subClassOfCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#subClassOf>', 'so:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "roleOfCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14.1_in_the_role_of>', 'ro:')\n",
+    "hasDomainCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P01_has_domain>', 'hd:')\n",
+    "hasRangeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P02_has_range>', 'hr:')\n",
+    "movedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P25i_moved_by>', 'mb:')\n",
+    "movedToCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P26_moved_to>', 'mt:')\n",
+    "movedFromCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P27_moved_from>', 'mf:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "# CIDOC Objects\n",
+    "moveCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E9_Move>', 'mv:', 'E9')\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "actorCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E39_Actor>', 'ac:', 'E39')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "pcarriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/PC14_carried_out_by>', 'cy:', 'PC14')\n",
+    "\n",
+    "# New classes (subclasses of E7 Activity) - Exchange, Sending, Recive Letters\n",
+    "exchangeLettersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL1_Exchange_Letters>', 'el:', 'EL1')\n",
+    "sendLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL2_Send_Letter>', 'sl:', 'EL2')\n",
+    "receiveLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL3_Receive_Letter>', 'rl:', 'EL3')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedByCoords.prefix + ' ' + movedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedToCoords.prefix + ' ' + movedToCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedFromCoords.prefix + ' ' + movedFromCoords.uri + closeLine)     \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + moveCoords.prefix + ' ' + moveCoords.uri + closeLine) \n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + exchangeLettersCoords.prefix + ' ' + exchangeLettersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + sendLetterCoords.prefix + ' ' + sendLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + receiveLetterCoords.prefix + ' ' + receiveLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + roleOfCoords.prefix + ' ' + roleOfCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasDomainCoords.prefix + ' ' + hasDomainCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + pcarriedByCoords.prefix + ' ' + pcarriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasRangeCoords.prefix + ' ' + hasRangeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + actorCoords.prefix + ' ' + actorCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_exchange_receiver.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Evento exchange letters\n",
+    "        el1placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + exchangeLettersCoords.code + \">\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \">\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \">\"\n",
+    "        PC14splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + pcarriedByCoords.code + \">\"   \n",
+    "        PC14rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + pcarriedByCoords.code + \">\"   \n",
+    "        E55splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + typeCoords.code + \">\"       \n",
+    "        E55rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + typeCoords.code + \">\"\n",
+    "    \n",
+    "        if(row['persona_destinatario'] != ''):\n",
+    "            destinatario = row['persona_destinatario'].replace('{\"nome\":', '').replace(',', '').replace('\"authID\":', '')\n",
+    "            name_destinatario = re.sub('IT-ASPO-AU00003-[0-9].*}', '', destinatario).replace('\"', '').replace('}', '').strip()\n",
+    "            auth = row['persona_destinatario']\n",
+    "            authcode = re.sub('{\"nome\": .* ', '', auth)\n",
+    "            authcodeprefix= authcode.replace('IT-ASPO-AU00003-', '').replace('\"', '').replace('}', '').strip()\n",
+    "            actorplaceHolder = personAuthCoords.prefix + authcodeprefix        \n",
+    "            line = triple(el3placeHolder, hasDomainCoords.prefix, PC14rplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14rplaceHolder, hasTypeCoords.prefix, pcarriedByCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14rplaceHolder, labelCoords.prefix, \"\\\"\" + name_destinatario + \" nel ruolo di destinatario\" + \"\\\"\" ) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14rplaceHolder, roleOfCoords.prefix, E55rplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(E55rplaceHolder, labelCoords.prefix, \"\\\"Destinatario\\\"\" ) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14rplaceHolder, hasRangeCoords.prefix, actorplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 262 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_event_exchange_sender.ipynb

@@ -0,0 +1,262 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json\n",
+    "import re"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3 Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "subClassOfCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#subClassOf>', 'so:')\n",
+    "# CIDOC Predicates\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasTimeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span>', 'hs:')\n",
+    "tookPlaceCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P7_took_place_at>', 'tk:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "roleOfCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14.1_in_the_role_of>', 'ro:')\n",
+    "hasDomainCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P01_has_domain>', 'hd:')\n",
+    "hasRangeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P02_has_range>', 'hr:')\n",
+    "movedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P25i_moved_by>', 'mb:')\n",
+    "movedToCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P26_moved_to>', 'mt:')\n",
+    "movedFromCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P27_moved_from>', 'mf:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "hasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108_has_produced>', 'hp:')\n",
+    "wasProducedCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P108i_was_produced_by>', 'wp:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "# CIDOC Objects\n",
+    "moveCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E9_Move>', 'mv:', 'E9')\n",
+    "productionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E12_Production>', 'pr:', 'E12')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "#placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "timeSpanCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span>', 'ts:', 'E52')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "pcarriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/PC14_carried_out_by>', 'cy:', 'PC14')\n",
+    "\n",
+    "# New classes (subclasses of E7 Activity) - Exchange, Sending, Recive Letters\n",
+    "exchangeLettersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL1_Exchange_Letters>', 'el:', 'EL1')\n",
+    "sendLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL2_Send_Letter>', 'sl:', 'EL2')\n",
+    "receiveLetterCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/EL3_Receive_Letter>', 'rl:', 'EL3')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTimeSpanCoords.prefix + ' ' + hasTimeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + tookPlaceCoords.prefix + ' ' + tookPlaceCoords.uri + closeLine)        \n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedByCoords.prefix + ' ' + movedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedToCoords.prefix + ' ' + movedToCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + movedFromCoords.prefix + ' ' + movedFromCoords.uri + closeLine)     \n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasProducedCoords.prefix + ' ' + hasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasProducedCoords.prefix + ' ' + wasProducedCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + moveCoords.prefix + ' ' + moveCoords.uri + closeLine) \n",
+    "    output.write('@prefix ' + productionCoords.prefix + ' ' + productionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + timeSpanCoords.prefix + ' ' + timeSpanCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + creationCoords.prefix + ' ' + creationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + exchangeLettersCoords.prefix + ' ' + exchangeLettersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + sendLetterCoords.prefix + ' ' + sendLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + receiveLetterCoords.prefix + ' ' + receiveLetterCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + roleOfCoords.prefix + ' ' + roleOfCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasDomainCoords.prefix + ' ' + hasDomainCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + pcarriedByCoords.prefix + ' ' + pcarriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasRangeCoords.prefix + ' ' + hasRangeCoords.uri + closeLine)\n",
+    "    \n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_event_exchange_sender.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        #Evento exchange letters\n",
+    "        el1placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + exchangeLettersCoords.code + \">\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \">\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \">\"\n",
+    "        PC14splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + pcarriedByCoords.code + \">\"   \n",
+    "        PC14rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + pcarriedByCoords.code + \">\"   \n",
+    "        E55splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + typeCoords.code + \">\"       \n",
+    "        E55rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + typeCoords.code + \">\"\n",
+    "    \n",
+    "        if(row['persona_mittente'] != ''):\n",
+    "            mittente = row['persona_mittente'].replace('{\"nome\":', '').replace(',', '').replace('\"authID\":', '')\n",
+    "            name_mittente = re.sub('IT-ASPO-AU00003-[0-9].*}', '', mittente).replace('\"', '').replace('}', '').strip()\n",
+    "            auth = row['persona_mittente']\n",
+    "            authcode = re.sub('{\"nome\": .* ', '', auth)\n",
+    "            authcodeprefix= authcode.replace('IT-ASPO-AU00003-', '').replace('\"', '').replace('}', '').strip()\n",
+    "            actorplaceHolder = personAuthCoords.prefix + authcodeprefix        \n",
+    "            line = triple(el2placeHolder, hasDomainCoords.prefix, PC14splaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14splaceHolder, hasTypeCoords.prefix, pcarriedByCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14splaceHolder, labelCoords.prefix, \"\\\"\" + name_mittente + \" nel ruolo di mittente\" + \"\\\"\" ) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14splaceHolder, roleOfCoords.prefix, E55splaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(E55splaceHolder, labelCoords.prefix, \"\\\"Mittente\\\"\" ) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(PC14splaceHolder, hasRangeCoords.prefix, actorplaceHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 225 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_extent.ipynb

@@ -0,0 +1,225 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "hasDimensionsCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P43_has_dimension>', 'hd:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "dimensionsCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E54_Dimension>', 'dm:', 'E54')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasDimensionsCoords.prefix + ' ' + hasDimensionsCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + dimensionsCoords.prefix + ' ' + dimensionsCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_extent.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # NUMERO DI CARTE - CONSISTENZA\n",
+    "        if(row['numero'] != ''):\n",
+    "            e54placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + dimensionsCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], hasDimensionsCoords.prefix, e54placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e54placeHolder, hasTypeCoords.prefix, dimensionsCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e54placeHolder, labelCoords.prefix, '\\\"Consistenza: carte ' + row['numero'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        \n",
+    "        if(row['extent'] != ''):\n",
+    "            e54placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + dimensionsCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], hasDimensionsCoords.prefix, e54placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e54placeHolder, hasTypeCoords.prefix, dimensionsCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e54placeHolder, labelCoords.prefix, '\\\"Consistenza: carte ' + row['extent'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        \n",
+    "        if(row['consistenza'] != ''):\n",
+    "            e54placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + dimensionsCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], hasDimensionsCoords.prefix, e54placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e54placeHolder, hasTypeCoords.prefix, dimensionsCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e54placeHolder, labelCoords.prefix, '\\\"Consistenza: carte ' + row['consistenza'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 215 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_note.ipynb

@@ -0,0 +1,215 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasNoteCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3_has_note>', 'no:')\n",
+    "hasTypeNCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3.1_has_type>', 'tn:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "stringCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E62_String>', 'sr:', 'E62')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasNoteCoords.prefix + ' ' + hasNoteCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeNCoords.prefix + ' ' + hasTypeNCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + stringCoords.prefix + ' ' + stringCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_note.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Physdesc\n",
+    "        if(row['nota'] != ''):\n",
+    "            e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "            e62placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/E73_\" + stringCoords.code + \">\"\n",
+    "            line = triple(e73placeHolder, hasNoteCoords.prefix, e62placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e62placeHolder, labelCoords.prefix, '\\\"' + row['nota'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e62placeHolder, hasTypeCoords.prefix, stringCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/E73_\" + stringCoords.code + \"_\" + typeCoords.code + \">\"\n",
+    "            line = triple(e62placeHolder, hasTypeNCoords.prefix, e55placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, labelCoords.prefix, '\\\"Nota contenuto informativo\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 205 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_permanent_location.ipynb

@@ -0,0 +1,205 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 18,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 20,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "hasCurrentPermanentLocationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P54_has_current_permanent_location>', 'ap:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 21,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 22,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasCurrentPermanentLocationCoords.prefix + ' ' + hasCurrentPermanentLocationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 23,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_permanent_location.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        \n",
+    "        E53placeHolder = '<http://www.archiviodistato.prato.it>'\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasCurrentPermanentLocationCoords.prefix, E53placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(E53placeHolder, hasTypeCoords.prefix, placeCoords.prefix ) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(E53placeHolder, labelCoords.prefix, \"\\\"Archivio di Stato di Prato\\\"\") + closeLine\n",
+    "        output.write(line)\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 214 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_phydesc.ipynb

@@ -0,0 +1,214 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "hasNoteCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3_has_note>', 'no:')\n",
+    "hasTypeNCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3.1_has_type>', 'tn:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "stringCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E62_String>', 'sr:', 'E62')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasNoteCoords.prefix + ' ' + hasNoteCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeNCoords.prefix + ' ' + hasTypeNCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + stringCoords.prefix + ' ' + stringCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_physdesc.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Physdesc\n",
+    "        if(row['descrizione_fisica'] != ''):\n",
+    "            e62placeHolder= \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/E22_\" + stringCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], hasNoteCoords.prefix, e62placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e62placeHolder, labelCoords.prefix, '\\\"' + row['descrizione_fisica'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e62placeHolder, hasTypeCoords.prefix, stringCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/E22_\" + stringCoords.code + \"_\" + typeCoords.code + \">\"\n",
+    "            line = triple(e62placeHolder, hasTypeNCoords.prefix, e55placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, labelCoords.prefix, '\\\"Nota descrizione fisica\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 208 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_physfacet.ipynb

@@ -0,0 +1,208 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "consistCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P45_consist_of>', 'cf:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')\n",
+    "materialCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E57_Material>', 'mt:', 'E57')"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + consistCoords.prefix + ' ' + consistCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + materialCoords.prefix + ' ' + materialCoords.uri + closeLine)\n",
+    "   \n",
+    "    output.write('\\n')\n"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_physfacet.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Physfacet - supporto\n",
+    "        if(row['supporto'] != ''):\n",
+    "            e57placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + materialCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], consistCoords.prefix, e57placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e57placeHolder, labelCoords.prefix, '\\\"' + row['supporto'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e57placeHolder, hasTypeCoords.prefix, materialCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ],
+   "outputs": [],
+   "metadata": {
+    "tags": []
+   }
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "name": "python3",
+   "display_name": "Python 3.9.0 64-bit"
+  },
+  "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  },
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 216 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_phystech.ipynb

@@ -0,0 +1,216 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "hasConditionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P44_has_condition>', 'hc:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "conditionCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E3_Condition_State>', 'cs:', 'E3')\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "# Added by FS CIDOC entity\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasConditionCoords.prefix + ' ' + hasConditionCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + conditionCoords.prefix + ' ' + conditionCoords.uri + closeLine)\n",
+    "    \n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_phystech.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # STATO DI CONSERVAZIONE\n",
+    "        if(row['conservazione'] != ''):\n",
+    "            e3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + conditionCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], hasConditionCoords.prefix,  e3placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e3placeHolder, hasTypeCoords.prefix, conditionCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e3placeHolder, labelCoords.prefix, '\\\"Stato di conservazione\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + conditionCoords.code + \"_\" + typeCoords.code + \">\"  \n",
+    "            line = triple(e3placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, labelCoords.prefix, '\\\"'+ row['conservazione'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 207 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_repository.ipynb

@@ -0,0 +1,207 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# Added by FS CIDOC properties for person\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "hasCurrentPermanentLocationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P54_has_current_permanent_location>', 'ap:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "placeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E53_Place>', 'pl:', 'E53')\n",
+    "# Added by FS CIDOC entity\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasCurrentPermanentLocationCoords.prefix + ' ' + hasCurrentPermanentLocationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + placeCoords.prefix + ' ' + placeCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_permanent_location.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?\n",
+    "        E53placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + placeCoords.code + \">\"\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasCurrentPermanentLocationCoords.prefix, E53placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(E53placeHolder, hasTypeCoords.prefix, placeCoords.prefix ) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(E53placeHolder, labelCoords.prefix, \"\\\"Archivio di Stato di Prato\\\"\") + closeLine\n",
+    "        output.write(line)\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 218 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_scopecontent.ipynb

@@ -0,0 +1,218 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "refersCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P67_refers_to>', 'rt:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "refersHasTypeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P67.1_type>', 'rh:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "entityCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E1_Entity>', 'ey:', 'E1')\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + refersCoords.prefix + ' ' + refersCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + entityCoords.prefix + ' ' + entityCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + refersHasTypeCoords.prefix + ' ' + refersHasTypeCoords.uri + closeLine)\n",
+    "   \n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_scopecontent.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Scopecontent\n",
+    "        if(row['scope-content_body'] != ''):\n",
+    "            e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "            e1placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/E73_\" + entityCoords.code + \">\"\n",
+    "            line = triple(e73placeHolder, refersCoords.prefix, e1placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e1placeHolder, hasTypeCoords.prefix, entityCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e1placeHolder, labelCoords.prefix, '\\\"' + row['scope-content_body'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + entityCoords.code + \"_\" + typeCoords.code + \">\"\n",
+    "            line = triple(e1placeHolder, refersHasTypeCoords.prefix, e55placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, labelCoords.prefix, '\\\"Scope and Content\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 213 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_segnatura.ipynb

@@ -0,0 +1,213 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# Added by FS CIDOC properties for person\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "# Added by FS CIDOC entity\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_segnatura.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        segnatura = ''\n",
+    "        if(row['segnatura_registri_1'] != ''):\n",
+    "            segnatura = row['segnatura_registri_1']\n",
+    "            if(row['segnatura_registri_2'] != ''):\n",
+    "                segnatura = segnatura + '.' + row['segnatura_registri_2']\n",
+    "        if(row['segnatura_busta'] != ''):\n",
+    "            segnatura = row['segnatura_busta']\n",
+    "            if(row['segnatura_inserto'] != ''):\n",
+    "                segnatura = segnatura + '.' + row['segnatura_inserto']\n",
+    "                if(row['segnatura_codice'] != ''):\n",
+    "                    segnatura = segnatura + '.' + row['segnatura_codice']\n",
+    "        if(segnatura != ''):\n",
+    "            e42placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + identifierCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], identifiedByCoords.prefix, e42placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e42placeHolder, hasTypeCoords.prefix, identifierCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e42placeHolder, labelCoords.prefix, '\\\"Segnatura: Fondo Datini, ' + segnatura + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "    \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.7.3 64-bit",
+   "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.7.3"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 215 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_item_title.ipynb

@@ -0,0 +1,215 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# Added by FS CIDOC properties for person\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "# Added by FS CIDOC entity\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'item'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_title.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # If the 'titolo_aspo' property is not empty for the given entry, write down title-related triples\n",
+    "        e37placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "      \n",
+    "        if(row['titolo_aspo'] != 'None' and row['titolo_aspo'] != ''):\n",
+    "            e35placeHolder1 = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + titleCoords.code + \">\"\n",
+    "            line = triple(e37placeHolder, identifiedByCoords.prefix, e35placeHolder1) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, hasTypeCoords.prefix, titleCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, labelCoords.prefix, '\\\"' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        \n",
+    "        if(row['titolo_originale'] != 'None' and row['titolo_originale'] != ''):\n",
+    "            line = triple(e35placeHolder1, hasAlternativeFormCoords.prefix, \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/original_title>\") + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(\"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/original_title>\", hasTypeCoords.prefix, titleCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(\"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/original_title>\", labelCoords.prefix, '\\\"' + row['titolo_originale'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "\n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.7.3 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 218 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_series.ipynb

@@ -0,0 +1,218 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "# Utilities to handle character encodings\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/e73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'series'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasTypeCoords.prefix, manMadeObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(datiniCoords.prefix + row['id'], labelCoords.prefix, '\\\"Documento fisico: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e73placeHolder =  \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "        line = triple(datiniCoords.prefix + row['id'], carriesCoords.prefix, e73placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, hasTypeCoords.prefix, informationObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, labelCoords.prefix, '\\\"Contenuto informativo: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "\n",
+    "        #\n",
+    "        # If the 'titolo_aspo' property is not empty for the given entry, write down title-related triples\n",
+    "        if(row['titolo_aspo'] != 'None'):\n",
+    "            e35placeHolder1 = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + titleCoords.code + \">\"\n",
+    "            line = triple(e73placeHolder, identifiedByCoords.prefix, e35placeHolder1) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, hasTypeCoords.prefix, titleCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, labelCoords.prefix, '\\\"' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            \n",
+    "        if(row['tipologia'] != ''):\n",
+    "            tipologie = []\n",
+    "            pipe = \"|\" \n",
+    "            if pipe in row['tipologia']:\n",
+    "                tipologie = row['tipologia'].split('|')\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + tipologie.replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "            else:\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "                   \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.7.3 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 203 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_subfonds_genreform.ipynb

@@ -0,0 +1,203 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "# Utilities to handle character encodings\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "hasNoteCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3_has_note>', 'no:')\n",
+    "hasTypeNCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P3.1_has_type>', 'tn:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "stringCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E62_String>', 'sr:', 'E62')"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 17,
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasNoteCoords.prefix + ' ' + hasNoteCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeNCoords.prefix + ' ' + hasTypeNCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + stringCoords.prefix + ' ' + stringCoords.uri + closeLine)\n",
+    "\n",
+    "    output.write('\\n')\n"
+   ],
+   "outputs": [],
+   "metadata": {}
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 18,
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'subfonds'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_genreform.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # <genreform> - genere\n",
+    "        if(row['genere'] != ''):\n",
+    "            e62placeHolder= \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + stringCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], hasNoteCoords.prefix, e62placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e62placeHolder, labelCoords.prefix, '\\\"' + row['genere'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"').replace(' |',',') + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e62placeHolder, hasTypeCoords.prefix, stringCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + stringCoords.code + \"_\" + typeCoords.code + \">\"\n",
+    "            line = triple(e62placeHolder, hasTypeNCoords.prefix, e55placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, labelCoords.prefix, '\\\"Genere\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "                        \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ],
+   "outputs": [],
+   "metadata": {}
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "name": "python3",
+   "display_name": "Python 3.9.0 64-bit"
+  },
+  "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  },
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 236 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_subseries.ipynb

@@ -0,0 +1,236 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "# Utilities to handle character encodings\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'subseries'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "        # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?\n",
+    "        line = triple(datiniCoords.prefix + row['id'], hasTypeCoords.prefix, manMadeObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(datiniCoords.prefix + row['id'], labelCoords.prefix, '\\\"Documento fisico: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \">\"\n",
+    "        line = triple(datiniCoords.prefix + row['id'], carriesCoords.prefix, e73placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, hasTypeCoords.prefix, informationObjectCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolder, labelCoords.prefix, '\\\"Contenuto informativo: ' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e55placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + typeCoords.code + \">\"        \n",
+    "        if(row['tipologia'] != ''):\n",
+    "            line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "            output.write(line)            \n",
+    "            line = triple(e55placeHolder, hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e55placeHolder, labelCoords.prefix, '\\\"' + row['tipologia'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        #\n",
+    "        # If the 'titolo_aspo' property is not empty for the given entry, write down title-related triples\n",
+    "        if(row['titolo_aspo'] != 'None'):\n",
+    "            e35placeHolder1 =  \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + titleCoords.code + \">\"\n",
+    "            output.write(line)\n",
+    "            line = triple(e73placeHolder, identifiedByCoords.prefix, e35placeHolder1) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, hasTypeCoords.prefix, titleCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e35placeHolder1, labelCoords.prefix, '\\\"' + row['titolo_aspo'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"')+ '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        #\n",
+    "        # Triplify the 'segnatura'\n",
+    "        if(row['segnatura_parent'] != ''):\n",
+    "            e42placeHolder =  \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + identifierCoords.code + \">\"\n",
+    "            line = triple(datiniCoords.prefix + row['id'], identifiedByCoords.prefix, e42placeHolder) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e42placeHolder, hasTypeCoords.prefix, identifierCoords.prefix) + closeLine\n",
+    "            output.write(line)\n",
+    "            line = triple(e42placeHolder, labelCoords.prefix, '\\\"Segnatura: Fondo Datini, ' + row['segnatura_parent'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "        \n",
+    "        if(row['tipologia'] != ''):\n",
+    "            tipologie = []\n",
+    "            pipe = \"|\" \n",
+    "            if pipe in row['tipologia']:\n",
+    "                tipologie = row['tipologia'].split('|')\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + tipologie.replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "            else:\n",
+    "                e55placeHolder = \"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\"\n",
+    "                line = triple(e73placeHolder, hasTypePCoords.prefix, e55placeHolder) + closeLine\n",
+    "                output.write(line)\n",
+    "        \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 208 - 0
ASPO/CSV_to_RDF/datini/CSV_to_RDF_datini_type.ipynb

@@ -0,0 +1,208 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Parser per estrarre tutte le tipologie di documenti ed associarle solo una volta ad ogni record"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Utilities to read/write csv files\n",
+    "import csv\n",
+    "import unicodedata\n",
+    "# Ordered Dicts\n",
+    "from collections import OrderedDict\n",
+    "import json\n",
+    "\n",
+    "\n",
+    "# OPZIONAL IMPORTS\n",
+    "\n",
+    "# For timestamping/simple speed tests\n",
+    "from datetime import datetime\n",
+    "# Random number generator\n",
+    "from random import *\n",
+    "# System & command line utilities\n",
+    "import sys\n",
+    "# Json for the dictionary\n",
+    "import json"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/ASPO/datini/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/ASPO/datini/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Custom class to store URIs + related infos for the ontologies/repositories\n",
+    "\n",
+    "class RDFcoords:\n",
+    "    def __init__(self, uri, prefix, code = None):\n",
+    "        self.uri = uri\n",
+    "        self.prefix = prefix\n",
+    "        self.code = code\n",
+    "\n",
+    "\n",
+    "# Repositories\n",
+    "datiniCoords = RDFcoords('<http://datini.archiviodistato.prato.it/la-ricerca/scheda/>', 'dt:')\n",
+    "# Added by FS\n",
+    "personAuthCoords = RDFcoords('<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003->', 'pa:')\n",
+    "# W3/CIDOC Predicates\n",
+    "hasTypeCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>', 'tp:')\n",
+    "hasTypePCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P2_has_type>', 'te:')\n",
+    "carriesCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P128_carries>', 'ca:')\n",
+    "identifiedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by>', 'ib:')\n",
+    "labelCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#label>', 'lb:')\n",
+    "# Added by FS CIDOC properties for person\n",
+    "wasBroughtCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P92i_was_brought_into_existence_by>', 'wb:')\n",
+    "carriedByCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P14_carried_out_by>', 'cb:')\n",
+    "hasAlternativeFormCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P139_has_alternative_form>', 'af:')\n",
+    "\n",
+    "# CIDOC Objects\n",
+    "manMadeObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object>', 'mo:', 'E22')\n",
+    "informationObjectCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object>', 'io:', 'E73')\n",
+    "titleCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E35_Title>', 'ti:' ,'E35')\n",
+    "placeAppellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E44_Place_appellation>', 'pa:', 'E44')\n",
+    "identifierCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E42_Identifier>', 'id:', 'E42')\n",
+    "typeCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E55_Type>', 'ty:', 'E55')\n",
+    "# Added by FS CIDOC entity\n",
+    "creationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E65_Creation>', 'cr:', 'E65')\n",
+    "personCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E21_Person>', 'ps:', 'E21')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Basic functions for triples / shortened triples in TTL format\n",
+    "\n",
+    "def triple(subject, predicate, object1):\n",
+    "    line = subject + ' ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def doublet(predicate, object1):\n",
+    "    line = '    ' + predicate + ' ' + object1\n",
+    "    return line\n",
+    "\n",
+    "def singlet(object1):\n",
+    "    line = '        ' + object1\n",
+    "    return line\n",
+    "\n",
+    "# Line endings in TTL format\n",
+    "continueLine1 = ' ;\\n'\n",
+    "continueLine2 = ' ,\\n'\n",
+    "closeLine = ' .\\n'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def writeTTLHeader(output):\n",
+    "    output.write('@prefix ' + datiniCoords.prefix + ' ' + datiniCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personAuthCoords.prefix + ' ' + personAuthCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypeCoords.prefix + ' ' + hasTypeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasTypePCoords.prefix + ' ' + hasTypePCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + manMadeObjectCoords.prefix + ' ' + manMadeObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriesCoords.prefix + ' ' + carriesCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + informationObjectCoords.prefix + ' ' + informationObjectCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifiedByCoords.prefix + ' ' + identifiedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + titleCoords.prefix + ' ' + titleCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + labelCoords.prefix + ' ' + labelCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + identifierCoords.prefix + ' ' + identifierCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + wasBroughtCoords.prefix + ' ' + wasBroughtCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + typeCoords.prefix + ' ' + typeCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + carriedByCoords.prefix + ' ' + carriedByCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + personCoords.prefix + ' ' + personCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasAlternativeFormCoords.prefix + ' ' + hasAlternativeFormCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'data_'\n",
+    "fileType = 'all_type'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '.ttl', 'w') as output:\n",
+    "    reader = csv.DictReader(csv_file)\n",
+    "    writeTTLHeader(output)\n",
+    "    first = True\n",
+    "    ii = 0\n",
+    "    for row in reader:\n",
+    "        # The index ii is used to process a limited number of entries for testing purposes\n",
+    "        ii = ii+1\n",
+    "        # Skip the first line as it carries info we don't want to triplify\n",
+    "        if(first):\n",
+    "            first = False\n",
+    "            continue\n",
+    "\n",
+    "        line = triple(\"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\", hasTypeCoords.prefix, typeCoords.prefix) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(\"<http://archiviodistato.prato.it/\" + typeCoords.code + \"/\" + row['tipologia'].replace(\" \", \"\") + \">\", labelCoords.prefix,  '\\\"' + row['tipologia']+ '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        \n",
+    "        output.write('\\n')\n",
+    "        #\n",
+    "        #\n",
+    "        # Limit number of entries processed (if desired)\n",
+    "        if(ii>max_entries):\n",
+    "            break\n",
+    "        "
+   ]
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.9.0 64-bit",
+   "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.9.0"
+  },
+  "metadata": {
+   "interpreter": {
+    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
+   }
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}