CSV_to_RDF_OA_BIB_IMG.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. # Utilities to read/write csv files
  2. import csv
  3. # Utilities to handle character encodings
  4. import unicodedata
  5. # Ordered Dicts
  6. from collections import OrderedDict
  7. from http.cookiejar import CookieJar
  8. from urllib.request import urlopen
  9. #from bs4 import BeautifulSoup
  10. import urllib
  11. import json
  12. from socket import error as SocketError
  13. import html.parser
  14. # OPZIONAL IMPORTS
  15. # For timestamping/simple speed tests
  16. from datetime import datetime
  17. # Random number generator
  18. from random import *
  19. # System & command line utilities
  20. import sys
  21. # Json for the dictionary
  22. import json
  23. import_dir = '/Users/federicaspinelli/TEAMOVI/Parser/DATA/MPP/CSV/corretti/'
  24. export_dir = '/Users/federicaspinelli/TEAMOVI/Parser/DATA/MPP/RDF/'
  25. # Custom class to store URIs + related infos for the ontologies/repositories
  26. class RDFcoords:
  27. def __init__(self, uri, prefix, code=None):
  28. self.uri = uri
  29. self.prefix = prefix
  30. self.code = code
  31. # Repositories
  32. museoCoords = RDFcoords('<https://palazzopretorio.prato.it/it/le-opere/alcuni-capolavori/>', 'mpp:')
  33. autCoords = RDFcoords('<https://palazzopretorio.prato.it/it/opere/autori/>', 'aut:')
  34. cidocCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/>', 'crm:')
  35. aatCoords = RDFcoords('<http://vocab.getty.edu/aat/>', 'aat:')
  36. nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')
  37. schemaCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')
  38. xsdCoords = RDFcoords('<http://www.w3.org/2001/XMLSchema#>', 'xsd:')
  39. iconCoords = RDFcoords('<http://iconclass.org/>', 'ico:')
  40. documentsCoords = RDFcoords('<http://www.cidoc-crm.org/cidoc-crm/P70_documents>', 'ds:')
  41. rdfsCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')
  42. nsCoords = RDFcoords('<http://www.w3.org/1999/02/22-rdf-syntax-ns#>', 'rdf:')
  43. schemaCoords = RDFcoords('<http://www.schema.org/>', 'schema:')
  44. rdfsCoords = RDFcoords('<http://www.w3.org/2000/01/rdf-schema#>', 'rdfs:')
  45. # Basic functions for triples / shortened triples in TTL format
  46. def triple(subject, predicate, object1):
  47. line = subject + ' ' + predicate + ' ' + object1
  48. return line
  49. def doublet(predicate, object1):
  50. line = ' ' + predicate + ' ' + object1
  51. return line
  52. def singlet(object1):
  53. line = ' ' + object1
  54. return line
  55. # Line endings in TTL format
  56. continueLine1 = ' ;\n'
  57. continueLine2 = ' ,\n'
  58. closeLine = ' .\n'
  59. def writeTTLHeader(output):
  60. output.write('@prefix ' + museoCoords.prefix + ' ' + museoCoords.uri + closeLine)
  61. output.write('@prefix ' + cidocCoords.prefix + ' ' + cidocCoords.uri + closeLine)
  62. output.write('@prefix ' + aatCoords.prefix + ' ' + aatCoords.uri + closeLine)
  63. output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)
  64. output.write('@prefix ' + autCoords.prefix + ' ' + autCoords.uri + closeLine)
  65. output.write('@prefix ' + xsdCoords.prefix + ' ' + xsdCoords.uri + closeLine)
  66. output.write('@prefix ' + iconCoords.prefix + ' ' + iconCoords.uri + closeLine)
  67. output.write('@prefix ' + documentsCoords.prefix + ' ' + documentsCoords.uri + closeLine)
  68. output.write('@prefix ' + rdfsCoords.prefix + ' ' + rdfsCoords.uri + closeLine)
  69. output.write('\n')
  70. filePrefix = 'OA_BIB_'
  71. fileType = 'IMG'
  72. max_entries = 1000000000
  73. with open(import_dir + filePrefix + fileType + '.csv', newline="") as csv_file, open(
  74. export_dir + filePrefix + fileType + '.ttl', 'w') as output:
  75. reader = csv.DictReader(csv_file)
  76. writeTTLHeader(output)
  77. first = True
  78. ii = 0
  79. for row in reader:
  80. # The index ii is used to process a limited number of entries for testing purposes
  81. ii = ii + 1
  82. # columnName = list(row)
  83. # placeHolders
  84. pp = row['NCT']
  85. if row['Marchini-1958-1']!= '':
  86. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  87. id = row['Marchini-1958-1'].replace(".jpg", "")
  88. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  89. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  90. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  91. output.write(line)
  92. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  93. output.write(line)
  94. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  95. output.write(line)
  96. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Marchini 1958\"') + closeLine
  97. output.write(line)
  98. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  99. output.write(line)
  100. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  101. output.write(line)
  102. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Marchini-1958-1']+ '\"') + closeLine
  103. output.write(line)
  104. if row['Marchini-1958-2']!= '':
  105. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  106. id = row['Marchini-1958-2'].replace(".jpg", "")
  107. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  108. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  109. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  110. output.write(line)
  111. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  112. output.write(line)
  113. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  114. output.write(line)
  115. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Marchini 1958\"') + closeLine
  116. output.write(line)
  117. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  118. output.write(line)
  119. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  120. output.write(line)
  121. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Marchini-1958-2']+ '\"') + closeLine
  122. output.write(line)
  123. if row['Marchini-1958-3']!= '':
  124. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  125. id = row['Marchini-1958-3'].replace(".jpg", "")
  126. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  127. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  128. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  129. output.write(line)
  130. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  131. output.write(line)
  132. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  133. output.write(line)
  134. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Marchini 1958\"') + closeLine
  135. output.write(line)
  136. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  137. output.write(line)
  138. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  139. output.write(line)
  140. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Marchini-1958-3']+ '\"') + closeLine
  141. output.write(line)
  142. if row['Guasti-1858-1']!= '':
  143. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  144. id = row['Guasti-1858-1'].replace(".jpg", "")
  145. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  146. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  147. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  148. output.write(line)
  149. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  150. output.write(line)
  151. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  152. output.write(line)
  153. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1858\"') + closeLine
  154. output.write(line)
  155. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  156. output.write(line)
  157. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  158. output.write(line)
  159. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1858-1']+ '\"') + closeLine
  160. output.write(line)
  161. if row['Guasti-1858-2']!= '':
  162. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  163. id = row['Guasti-1858-2'].replace(".jpg", "")
  164. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  165. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  166. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  167. output.write(line)
  168. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  169. output.write(line)
  170. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  171. output.write(line)
  172. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1858\"') + closeLine
  173. output.write(line)
  174. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  175. output.write(line)
  176. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  177. output.write(line)
  178. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1858-2']+ '\"') + closeLine
  179. output.write(line)
  180. if row['Guasti-1858-3']!= '':
  181. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  182. id = row['Guasti-1858-3'].replace(".jpg", "")
  183. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  184. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  185. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  186. output.write(line)
  187. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  188. output.write(line)
  189. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  190. output.write(line)
  191. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1858\"') + closeLine
  192. output.write(line)
  193. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  194. output.write(line)
  195. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  196. output.write(line)
  197. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1858-3']+ '\"') + closeLine
  198. output.write(line)
  199. if row['Guasti-1888-1']!= '':
  200. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  201. id = row['Guasti-1888-1'].replace(".jpg", "")
  202. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  203. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  204. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  205. output.write(line)
  206. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  207. output.write(line)
  208. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  209. output.write(line)
  210. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1888\"') + closeLine
  211. output.write(line)
  212. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  213. output.write(line)
  214. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  215. output.write(line)
  216. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1888-1']+ '\"') + closeLine
  217. output.write(line)
  218. if row['Guasti-1888-2']!= '':
  219. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  220. id = row['Guasti-1888-2'].replace(".jpg", "")
  221. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  222. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  223. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  224. output.write(line)
  225. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  226. output.write(line)
  227. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  228. output.write(line)
  229. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1888\"') + closeLine
  230. output.write(line)
  231. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  232. output.write(line)
  233. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  234. output.write(line)
  235. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1888-2']+ '\"') + closeLine
  236. output.write(line)
  237. if row['Guasti-1888-3']!= '':
  238. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  239. id = row['Guasti-1888-3'].replace(".jpg", "")
  240. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  241. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  242. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  243. output.write(line)
  244. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  245. output.write(line)
  246. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  247. output.write(line)
  248. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1888\"') + closeLine
  249. output.write(line)
  250. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  251. output.write(line)
  252. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  253. output.write(line)
  254. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1888-3']+ '\"') + closeLine
  255. output.write(line)
  256. if row['Guasti-1888-4']!= '':
  257. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  258. id = row['Guasti-1888-4'].replace(".jpg", "")
  259. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  260. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  261. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  262. output.write(line)
  263. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  264. output.write(line)
  265. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  266. output.write(line)
  267. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1888\"') + closeLine
  268. output.write(line)
  269. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  270. output.write(line)
  271. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  272. output.write(line)
  273. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1888-4']+ '\"') + closeLine
  274. output.write(line)
  275. if row['Guasti-1888-5']!= '':
  276. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  277. id = row['Guasti-1888-5'].replace(".jpg", "")
  278. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  279. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  280. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  281. output.write(line)
  282. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  283. output.write(line)
  284. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  285. output.write(line)
  286. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1888\"') + closeLine
  287. output.write(line)
  288. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  289. output.write(line)
  290. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  291. output.write(line)
  292. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1888-5']+ '\"') + closeLine
  293. output.write(line)
  294. if row['Guasti-1888-6']!= '':
  295. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  296. id = row['Guasti-1888-6'].replace(".jpg", "")
  297. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  298. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  299. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  300. output.write(line)
  301. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  302. output.write(line)
  303. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  304. output.write(line)
  305. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Guida Guasti 1888\"') + closeLine
  306. output.write(line)
  307. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  308. output.write(line)
  309. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  310. output.write(line)
  311. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Guasti-1888-6']+ '\"') + closeLine
  312. output.write(line)
  313. if row['Papini-1912-1']!= '':
  314. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  315. id = row['Papini-1912-1'].replace(".jpg", "")
  316. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  317. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  318. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  319. output.write(line)
  320. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  321. output.write(line)
  322. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  323. output.write(line)
  324. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Catalogo Papini 1912\"') + closeLine
  325. output.write(line)
  326. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  327. output.write(line)
  328. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  329. output.write(line)
  330. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Papini-1912-1']+ '\"') + closeLine
  331. output.write(line)
  332. if row['Papini-1912-2']!= '':
  333. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  334. id = row['Papini-1912-2'].replace(".jpg", "")
  335. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  336. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  337. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  338. output.write(line)
  339. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  340. output.write(line)
  341. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  342. output.write(line)
  343. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Catalogo Papini 1912\"') + closeLine
  344. output.write(line)
  345. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  346. output.write(line)
  347. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  348. output.write(line)
  349. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Papini-1912-2']+ '\"') + closeLine
  350. output.write(line)
  351. if row['Papini-1912-3']!= '':
  352. e73placeHolderEDPP = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + pp + ">"
  353. id = row['Papini-1912-3'].replace(".jpg", "")
  354. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  355. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + '_E36_E42>'
  356. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolderEDPP) + closeLine
  357. output.write(line)
  358. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  359. output.write(line)
  360. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Opera\"') + closeLine
  361. output.write(line)
  362. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Catalogo Papini 1912\"') + closeLine
  363. output.write(line)
  364. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  365. output.write(line)
  366. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  367. output.write(line)
  368. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['Papini-1912-3']+ '\"') + closeLine
  369. output.write(line)
  370. if row['FNTI-SS']!= '':
  371. e73placeHolder = "<"+ row['ID OPERA'].replace(" ","")+ "_E73>"
  372. id = row['FNTI-SS'].replace(".pdf", "")
  373. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  374. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + "_E36_E42>"
  375. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolder) + closeLine
  376. output.write(line)
  377. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  378. output.write(line)
  379. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Storica\"') + closeLine
  380. output.write(line)
  381. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Scheda Storica\"') + closeLine
  382. output.write(line)
  383. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  384. output.write(line)
  385. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  386. output.write(line)
  387. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['FNTI-SS'].replace("pdf","jpg")+ '\"') + closeLine
  388. output.write(line)
  389. if row['SS-1956-Marchini']!= '':
  390. e73placeHolder = "<"+ row['ID OPERA'].replace(" ","")+ "_E73>"
  391. id = row['SS-1956-Marchini'].replace(".pdf", "")
  392. e36placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + ">"
  393. e36e42placeHolder = "<https://palazzopretorio.prato.it/it/bib/" + row['BIBH'] + "/E73" + "_ED_" + id + "_E36_E42>"
  394. line = triple(e36placeHolder, cidocCoords.prefix + 'P138_represents', e73placeHolder) + closeLine
  395. output.write(line)
  396. line = triple(e36placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E36_Visual_Item') + closeLine
  397. output.write(line)
  398. line = triple(e36placeHolder, rdfsCoords.prefix + 'label', '\"Scheda Storica\"') + closeLine
  399. output.write(line)
  400. line = triple(e36placeHolder, cidocCoords.prefix + 'P2_has_type', '\"Marchini 1956\"') + closeLine
  401. output.write(line)
  402. line = triple(e36placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e36e42placeHolder) + closeLine
  403. output.write(line)
  404. line = triple(e36e42placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E42_Identifier') + closeLine
  405. output.write(line)
  406. line = triple(e36e42placeHolder, rdfsCoords.prefix + 'label', '\"'+row['SS-1956-Marchini'].replace("pdf","jpg")+ '\"') + closeLine
  407. output.write(line)
  408. output.write('\n')
  409. #
  410. #
  411. # Limit number of entries processed (if desired)
  412. if (ii > max_entries):
  413. break