Browse Source

Elimina 'Museo/CSV_to_RDF/CSV_to_RDF_mpp_MaterialAndTechnique.py'

Alessia 2 years ago
parent
commit
d30205c4ae
1 changed files with 0 additions and 144 deletions
  1. 0 144
      Museo/CSV_to_RDF/CSV_to_RDF_mpp_MaterialAndTechnique.py

+ 0 - 144
Museo/CSV_to_RDF/CSV_to_RDF_mpp_MaterialAndTechnique.py

@@ -1,144 +0,0 @@
-# Utilities to read/write csv files
-import csv
-# Utilities to handle character encodings
-import unicodedata
-# Ordered Dicts
-from collections import OrderedDict
-
-import json
-
-
-# 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/alessiaspadi/Documents/RESTORE/temp_MPP/tabelle/Datini/mod/'
-export_dir = '/Users/alessiaspadi/Documents/RESTORE/temp_MPP/tabelle/Datini/mod/E57_'
-
-
-# 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
-museoCoords = RDFcoords('<http://palazzopretorio.comune.prato.it/it/le-opere/alcuni-capolavori/>', 'mpp:')
-
-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:')
-
-
-# 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 ' + 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('\n')
-
-
-filePrefix = 'SR20OA_'
-fileType = 'Datini'
-max_entries = 1000000000
-
-def get_elem(mtc):
-    mtc_file = open('/Users/alessiaspadi/Documents/RESTORE/temp_MPP/tabelle/AAT_MTC.csv', newline="")
-    reader = csv.DictReader(mtc_file)
-    for row in reader:
-        if row['MTC'] == mtc:
-            return [row['AAT'], row['Type']]
-
-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
-
-        url = row['URL']
-
-        #placeHolders
-        datplaceHolder = museoCoords.prefix + url
-        e12placeHolder = museoCoords.prefix + url + '_E12'
-
-        if row['MTC'] != '':
-            mtcs = []
-            if '/' in row['MTC']:
-                mtcs = row['MTC'].split('/')
-            else:
-                mtcs.append(row['MTC'])
-
-            for tc in mtcs:
-                mtc = tc.lstrip()
-                el = get_elem(mtc)
-                if el[1] == 'MTC/M':
-
-                    line = triple(datplaceHolder,
-                                  cidocCoords.prefix + 'P45_consists_of',
-                                  aatCoords.prefix + el[0]) + closeLine
-                    output.write(line)
-                    line = triple(aatCoords.prefix + el[0],
-                                  nsCoords.prefix + 'type',
-                                  cidocCoords.prefix + 'E57_Material') + closeLine
-                    output.write(line)
-                    line = triple(aatCoords.prefix + el[0],
-                                  schemaCoords.prefix + 'label',
-                                  '\"' + mtc + '\"') + closeLine
-                    output.write(line)
-
-                else:   #E12 Production - P32 used technique - E55 Type
-                    line = triple(e12placeHolder,
-                                  cidocCoords.prefix + 'P32_used_general_technique',
-                                  aatCoords.prefix + el[0]) + closeLine
-                    output.write(line)
-                    line = triple(aatCoords.prefix + el[0],
-                                  nsCoords.prefix + 'type',
-                                  cidocCoords.prefix + 'E55_Type') + closeLine
-                    output.write(line)
-                    line = triple(aatCoords.prefix + el[0],
-                                  schemaCoords.prefix + 'label',
-                                  '\"' + mtc + '\"') + closeLine
-                    output.write(line)
-
-        output.write('\n')
-        #
-        #
-        # Limit number of entries processed (if desired)
-        if (ii > max_entries):
-            break