CSV_to_RDF_Datini.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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. # Basic functions for triples / shortened triples in TTL format
  41. def triple(subject, predicate, object1):
  42. line = subject + ' ' + predicate + ' ' + object1
  43. return line
  44. def doublet(predicate, object1):
  45. line = ' ' + predicate + ' ' + object1
  46. return line
  47. def singlet(object1):
  48. line = ' ' + object1
  49. return line
  50. # Line endings in TTL format
  51. continueLine1 = ' ;\n'
  52. continueLine2 = ' ,\n'
  53. closeLine = ' .\n'
  54. def writeTTLHeader(output):
  55. output.write('@prefix ' + museoCoords.prefix + ' ' + museoCoords.uri + closeLine)
  56. output.write('@prefix ' + cidocCoords.prefix + ' ' + cidocCoords.uri + closeLine)
  57. output.write('@prefix ' + aatCoords.prefix + ' ' + aatCoords.uri + closeLine)
  58. output.write('@prefix ' + schemaCoords.prefix + ' ' + schemaCoords.uri + closeLine)
  59. output.write('@prefix ' + nsCoords.prefix + ' ' + nsCoords.uri + closeLine)
  60. output.write('@prefix ' + autCoords.prefix + ' ' + autCoords.uri + closeLine)
  61. output.write('@prefix ' + xsdCoords.prefix + ' ' + xsdCoords.uri + closeLine)
  62. output.write('@prefix ' + iconCoords.prefix + ' ' + iconCoords.uri + closeLine)
  63. output.write('\n')
  64. filePrefix = 'OA_Data_'
  65. fileType = 'Datini'
  66. max_entries = 1000000000
  67. def get_aut_url(code):
  68. aut_file = open(import_dir + 'AR20AUT_' + fileType + '.csv', newline="")
  69. reader = csv.DictReader(aut_file)
  70. for row in reader:
  71. auth = int(row['AUTH'])
  72. cod = int(code)
  73. role = ''
  74. if row['AUTQ'] != '':
  75. role = row['AUTQ']
  76. else:
  77. role = ''
  78. if auth == cod:
  79. return [row['URL'], role]
  80. def get_role(role):
  81. role_file = open('/Users/federicaspinelli/TEAMOVI/Parser/DATA/MPP/CSV/AAT_RUOLI.csv', newline="")
  82. reader = csv.DictReader(role_file)
  83. for row in reader:
  84. if row['Label'] == role:
  85. return row['AAT']
  86. def get_elem(mtc):
  87. mtc_file = open('/Users/federicaspinelli/TEAMOVI/Parser/DATA/MPP/CSV/AAT_MTC.csv', newline="")
  88. reader = csv.DictReader(mtc_file)
  89. for row in reader:
  90. if row['MTC'] == mtc:
  91. return [row['AAT'], row['Type']]
  92. with open(import_dir + filePrefix + fileType + '.csv', newline="") as csv_file, open(
  93. export_dir + filePrefix + fileType + '.ttl', 'w') as output:
  94. reader = csv.DictReader(csv_file)
  95. writeTTLHeader(output)
  96. first = True
  97. ii = 0
  98. for row in reader:
  99. # The index ii is used to process a limited number of entries for testing purposes
  100. ii = ii + 1
  101. sb = ''
  102. subj = ''
  103. #pp = row['OGTD'] + ' (' + row['ACC'] + ') '
  104. if row['SGTI'] != '':
  105. sb = row['SGTI']
  106. # Triplify the 'codice' -- should exist for every entry
  107. codice = ''
  108. if (row['NCTR'] != '' and row['NCTN'] != ''):
  109. codice = row['NCTR'] + row['NCTN']
  110. codiceP = ''
  111. if (row['AUTH'] != ''):
  112. codiceP = row['AUTH']
  113. place = ''
  114. if (row['PRVC'] != ''):
  115. place = row['PRVC']
  116. columnName = list(row)
  117. url = row['URL']
  118. # placeHolders
  119. datplaceHolder = museoCoords.prefix + url
  120. e1placeHolder = museoCoords.prefix + url + '_E1'
  121. e3placeHolder = museoCoords.prefix + url + 'E3'
  122. e10placeHolder = museoCoords.prefix + url + '_E10'
  123. e12placeHolder = museoCoords.prefix + url + '_E12'
  124. e13placeHolder = museoCoords.prefix + url + '_E13'
  125. e21placeHolder = museoCoords.prefix + url + '_InE21'
  126. e25placeHolder = museoCoords.prefix + url + '_E25'
  127. e34placeHolder = museoCoords.prefix + url + '_E34'
  128. e35placeHolder1 = museoCoords.prefix + url + '_E35'
  129. e42placeHolder = museoCoords.prefix + url + '_E42'
  130. e42CplaceHolder = museoCoords.prefix + url + '_E42_MPP'
  131. e65placeHolder = museoCoords.prefix + url + '_InE65'
  132. e73placeHolder = museoCoords.prefix + url + '_E73'
  133. e74placeHolder = museoCoords.prefix + url + '_E74'
  134. if (codice != ''):
  135. line = triple(datplaceHolder, cidocCoords.prefix + 'P1_is_identified_by', e42placeHolder) + closeLine
  136. output.write(line)
  137. line = triple(e42placeHolder, nsCoords.prefix + 'type',
  138. cidocCoords.prefix + 'E42_Identifier') + closeLine
  139. output.write(line)
  140. line = triple(e42placeHolder,
  141. schemaCoords.prefix + 'label',
  142. '\"0' + codice + '\"') + closeLine
  143. output.write(line)
  144. ###
  145. line = triple(e42placeHolder,
  146. cidocCoords.prefix + 'P2_has_type',
  147. '\"Codice univoco del bene (NCT)\"') + closeLine
  148. output.write(line)
  149. # Write E22 Man Made Object & E73 Information Object -- should exist for every entry?
  150. line = triple(datplaceHolder, nsCoords.prefix + 'type',
  151. cidocCoords.prefix + 'E22_Man-Made_Object') + closeLine
  152. output.write(line)
  153. line = triple(datplaceHolder, schemaCoords.prefix + 'label', '\"' + sb + '\"') + closeLine
  154. output.write(line)
  155. line = triple(datplaceHolder, cidocCoords.prefix + 'P128_carries', e73placeHolder) + closeLine
  156. output.write(line)
  157. line = triple(e73placeHolder, nsCoords.prefix + 'type',
  158. cidocCoords.prefix + 'E73_Information_Object') + closeLine
  159. output.write(line)
  160. ss = ''
  161. if row['SGTI'] != '':
  162. ss = row['SGTI']
  163. else:
  164. ss = 'senza titolo'
  165. line = triple(e73placeHolder, schemaCoords.prefix + 'label',
  166. '\"Opera d\'arte raffigurante ' + ss + '\"') + closeLine
  167. output.write(line)
  168. # E73 - P2 - E55
  169. tt = ''
  170. typeLabel = ''
  171. if row['OGTD'] == 'dipinto':
  172. tt = aatCoords.prefix + "300033618"
  173. elif row['OGTD'] == 'rilievo':
  174. tt = aatCoords.prefix + "300047230"
  175. elif row['OGTD'] == 'polittico':
  176. tt = aatCoords.prefix + "300178235"
  177. elif row['OGTD'] == 'predella':
  178. tt = aatCoords.prefix + "300003745"
  179. line = triple(e73placeHolder,
  180. cidocCoords.prefix + 'P2_has_type',
  181. tt) + closeLine
  182. output.write(line)
  183. line = triple(tt, schemaCoords.prefix + 'label',
  184. '\"' + row['OGTD'] + '\"') + closeLine
  185. output.write(line)
  186. # E73 - P1 - E35
  187. if row['SGTT'] != '':
  188. line = triple(e73placeHolder, cidocCoords.prefix + 'P1_is_identified_by', e35placeHolder1) + closeLine
  189. output.write(line)
  190. line = triple(e35placeHolder1, nsCoords.prefix + 'type', cidocCoords.prefix + 'E35_Title') + closeLine
  191. output.write(line)
  192. line = triple(e35placeHolder1, schemaCoords.prefix + 'label', '\"' + row['SGTT'] + '\"') + closeLine
  193. output.write(line)
  194. # E22 - P62 - E1
  195. if row['SGTI'] != '':
  196. line = triple(datplaceHolder,
  197. cidocCoords.prefix + 'P62_depicts',
  198. e1placeHolder) + closeLine
  199. output.write(line)
  200. line = triple(e1placeHolder,
  201. nsCoords.prefix + 'type',
  202. cidocCoords.prefix + 'E1_CRM_Entity') + closeLine
  203. output.write(line)
  204. line = triple(e1placeHolder,
  205. schemaCoords.prefix + 'label', '\"' +
  206. row['SGTI'] + '\"') + closeLine
  207. output.write(line)
  208. line = triple(e1placeHolder,
  209. cidocCoords.prefix + 'P2_has_type',
  210. '\"Identificazione Iconografica\"') + closeLine
  211. output.write(line)
  212. # Attention: these triples are identified only for C100005 Museo di Palazzo Pretorio
  213. if row['ESC'] == 'C100005':
  214. line = triple(datplaceHolder,
  215. cidocCoords.prefix + 'P52_has_current_owner',
  216. '<https://palazzopretorio.prato.it/it/>') + closeLine
  217. output.write(line)
  218. line = triple('<https://palazzopretorio.prato.it/it/>',
  219. nsCoords.prefix + 'type',
  220. cidocCoords.prefix + 'E74_Group') + closeLine
  221. output.write(line)
  222. line = triple('<https://palazzopretorio.prato.it/it/>',
  223. schemaCoords.prefix + 'label',
  224. '\"Museo di Palazzo Pretorio\"') + closeLine
  225. output.write(line)
  226. currentLocation = ''
  227. # E22 - P54 - E53
  228. if row['LDCN'] != '':
  229. if row['LDCS'] != '':
  230. currentLocation = row['LDCS']
  231. else:
  232. currentLocation = currentLocation
  233. if row['LDCM'] != '':
  234. currentLocation = currentLocation + ', ' + row['LDCM']
  235. else:
  236. currentLocation = currentLocation
  237. if row['LDCN'] != '':
  238. currentLocation = currentLocation + ', ' + row['LDCN']
  239. else:
  240. currentLocation = currentLocation
  241. currentLocation = currentLocation + ', ' + row['PVCC'] + ' (' + row['PVCP'] + ')'
  242. line = triple(datplaceHolder, cidocCoords.prefix + 'P54_has_current_permanent_location',
  243. '\"' + currentLocation + '\"') + closeLine
  244. output.write(line)
  245. e12FplaceHolder = ''
  246. if row['DTSI'] != row['DTSF']:
  247. e12FplaceHolder = museoCoords.prefix + url + '_E12F'
  248. # Write E12 Production -- should exist for every entry?
  249. # E12 P108 E22
  250. line = triple(e12placeHolder, cidocCoords.prefix + 'P108_has_produced', datplaceHolder) + closeLine
  251. output.write(line)
  252. line = triple(e12placeHolder, nsCoords.prefix + 'type', cidocCoords.prefix + 'E12_Production') + closeLine
  253. output.write(line)
  254. # E73 P108i E12
  255. line = triple(e73placeHolder, cidocCoords.prefix + 'P108i_was_produced_by', e12placeHolder) + closeLine
  256. output.write(line)
  257. if e12FplaceHolder != '':
  258. line = triple(e12FplaceHolder, cidocCoords.prefix + 'P108_has_produced', datplaceHolder) + closeLine
  259. output.write(line)
  260. line = triple(e12FplaceHolder, nsCoords.prefix + 'type',
  261. cidocCoords.prefix + 'E12_Production') + closeLine
  262. output.write(line)
  263. line = triple(e12FplaceHolder, schemaCoords.prefix + 'label',
  264. '\"Fine produzione di ' + row['SGTI'] + '\"') + closeLine
  265. output.write(line)
  266. # E73 P108i E12
  267. line = triple(e73placeHolder, cidocCoords.prefix + 'P108i_was_produced_by', e12FplaceHolder) + closeLine
  268. output.write(line)
  269. # E12 P140i E13
  270. line = triple(e12FplaceHolder,
  271. cidocCoords.prefix + 'P140i_was_attributed_by',
  272. e13placeHolder) + closeLine
  273. output.write(line)
  274. # E12 P2
  275. line = triple(e12FplaceHolder,
  276. cidocCoords.prefix + 'P2_has_type',
  277. '\"Fine\"^^xsd:string') + closeLine
  278. output.write(line)
  279. line = triple(e12placeHolder,
  280. cidocCoords.prefix + 'P2_has_type',
  281. '\"Inizio\"^^xsd:string') + closeLine
  282. output.write(line)
  283. line = triple(e12placeHolder, schemaCoords.prefix + 'label',
  284. '\"Inizio produzione di ' + row['SGTI'] + '\"') + closeLine
  285. output.write(line)
  286. else:
  287. line = triple(e12placeHolder, schemaCoords.prefix + 'label',
  288. '\"Produzione di ' + row['SGTI'] + '\"') + closeLine
  289. output.write(line)
  290. tcl = []
  291. for name in columnName:
  292. if 'TCL' in name:
  293. tcl.append(name)
  294. # E12 - P7 - E53
  295. for el in tcl:
  296. i = 0
  297. if row[el] == 'luogo di produzione':
  298. pl = ''
  299. if i == 0:
  300. pl = row['PRVC']
  301. else:
  302. pl = row['PRVC' + i]
  303. line = triple(e12placeHolder,
  304. cidocCoords.prefix + 'P7_took_place_at',
  305. museoCoords.prefix + pl) + closeLine
  306. output.write(line)
  307. if e12FplaceHolder != '':
  308. line = triple(e12FplaceHolder,
  309. cidocCoords.prefix + 'P7_took_place_at',
  310. museoCoords.prefix + pl) + closeLine
  311. output.write(line)
  312. i = i + 1
  313. # E12 - PC14 - E21
  314. if row['AUTH'] != '':
  315. aut = get_aut_url(row['AUTH'])
  316. aut_url = aut[0]
  317. aut_role = aut[1]
  318. ll = row['AUTN'] + '_' + aut_role
  319. lab = ll.replace(' ', '')
  320. label = lab.replace(',', '')
  321. AuthorPlaceholder = autCoords.prefix + str(aut)
  322. line = triple(museoCoords.prefix + '_' + label,
  323. cidocCoords.prefix + 'P01_has_domain',
  324. e12placeHolder) + closeLine
  325. output.write(line)
  326. if e12FplaceHolder != '':
  327. line = triple(museoCoords.prefix + '_' + label,
  328. cidocCoords.prefix + 'P01_has_domain',
  329. e12FplaceHolder) + closeLine
  330. output.write(line)
  331. if 'AUTH1' in columnName:
  332. if row['AUTH1'] != '':
  333. aut = get_aut_url(row['AUTH1'])
  334. aut_url = aut[0]
  335. aut_role = aut[1]
  336. ll = row['AUTN1'] + '_' + aut_role
  337. lab = ll.replace(' ', '')
  338. label = lab.replace(',', '')
  339. AuthorPlaceholder = autCoords.prefix + aut_url
  340. line = triple(museoCoords.prefix + '_' + label,
  341. cidocCoords.prefix + 'P01_has_domain',
  342. e12placeHolder) + closeLine
  343. output.write(line)
  344. if e12FplaceHolder != '':
  345. line = triple(museoCoords.prefix + '_' + label,
  346. cidocCoords.prefix + 'P01_has_domain',
  347. e12FplaceHolder) + closeLine
  348. output.write(line)
  349. # E12 - PC14 - E21
  350. if 'CMMN' in columnName:
  351. if row['CMMN'] != '':
  352. cc = row['CMMN']
  353. cm = cc.replace(' ', '')
  354. cmmn = cm.replace(',', '')
  355. cmmPlaceholder = museoCoords.prefix + '_' + cmmn
  356. line = triple(museoCoords.prefix + '_commit_' + cmmn,
  357. cidocCoords.prefix + 'P01_has_domain',
  358. e12placeHolder) + closeLine
  359. output.write(line)
  360. if e12FplaceHolder != '':
  361. line = triple(museoCoords.prefix + '_commit_' + cmmn,
  362. cidocCoords.prefix + 'P01_has_domain',
  363. e12FplaceHolder) + closeLine
  364. output.write(line)
  365. line = triple(museoCoords.prefix + '_commit_' + cmmn,
  366. nsCoords.prefix + 'type',
  367. cidocCoords.prefix + 'PC14_carried_out_by') + closeLine
  368. output.write(line)
  369. line = triple(museoCoords.prefix + '_commit_' + cmmn,
  370. schemaCoords.prefix + 'label',
  371. '\"' + row['CMMN'] + ' nel ruolo di committente\"') + closeLine
  372. output.write(line)
  373. line = triple(museoCoords.prefix + '_commit_' + cmmn,
  374. cidocCoords.prefix + 'P02_has_range',
  375. cmmPlaceholder) + closeLine
  376. output.write(line)
  377. line = triple(cmmPlaceholder,
  378. nsCoords.prefix + 'type',
  379. cidocCoords.prefix + 'E39_Actor') + closeLine
  380. output.write(line)
  381. line = triple(cmmPlaceholder,
  382. schemaCoords.prefix + 'label',
  383. '\"' + row['CMMN'] + '\"') + closeLine
  384. output.write(line)
  385. line = triple(museoCoords.prefix + '_commit_' + cmmn,
  386. cidocCoords.prefix + 'P14.1_in_the_role_of',
  387. museoCoords.prefix + '_client') + closeLine
  388. output.write(line)
  389. line = triple(museoCoords.prefix + '_client',
  390. nsCoords.prefix + 'type',
  391. cidocCoords.prefix + 'E55_Type') + closeLine
  392. output.write(line)
  393. line = triple(museoCoords.prefix + '_client',
  394. schemaCoords.prefix + 'label',
  395. '\"Committente\"') + closeLine
  396. output.write(line)
  397. # E12 - P4 - E52
  398. if row['DTSI'] != '':
  399. line = triple(e12placeHolder,
  400. cidocCoords.prefix + 'P4_has_time-span',
  401. museoCoords.prefix + row['DTSI']) + closeLine
  402. output.write(line)
  403. line = triple(museoCoords.prefix + row['DTSI'],
  404. nsCoords.prefix + 'type',
  405. cidocCoords.prefix + 'E52_Time-Span') + closeLine
  406. output.write(line)
  407. line = triple(museoCoords.prefix + row['DTSI'],
  408. schemaCoords.prefix + 'label',
  409. '\"' + row['DTSI'] + '\"') + closeLine
  410. output.write(line)
  411. if e12FplaceHolder != '':
  412. line = triple(e12FplaceHolder,
  413. cidocCoords.prefix + 'P4_has_time-span',
  414. museoCoords.prefix + row['DTSF']) + closeLine
  415. output.write(line)
  416. line = triple(museoCoords.prefix + row['DTSF'],
  417. nsCoords.prefix + 'type',
  418. cidocCoords.prefix + 'E52_Time-Span') + closeLine
  419. output.write(line)
  420. line = triple(museoCoords.prefix + row['DTSF'],
  421. schemaCoords.prefix + 'label',
  422. '\"' + row['DTSF'] + '\"') + closeLine
  423. output.write(line)
  424. tcl = []
  425. for name in columnName:
  426. if 'TCL' in name:
  427. tcl.append(name)
  428. j = 0
  429. for el in tcl:
  430. if row[el] != '':
  431. j = j + 1
  432. last = str(j - 1)
  433. n = len(tcl) - 1
  434. for i in range(n):
  435. k = str(i + 1)
  436. if i + 1 == 1:
  437. w = ''
  438. else:
  439. w = i
  440. f = str(w)
  441. if row['TCL' + k] != '':
  442. pastActor = ''
  443. newActor = ''
  444. pl = ''
  445. if row['PRCD' + k] != '':
  446. newActor = ' a ' + row['PRCD' + k]
  447. if row['PRCD' + f] != '':
  448. pastActor = ' da ' + row['PRCD' + f]
  449. pl = row['PRCD' + f].replace(' ', '')
  450. newe10placeHolder = museoCoords.prefix + url + "_E10_" + k
  451. line = triple(newe10placeHolder,
  452. cidocCoords.prefix + 'P30_transferred_custody_of',
  453. datplaceHolder) + closeLine
  454. output.write(line)
  455. line = triple(newe10placeHolder,
  456. nsCoords.prefix + 'type',
  457. cidocCoords.prefix + 'E10_Transfer_of_Custody') + closeLine
  458. output.write(line)
  459. line = triple(newe10placeHolder,
  460. schemaCoords.prefix + 'label',
  461. '\"Passaggio di ' + row['SGTI'] + pastActor +
  462. newActor + '\"') + closeLine
  463. output.write(line)
  464. if row['PRDI' + f] != '':
  465. timespan = row['PRDI' + f]
  466. tt = timespan.replace(' ', '')
  467. tp = tt.replace('.', '')
  468. ts = tp.replace('/', '')
  469. timespanPlaceholder = museoCoords.prefix + '_' + ts
  470. # E10 P4 E52
  471. line = triple(newe10placeHolder,
  472. cidocCoords.prefix + 'P4_has_time-span',
  473. timespanPlaceholder) + closeLine
  474. output.write(line)
  475. line = triple(timespanPlaceholder,
  476. nsCoords.prefix + 'type',
  477. cidocCoords.prefix + 'E52_Time-Span') + closeLine
  478. output.write(line)
  479. line = triple(timespanPlaceholder,
  480. schemaCoords.prefix + 'label',
  481. '\"' + timespan + '\"') + closeLine
  482. output.write(line)
  483. pastActorPlaceholder = museoCoords.prefix + '_' + pl
  484. newLoc = row['PRCD' + k].replace(' ', '')
  485. newActorPlaceholder = museoCoords.prefix + '_' + newLoc
  486. # E10 P26 E74 (moved to)
  487. if newActorPlaceholder != '':
  488. line = triple(newe10placeHolder,
  489. cidocCoords.prefix + 'P29_custody_received_by',
  490. newActorPlaceholder) + closeLine
  491. output.write(line)
  492. # E10 P27 E74
  493. pastActorLabel = row['PRCD' + f]
  494. line = triple(newe10placeHolder,
  495. cidocCoords.prefix + 'P28_custody_surrendered_by',
  496. pastActorPlaceholder) + closeLine
  497. output.write(line)
  498. line = triple(pastActorPlaceholder,
  499. nsCoords.prefix + 'type',
  500. cidocCoords.prefix + 'E39_Actor') + closeLine
  501. output.write(line)
  502. line = triple(pastActorPlaceholder,
  503. schemaCoords.prefix + 'label',
  504. '\"' + pastActorLabel + '\"') + closeLine
  505. output.write(line)
  506. line = triple(datplaceHolder,
  507. cidocCoords.prefix + 'P49_has_former_or_current_keeper',
  508. pastActorPlaceholder) + closeLine
  509. output.write(line)
  510. # E74 P74 E53
  511. pastResidenceLabel = row['PRVC' + f]
  512. pastResidencePlaceHolder = museoCoords.prefix + row['PRVC' + f]
  513. line = triple(pastActorPlaceholder,
  514. cidocCoords.prefix + 'P74_has_current_or_former_residence',
  515. pastResidencePlaceHolder) + closeLine
  516. output.write(line)
  517. ####
  518. pastActor = ''
  519. newActor = ''
  520. pl = ''
  521. if row['LDCN'] != '':
  522. newActor = ' a ' + row['LDCN']
  523. if row['PRCD' + last] != '':
  524. pastActor = ' da ' + row['PRCD' + last]
  525. pl = row['PRCD' + last].replace(' ', '')
  526. line = triple(e10placeHolder,
  527. cidocCoords.prefix + 'P30_transferred_custody_of',
  528. datplaceHolder) + closeLine
  529. output.write(line)
  530. line = triple(e10placeHolder,
  531. nsCoords.prefix + 'type',
  532. cidocCoords.prefix + 'E10_Transfer_of_Custody') + closeLine
  533. output.write(line)
  534. line = triple(e10placeHolder,
  535. schemaCoords.prefix + 'label',
  536. '\"Passaggio di ' + row['SGTI'] + pastActor +
  537. newActor + '\"') + closeLine
  538. output.write(line)
  539. if row['PRDU' + last] != '':
  540. timespan = row['PRDU' + last]
  541. tt = timespan.replace(' ', '')
  542. ts = tt.replace('/', '')
  543. timespanPlaceholder = museoCoords.prefix + '_' + ts
  544. # E10 P4 E52
  545. line = triple(e10placeHolder,
  546. cidocCoords.prefix + 'P4_has_time-span',
  547. timespanPlaceholder) + closeLine
  548. output.write(line)
  549. line = triple(timespanPlaceholder,
  550. nsCoords.prefix + 'type',
  551. cidocCoords.prefix + 'E52_Time-Span') + closeLine
  552. output.write(line)
  553. line = triple(timespanPlaceholder,
  554. schemaCoords.prefix + 'label',
  555. '\"' + timespan + '\"') + closeLine
  556. output.write(line)
  557. pastActorPlaceholder = museoCoords.prefix + '_' + pl
  558. newLocPlaceholder = e74placeHolder
  559. # E10 P26 E74 (moved to)
  560. if newLocPlaceholder != '':
  561. line = triple(e10placeHolder,
  562. cidocCoords.prefix + 'P29_custody_received_by',
  563. newLocPlaceholder) + closeLine
  564. output.write(line)
  565. # E10 P27 E74
  566. pastActorLabel = row['PRCD' + last]
  567. line = triple(e10placeHolder,
  568. cidocCoords.prefix + 'P28_custody_surrendered_by',
  569. pastActorPlaceholder) + closeLine
  570. output.write(line)
  571. line = triple(pastActorPlaceholder,
  572. nsCoords.prefix + 'type',
  573. cidocCoords.prefix + 'E39_Actor') + closeLine
  574. output.write(line)
  575. line = triple(pastActorPlaceholder,
  576. schemaCoords.prefix + 'label',
  577. '\"' + pastActorLabel + '\"') + closeLine
  578. output.write(line)
  579. line = triple(datplaceHolder,
  580. cidocCoords.prefix + 'P49_has_former_or_current_keeper',
  581. pastActorPlaceholder) + closeLine
  582. output.write(line)
  583. # E74 P74 E53
  584. pastResidenceLabel = row['PRVC' + last]
  585. pastResidencePlaceHolder = museoCoords.prefix + row['PRVC' + last]
  586. if row['PRVP' + last] != '':
  587. pastResidenceLabel = pastResidenceLabel + ' (' + row['PRVP' + last] + ')'
  588. if row['PRVR' + last] != '':
  589. pastResidenceLabel = pastResidenceLabel + ', ' + row['PRVR' + last]
  590. if row['PRVS' + last] != '':
  591. pastResidenceLabel = pastResidenceLabel + ', ' + row['PRVS' + last]
  592. line = triple(pastActorPlaceholder,
  593. cidocCoords.prefix + 'P74_has_current_or_former_residence',
  594. pastResidencePlaceHolder) + closeLine
  595. output.write(line)
  596. line = triple(pastResidencePlaceHolder,
  597. nsCoords.prefix + 'type',
  598. cidocCoords.prefix + 'E53_Place') + closeLine
  599. output.write(line)
  600. # E22 P44 E3
  601. if row['STCC'] != '':
  602. line = triple(datplaceHolder,
  603. cidocCoords.prefix + 'P44_has_condition',
  604. e3placeHolder) + closeLine
  605. output.write(line)
  606. line = triple(e3placeHolder,
  607. nsCoords.prefix + 'type',
  608. cidocCoords.prefix + 'E3_Condition_State') + closeLine
  609. output.write(line)
  610. line = triple(e3placeHolder,
  611. schemaCoords.prefix + 'label',
  612. '\"Condizione di: ' + row['SGTI'] + '\"') + closeLine
  613. output.write(line)
  614. line = triple(e3placeHolder,
  615. cidocCoords.prefix + 'P2_has_type',
  616. '\"' + row['STCC'] + '\"') + closeLine
  617. output.write(line)
  618. # E22 P65 E34
  619. if (row['ISRI'] != ''):
  620. line = triple(datplaceHolder,
  621. cidocCoords.prefix + 'P56_bears_feature',
  622. e25placeHolder) + closeLine
  623. output.write(line)
  624. line = triple(e25placeHolder,
  625. nsCoords.prefix + 'type',
  626. cidocCoords.prefix + 'E25_Man-Made_Feature') + closeLine
  627. output.write(line)
  628. line = triple(e25placeHolder,
  629. schemaCoords.prefix + 'label',
  630. '\"Iscrizione su ' + subj + '\"') + closeLine
  631. output.write(line)
  632. line = triple(e25placeHolder,
  633. cidocCoords.prefix + 'P128_carries',
  634. e34placeHolder) + closeLine
  635. output.write(line)
  636. line = triple(e34placeHolder,
  637. nsCoords.prefix + 'type',
  638. cidocCoords.prefix + 'E34_Inscription') + closeLine
  639. output.write(line)
  640. line = triple(e34placeHolder,
  641. schemaCoords.prefix + 'label',
  642. '\"Iscrizione: ' + row['ISRI'] + '\"') + closeLine
  643. output.write(line)
  644. pl = row['ISRI'].replace(' ', '-')
  645. pla = pl.replace('.', '')
  646. line = triple(e34placeHolder,
  647. cidocCoords.prefix + 'P3_has_note',
  648. '\"' + row['ISRI'] + '\"') + closeLine
  649. output.write(line)
  650. # E34 P2 E55
  651. if (row['ISRT'] != ''):
  652. rr = row['ISRT'].replace(' ', '')
  653. line = triple(e34placeHolder,
  654. cidocCoords.prefix + 'P2_has_type',
  655. '\"' + row['ISRT'] + '\"') + closeLine
  656. output.write(line)
  657. # E34 P72 E56
  658. if (row['ISRL'] != ''):
  659. line = triple(e34placeHolder,
  660. cidocCoords.prefix + 'P72_has_language',
  661. museoCoords.prefix + '_' + row['ISRL']) + closeLine
  662. output.write(line)
  663. line = triple(museoCoords.prefix + '_' + row['ISRL'],
  664. nsCoords.prefix + 'type',
  665. cidocCoords.prefix + 'E56_Language') + closeLine
  666. output.write(line)
  667. line = triple(museoCoords.prefix + '_' + row['ISRL'],
  668. schemaCoords.prefix + 'label',
  669. '\"' + row['ISRL'] + '\"') + closeLine
  670. output.write(line)
  671. if row['ISRS'] != '':
  672. line = triple(e34placeHolder,
  673. cidocCoords.prefix + 'P92i_was_brought_into_existence_by',
  674. e65placeHolder) + closeLine
  675. output.write(line)
  676. line = triple(e65placeHolder,
  677. nsCoords.prefix + 'type',
  678. cidocCoords.prefix + 'E65_Creation') + closeLine
  679. output.write(line)
  680. line = triple(e65placeHolder,
  681. schemaCoords.prefix + 'label',
  682. '\"Creazione dell\'Iscrizione ' + row['ISRI'] + '\"') + closeLine
  683. output.write(line)
  684. if row['ISRS']:
  685. ss = row['ISRS'].replace(' ', '')
  686. tecPlaceholder = museoCoords.prefix + url + '_' + ss
  687. line = triple(e65placeHolder,
  688. cidocCoords.prefix + 'P32_used_general_technique',
  689. tecPlaceholder) + closeLine
  690. output.write(line)
  691. line = triple(tecPlaceholder,
  692. nsCoords.prefix + 'type',
  693. cidocCoords.prefix + 'E55_Type') + closeLine
  694. output.write(line)
  695. line = triple(tecPlaceholder,
  696. schemaCoords.prefix + 'label',
  697. '\"' + row['ISRS'] + '\"') + closeLine
  698. output.write(line)
  699. if row['ISRP'] != '':
  700. line = triple(e25placeHolder,
  701. cidocCoords.prefix + 'P3_has_note',
  702. '\"' + row['ISRP'] + '\"^^xsd:string') + closeLine
  703. output.write(line)
  704. unit = ''
  705. if (row['MISU'] != ''):
  706. unit = row['MISU']
  707. valueA = ''
  708. valueL = ''
  709. if (row['MISA'] != ''):
  710. value = row['MISA']
  711. valueA = value.replace(',', 'v')
  712. if (row['MISL'] != ''):
  713. value = row['MISL']
  714. valueL = value.replace(',', 'v')
  715. # Altezza
  716. # E22 P43 E54
  717. if (row['MISA'] != ''):
  718. line = triple(datplaceHolder,
  719. cidocCoords.prefix + 'P43_has_dimension',
  720. museoCoords.prefix + url + '_Altezza') + closeLine
  721. output.write(line)
  722. line = triple(museoCoords.prefix + url + '_Altezza',
  723. nsCoords.prefix + 'type',
  724. cidocCoords.prefix + 'E54_Dimension') + closeLine
  725. output.write(line)
  726. line = triple(museoCoords.prefix + url + '_Altezza',
  727. schemaCoords.prefix + 'label',
  728. '\"Altezza: ' + row['MISA'] + row['MISU'] + '\"') + closeLine
  729. output.write(line)
  730. # E54 P90 E60
  731. line = triple(museoCoords.prefix + url + '_Altezza',
  732. cidocCoords.prefix + 'P90_has_value',
  733. '\"' + row['MISA'] + '\"^^xsd:integer') + closeLine
  734. output.write(line)
  735. # E54 P2 E55
  736. line = triple(museoCoords.prefix + url + '_Altezza',
  737. cidocCoords.prefix + 'P2_has_type',
  738. aatCoords.prefix + '300055644') + closeLine
  739. output.write(line)
  740. line = triple(aatCoords.prefix + '300055644',
  741. schemaCoords.prefix + 'label',
  742. '\"altezza\"') + closeLine
  743. output.write(line)
  744. # E54 P91 E58
  745. if (row['MISU'] != ''):
  746. line = triple(museoCoords.prefix + url + '_Altezza',
  747. cidocCoords.prefix + 'P91_has_unit',
  748. aatCoords.prefix + '300379098') + closeLine
  749. output.write(line)
  750. line = triple(aatCoords.prefix + '300379098',
  751. nsCoords.prefix + 'type',
  752. cidocCoords.prefix + 'E58_Measurement_Unit') + closeLine
  753. output.write(line)
  754. line = triple(aatCoords.prefix + '300379098',
  755. schemaCoords.prefix + 'label',
  756. '\"' + row['MISU'] + '\"') + closeLine
  757. output.write(line)
  758. # Larghezza
  759. # E22 P43 E54
  760. if (row['MISL'] != ''):
  761. line = triple(datplaceHolder,
  762. cidocCoords.prefix + 'P43_has_dimension',
  763. museoCoords.prefix + url + '_Larghezza') + closeLine
  764. output.write(line)
  765. line = triple(museoCoords.prefix + url + '_Larghezza',
  766. nsCoords.prefix + 'type',
  767. cidocCoords.prefix + 'E54_Dimension') + closeLine
  768. output.write(line)
  769. line = triple(museoCoords.prefix + url + '_Larghezza',
  770. schemaCoords.prefix + 'label',
  771. '\"Larghezza: ' + row['MISL'] + row['MISU'] + '\"') + closeLine
  772. output.write(line)
  773. # E54 P90 E60
  774. line = triple(museoCoords.prefix + url + '_Larghezza',
  775. cidocCoords.prefix + 'P90_has_value',
  776. '\"' + row['MISL'] + '\"^^xsd:integer') + closeLine
  777. output.write(line)
  778. # E54 P2 E55
  779. line = triple(museoCoords.prefix + url + '_Larghezza',
  780. cidocCoords.prefix + 'P2_has_type',
  781. aatCoords.prefix + '300055647') + closeLine
  782. output.write(line)
  783. line = triple(aatCoords.prefix + '300055647',
  784. schemaCoords.prefix + 'label',
  785. '\"larghezza\"') + closeLine
  786. output.write(line)
  787. # E54 P91 E58
  788. if (row['MISU'] != ''):
  789. line = triple(museoCoords.prefix + url + '_Larghezza',
  790. cidocCoords.prefix + 'P91_has_unit',
  791. aatCoords.prefix + '300379098') + closeLine
  792. output.write(line)
  793. line = triple(aatCoords.prefix + '300379098',
  794. nsCoords.prefix + 'type',
  795. cidocCoords.prefix + 'E58_Measurement_Unit') + closeLine
  796. output.write(line)
  797. line = triple(aatCoords.prefix + '300379098',
  798. schemaCoords.prefix + 'label',
  799. '\"' + row['MISU'] + '\"') + closeLine
  800. output.write(line)
  801. # if row['MTC'] != '':
  802. # mtcs = []
  803. # if '/' in row['MTC']:
  804. # mtcs = row['MTC'].split('/')
  805. # else:
  806. # mtcs.append(row['MTC'])
  807. # for tc in mtcs:
  808. # mtc = tc.lstrip()
  809. # el = get_elem(mtc)
  810. # if (el[1] == 'MTC/M'):
  811. # line = triple(datplaceHolder,
  812. # cidocCoords.prefix + 'P45_consists_of',
  813. # aatCoords.prefix + el[0]) + closeLine
  814. # output.write(line)
  815. # line = triple(aatCoords.prefix + el[0],
  816. # nsCoords.prefix + 'type',
  817. # cidocCoords.prefix + 'E57_Material') + closeLine
  818. # output.write(line)
  819. # line = triple(aatCoords.prefix + el[0],
  820. # schemaCoords.prefix + 'label',
  821. # '\"' + mtc + '\"') + closeLine
  822. # output.write(line)
  823. # else: #E12 Production - P32 used technique - E55 Type
  824. # line = triple(e12placeHolder,
  825. # cidocCoords.prefix + 'P32_used_general_technique',
  826. # aatCoords.prefix + el[0]) + closeLine
  827. # output.write(line)
  828. # if e12FplaceHolder != '':
  829. # line = triple(e12FplaceHolder,
  830. # cidocCoords.prefix + 'P32_used_general_technique',
  831. # aatCoords.prefix + el[0]) + closeLine
  832. # output.write(line)
  833. # line = triple(aatCoords.prefix + el[0],
  834. # nsCoords.prefix + 'type',
  835. # cidocCoords.prefix + 'E55_Type') + closeLine
  836. # output.write(line)
  837. # line = triple(aatCoords.prefix + el[0],
  838. # schemaCoords.prefix + 'label',
  839. # '\"' + mtc + '\"') + closeLine
  840. # output.write(line)
  841. if row['MTC'] != '':
  842. mtcs = []
  843. if '/' in row['MTC']:
  844. mtcs = row['MTC'].split('/')
  845. else:
  846. mtcs.append(row['MTC'])
  847. for tc in mtcs:
  848. mtc = tc.lstrip()
  849. el = get_elem(mtc)
  850. if el[1] == 'MTC/M':
  851. line = triple(datplaceHolder,
  852. cidocCoords.prefix + 'P45_consists_of',
  853. aatCoords.prefix + el[0]) + closeLine
  854. output.write(line)
  855. line = triple(aatCoords.prefix + el[0],
  856. nsCoords.prefix + 'type',
  857. cidocCoords.prefix + 'E57_Material') + closeLine
  858. output.write(line)
  859. line = triple(aatCoords.prefix + el[0],
  860. schemaCoords.prefix + 'label',
  861. '\"' + mtc + '\"') + closeLine
  862. output.write(line)
  863. else: #E12 Production - P32 used technique - E55 Type
  864. line = triple(e12placeHolder,
  865. cidocCoords.prefix + 'P32_used_general_technique',
  866. aatCoords.prefix + el[0]) + closeLine
  867. output.write(line)
  868. if e12FplaceHolder != '':
  869. line = triple(e12FplaceHolder,
  870. cidocCoords.prefix + 'P32_used_general_technique',
  871. aatCoords.prefix + el[0]) + closeLine
  872. output.write(line)
  873. line = triple(aatCoords.prefix + el[0],
  874. nsCoords.prefix + 'type',
  875. cidocCoords.prefix + 'E55_Type') + closeLine
  876. output.write(line)
  877. line = triple(aatCoords.prefix + el[0],
  878. schemaCoords.prefix + 'label',
  879. '\"' + mtc + '\"') + closeLine
  880. output.write(line)
  881. # E12 P140i E13
  882. if row['AUTM'] != '':
  883. mot = row['AUTM'].replace(' ', '_')
  884. e55placeHolder = museoCoords.prefix + url + '_' + mot
  885. line = triple(e12placeHolder,
  886. cidocCoords.prefix + 'P140i_was_attributed_by',
  887. e13placeHolder) + closeLine
  888. output.write(line)
  889. line = triple(e13placeHolder,
  890. nsCoords.prefix + 'type',
  891. cidocCoords.prefix + 'E13_Attribute_Assignment') + closeLine
  892. output.write(line)
  893. line = triple(e13placeHolder,
  894. schemaCoords.prefix + 'label',
  895. '\"Motivazione attribuzione\"') + closeLine
  896. output.write(line)
  897. line = triple(e13placeHolder,
  898. cidocCoords.prefix + 'P2_has_type',
  899. '\"' + row['AUTM'] + '\"') + closeLine
  900. output.write(line)
  901. aut = get_aut_url(row['AUTH'])
  902. aut_url = aut[0]
  903. AuthorPlaceholder = autCoords.prefix + aut_url
  904. line = triple(e13placeHolder,
  905. cidocCoords.prefix + 'P141_assigned',
  906. AuthorPlaceholder) + closeLine
  907. output.write(line)
  908. # E22 P44 E62
  909. if row['NSC'] != '':
  910. ph = row['NSC'].replace(' "', ' «')
  911. phr = ph.replace('"', '»')
  912. line = triple(datplaceHolder,
  913. cidocCoords.prefix + 'P3_has_note',
  914. '\"' + phr + '\"^^xsd:string') + closeLine
  915. output.write(line)
  916. iconclass = row['DESI']
  917. icon = iconclass.replace(' ', '')
  918. list_icon = []
  919. if ':' in icon:
  920. list_icon = icon.split(':')
  921. else:
  922. list_icon.append(icon)
  923. for ic in list_icon:
  924. siglaiconclass = str(ic)
  925. #url = 'http://iconclass.org/rdk/' + str(ic)
  926. #html = urlopen(url).read()
  927. #soup = BeautifulSoup(html, 'html.parser')
  928. # kill all script and style elements
  929. #for script in soup(["script", "style"]):
  930. # script.extract() # rip it out
  931. # get text
  932. #text = soup.get_text()
  933. #pretty = soup.prettify()
  934. #ff = soup.find("div", {"id": "ic_current"})
  935. #dd = ff.find("a", {"class", "ic_notation"})
  936. #ss = dd.text
  937. #x = ss.find(' ')
  938. #icon_label = ss[x + 1:]
  939. siglaiconclass = ic.replace("%28", "(",)
  940. siglaiconclassok = siglaiconclass.replace("%29", ")")
  941. siglaiconclassokplaceHolder = '<https://iconclass.org/' + siglaiconclassok + '>'
  942. line = triple(datplaceHolder,
  943. cidocCoords.prefix + 'P62_depicts',
  944. siglaiconclassokplaceHolder) + closeLine
  945. output.write(line)
  946. line = triple(siglaiconclassokplaceHolder,
  947. nsCoords.prefix + 'type',
  948. cidocCoords.prefix + 'E1_CRM_Entity') + closeLine
  949. output.write(line)
  950. line = triple(siglaiconclassokplaceHolder,
  951. schemaCoords.prefix + 'label',
  952. '\"' + siglaiconclassok + '\"' ) + closeLine
  953. output.write(line)
  954. line = triple(siglaiconclassokplaceHolder,
  955. cidocCoords.prefix + 'P2_has_type',
  956. '\"Sigla Iconclass\"') + closeLine
  957. output.write(line)
  958. datiniplaceHolder = '<http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/IT-ASPO-AU00003-0001806>'
  959. line = triple(datplaceHolder,
  960. cidocCoords.prefix + 'P62_depicts',
  961. datiniplaceHolder) + closeLine
  962. output.write(line)
  963. # P2 Opera d'arte
  964. line = triple(datplaceHolder,
  965. cidocCoords.prefix + 'P2_has_type',
  966. '\"Opera d\'Arte\"') + closeLine
  967. output.write(line)
  968. output.write('\n')
  969. #
  970. #
  971. # Limit number of entries processed (if desired)
  972. if (ii > max_entries):
  973. break