|
@@ -0,0 +1,153 @@
|
|
|
+
|
|
|
+import csv
|
|
|
+
|
|
|
+import unicodedata
|
|
|
+
|
|
|
+from collections import OrderedDict
|
|
|
+
|
|
|
+import json
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+from datetime import datetime
|
|
|
+
|
|
|
+from random import *
|
|
|
+
|
|
|
+import sys
|
|
|
+
|
|
|
+import json
|
|
|
+
|
|
|
+import_dir = '/Users/alessiaspadi/Documents/RESTORE/temp_MPP/tabelle/Ospedale/mod/'
|
|
|
+export_dir = '/Users/alessiaspadi/Documents/RESTORE/temp_MPP/tabelle/Carica/PC14/'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class RDFcoords:
|
|
|
+ def __init__(self, uri, prefix, code=None):
|
|
|
+ self.uri = uri
|
|
|
+ self.prefix = prefix
|
|
|
+ self.code = code
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+museoCoords = RDFcoords('<http://palazzopretorio.comune.prato.it/it/le-opere/alcuni-capolavori/>', 'mpp:')
|
|
|
+autCoords = RDFcoords('<http://palazzopretorio.comune.prato.it/it/opere/autori/>', 'aut:')
|
|
|
+cidocCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/>', 'crm:')
|
|
|
+aatCoords = RDFcoords('<http://vocab.getty.edu/aat/>', 'aat:')
|
|
|
+nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')
|
|
|
+schemaCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+continueLine1 = ' ;\n'
|
|
|
+continueLine2 = ' ,\n'
|
|
|
+closeLine = ' .\n'
|
|
|
+
|
|
|
+
|
|
|
+def writeTTLHeader(output):
|
|
|
+ output.write('@prefix ' + museoCoords.prefix + ' ' + museoCoords.uri + closeLine)
|
|
|
+ output.write('@prefix ' + cidocCoords.prefix + ' ' + cidocCoords.uri + closeLine)
|
|
|
+ output.write('@prefix ' + aatCoords.prefix + ' ' + aatCoords.uri + closeLine)
|
|
|
+ output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)
|
|
|
+ output.write('@prefix ' + nsCoords.prefix + ' ' + nsCoords.uri + closeLine)
|
|
|
+ output.write('@prefix ' + autCoords.prefix + ' ' + autCoords.uri + closeLine)
|
|
|
+
|
|
|
+ output.write('\n')
|
|
|
+
|
|
|
+
|
|
|
+filePrefix = 'AR20AUT_'
|
|
|
+fileType = 'Ospedale'
|
|
|
+max_entries = 1000000000
|
|
|
+
|
|
|
+
|
|
|
+def get_role(role):
|
|
|
+ role_file = open('/Users/alessiaspadi/Documents/RESTORE/temp_MPP/tabelle/AAT_RUOLI.csv', newline="")
|
|
|
+ reader = csv.DictReader(role_file)
|
|
|
+ for row in reader:
|
|
|
+ if row['Label'] == role:
|
|
|
+ return row['AAT']
|
|
|
+
|
|
|
+
|
|
|
+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:
|
|
|
+
|
|
|
+ ii = ii + 1
|
|
|
+
|
|
|
+ url = row['URL']
|
|
|
+
|
|
|
+
|
|
|
+ datplaceHolder = museoCoords.prefix + url
|
|
|
+
|
|
|
+
|
|
|
+ if row['AUTH'] != '':
|
|
|
+ aut_role = ''
|
|
|
+ if row['AUTQ'] != '':
|
|
|
+ aut_role = row['AUTQ']
|
|
|
+ else:
|
|
|
+ aut_role = ''
|
|
|
+ ll = row['AUTN'] + '_' + aut_role
|
|
|
+ lab = ll.replace(' ', '')
|
|
|
+ label = lab.replace(',', '')
|
|
|
+
|
|
|
+ AuthorPlaceholder = autCoords.prefix + row['URL']
|
|
|
+
|
|
|
+ line = triple(museoCoords.prefix + '_' + label,
|
|
|
+ nsCoords.prefix + 'type',
|
|
|
+ cidocCoords.prefix + 'PC14_carried_out_by') + closeLine
|
|
|
+ output.write(line)
|
|
|
+ line = triple(museoCoords.prefix + '_' + label,
|
|
|
+ schemaCoords.prefix + 'label',
|
|
|
+ '\"' + row['AUTN'] + ' nel ruolo di ' + aut_role + '\"') + closeLine
|
|
|
+ output.write(line)
|
|
|
+
|
|
|
+ line = triple(museoCoords.prefix + '_' + label,
|
|
|
+ cidocCoords.prefix + 'P02_has_range',
|
|
|
+ AuthorPlaceholder) + closeLine
|
|
|
+ output.write(line)
|
|
|
+
|
|
|
+ if aut_role != '':
|
|
|
+ role = get_role(aut_role)
|
|
|
+ line = triple(museoCoords.prefix + '_' + label,
|
|
|
+ cidocCoords.prefix + 'P14.1_in_the_role_of',
|
|
|
+ aatCoords.prefix + role) + closeLine
|
|
|
+ output.write(line)
|
|
|
+ line = triple(aatCoords.prefix + role,
|
|
|
+ nsCoords.prefix + 'type',
|
|
|
+ cidocCoords.prefix + 'E55_Type') + closeLine
|
|
|
+ output.write(line)
|
|
|
+ line = triple(aatCoords.prefix + role,
|
|
|
+ schemaCoords.prefix + 'label',
|
|
|
+ '\"' + aut_role + '\"') + closeLine
|
|
|
+ output.write(line)
|
|
|
+
|
|
|
+ output.write('\n')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (ii > max_entries):
|
|
|
+ break
|