Browse Source

Add new parsers CSV_to_RDF OVI

Federica 2 years ago
parent
commit
bf2b2c6818

+ 257 - 0
OVI/CSV_to_RDF/CSV_to_RDF_ovi_edition.ipynb

@@ -0,0 +1,257 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "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": 14,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/OVI/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/OVI/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "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",
+    "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",
+    "hasLanguageCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P72_has_language>', 'hl:')\n",
+    "documentsCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P70_documents>', 'ds:')\n",
+    "hasComponentCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P148_has_component>', 'hc:')\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')\n",
+    "linguisticObjCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E33_Linguistic_Object>', 'lj:', 'E33')\n",
+    "languageCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E56_Language>', 'ln:', 'E56')\n",
+    "appellationCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E41_appellation>', 'ap:', 'E41')\n",
+    "propositionalObjCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/E89_Propositional_Object>', 'pj:', 'E89')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "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": 17,
+   "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",
+    "    output.write('@prefix ' + linguisticObjCoords.prefix + ' ' + linguisticObjCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + languageCoords.prefix + ' ' + languageCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasLanguageCoords.prefix + ' ' + hasLanguageCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + documentsCoords.prefix + ' ' + documentsCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + appellationCoords.prefix + ' ' + appellationCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + propositionalObjCoords.prefix + ' ' + propositionalObjCoords.uri + closeLine)\n",
+    "    output.write('@prefix ' + hasComponentCoords.prefix + ' ' + hasComponentCoords.uri + closeLine)\n",
+    "    output.write('\\n')\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 18,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'Biblio'\n",
+    "fileType = 'Datini'\n",
+    "max_entries = 10000000000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '_IDAspo.csv', newline=\"\") as csv_file, open(export_dir + filePrefix + fileType + '_edition.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+0\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",
+    "        if(row['num_ovi'] != '2'):\n",
+    "            e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \"_OVI\"\n",
+    "        else: \n",
+    "            e73placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + informationObjectCoords.code + \"_OVI_2\"\n",
+    "\n",
+    "        e73placeHolderE = e73placeHolder + \"_ED>\"            \n",
+    "        line = triple(e73placeHolderE, documentsCoords.prefix, e73placeHolder + \">\") + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e73placeHolderE, labelCoords.prefix, '\\\"Edizione\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e41placeHolder = e73placeHolder + \"_ED\" + \"_\" + appellationCoords.code + \">\"\n",
+    "        line = triple(e73placeHolderE , identifiedByCoords.prefix, e41placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e41placeHolder, hasTypeCoords.prefix, appellationCoords.prefix) + closeLine\n",
+    "        output.write(line)            \n",
+    "        line = triple(e41placeHolder, labelCoords.prefix, '\\\"'  + row['edizione'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"') + '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "\n",
+    "        #edizione abbreviata\n",
+    "        e41placeHolder2 = e73placeHolder + \"_ED_AB>\"\n",
+    "        line = triple(e41placeHolder, hasAlternativeFormCoords.prefix, e41placeHolder2) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e41placeHolder2, labelCoords.prefix, '\\\"' + row['edizione_abbr'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"') + '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e41e55placeHolder2 = e73placeHolder + \"_ED_AB_E55>\"\n",
+    "        line = triple(e41placeHolder2, hasTypePCoords.prefix, e41e55placeHolder2) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e41e55placeHolder2, labelCoords.prefix, '\\\"Edizione abbreviata\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "\n",
+    "        #raccolta\n",
+    "        e89placeHolder = e73placeHolder + \"_\" + propositionalObjCoords.code + \">\"\n",
+    "        line = triple(e89placeHolder, hasComponentCoords.prefix, e73placeHolder+ \">\") + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e89placeHolder, hasTypeCoords.prefix, propositionalObjCoords.prefix) + closeLine\n",
+    "        output.write(line)  \n",
+    "        line = triple(e89placeHolder, labelCoords.prefix, '\\\"' + row['raccolta'].replace('\\\\','\\\\\\\\').replace('\"','\\\\\"') + '\\\"') + closeLine\n",
+    "        output.write(line)\n",
+    "        e89e55placeHolder = e73placeHolder + \"_\" + propositionalObjCoords.code + \"_E55>\"\n",
+    "        line = triple(e89placeHolder, hasTypePCoords.prefix, e89e55placeHolder) + closeLine\n",
+    "        output.write(line)\n",
+    "        line = triple(e89e55placeHolder, labelCoords.prefix, '\\\"Raccolta\\\"') + 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
OVI/CSV_to_RDF/CSV_to_RDF_ovi_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/OVI/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/OVI/'"
+   ]
+  },
+  {
+   "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 = 'Biblio'\n",
+    "fileType = 'Datini'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '_IDAspo.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 + \"_OVI>\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_OVI>\"\n",
+    "\n",
+    "        # Data invio\n",
+    "        if(row['data_partenza'] != ''):\n",
+    "            e52PplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + timeSpanCoords.code + \"_OVI>\"\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_partenza'] + '\\\"') + 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_arrivo'] != ''):\n",
+    "            e52AplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + timeSpanCoords.code + \"_OVI>\"\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_arrivo'] + '\\\"') + 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
+}

+ 252 - 0
OVI/CSV_to_RDF/CSV_to_RDF_ovi_event_exchange_place.ipynb

@@ -0,0 +1,252 @@
+{
+ "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/OVI/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/OVI/'"
+   ]
+  },
+  {
+   "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 = 'Biblio'\n",
+    "fileType = 'Datini'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '_IDAspo.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 + \"_OVI>\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_OVI>\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_OVI>\"\n",
+    "          \n",
+    "        if(row['luogo_emissione'] != '' and row['luogo_arrivo'] != ''):\n",
+    "            #Luogo partenza\n",
+    "            e53placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + placeCoords.code +  \"_OVI>\"\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, '\\\"' + row['luogo_emissione'] + '\\\"') + closeLine\n",
+    "            output.write(line)\n",
+    "            #Luogo arrivo\n",
+    "            e53placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + placeCoords.code +  \"_OVI>\"\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, '\\\"' + row['luogo_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
+}

+ 257 - 0
OVI/CSV_to_RDF/CSV_to_RDF_ovi_event_exchange_receiver.ipynb

@@ -0,0 +1,257 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "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": 14,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/OVI/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/OVI/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "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": 16,
+   "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": 17,
+   "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": 18,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'Biblio'\n",
+    "fileType = 'Datini'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '_IDAspo.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 + \"_OVI>\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_OVI>\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_OVI>\"\n",
+    "        PC14splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + pcarriedByCoords.code + \"_OVI>\"   \n",
+    "        PC14rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + pcarriedByCoords.code + \"_OVI>\"   \n",
+    "        E55splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + typeCoords.code + \"_OVI>\"       \n",
+    "        E55rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + typeCoords.code + \"_OVI>\"\n",
+    "    \n",
+    "        if(row['destinatario'] != ''):\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, \"\\\"\" + row['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, \"\\\"\" + row['destinatario'] + \"\\\"\") + 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
+}

+ 256 - 0
OVI/CSV_to_RDF/CSV_to_RDF_ovi_event_exchange_sender.ipynb

@@ -0,0 +1,256 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "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": 14,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/CSV/OVI/'\n",
+    "export_dir = '/Users/federicaspinelli/Google Drive/OVI-CNR/RDF/OVI/'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "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": 16,
+   "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": 17,
+   "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": 18,
+   "metadata": {
+    "tags": []
+   },
+   "outputs": [],
+   "source": [
+    "filePrefix = 'Biblio'\n",
+    "fileType = 'Datini'\n",
+    "max_entries = 1000000000\n",
+    "\n",
+    "with open(import_dir + filePrefix + fileType + '_IDAspo.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 + \"_OVI>\"\n",
+    "        el2placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_OVI>\"\n",
+    "        el3placeHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_OVI>\"\n",
+    "        PC14splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + pcarriedByCoords.code + \"_OVI>\"   \n",
+    "        PC14rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + pcarriedByCoords.code + \"_OVI>\"   \n",
+    "        E55splaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + sendLetterCoords.code + \"_\" + typeCoords.code + \"_OVI>\"       \n",
+    "        E55rplaceHolder = \"<http://datini.archiviodistato.prato.it/la-ricerca/scheda/\" + row['id'] + \"/\" + receiveLetterCoords.code + \"_\" + typeCoords.code + \"_OVI>\"\n",
+    "    \n",
+    "        if(row['mittente'] != '' ):     \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, \"\\\"\" + row['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, \"\\\"\" + row['mittente'] + \"\\\"\") + 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
+}