OA.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  2. thisUrlParams = {};
  3. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. thisUrlParams[key] = value;
  5. });
  6. console.log('URL get params: ', thisUrlParams);
  7. // Funzioni per eseguire le queries
  8. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. function doJsonQuery(query){
  14. queryURL = prepareQueryURL(query);
  15. response = $.ajax({//OGGETTO
  16. url: queryURL,
  17. dataType: "json",
  18. success: function (data){},
  19. error: function (e) {}
  20. });
  21. return response;
  22. }
  23. // Funzioni per raccattare + stringhificare l'output
  24. queryStringOutput = "";
  25. function stringifyResponse(val){
  26. resultArray = val['results']['bindings'];
  27. out = "";
  28. for(i = 0; i < resultArray.length; i++){
  29. out = out + JSON.stringify(resultArray[i])
  30. }
  31. queryStringOutput = (queryStringOutput + out).replace("}{",",");
  32. }
  33. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  34. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  35. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  36. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  37. PREFIX schema: <http://schema.org/> \
  38. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  39. PREFIX person: <http://www.w3.org/ns/person#>"
  40. queryInfo = prefixes + " SELECT DISTINCT ?graph ?identifier ?label ?title ?uriType ?type ?uriOwner ?current_owner ?current_location ?subject (group_concat(distinct ?value ; separator='x') as ?dimensions) SAMPLE(?unit) AS ?unit (GROUP_CONCAT(DISTINCT CONCAT(?uriMaterial, '; ', ?material) ; SEPARATOR = '<br />') AS ?Materials) ?condition ?note \
  41. WHERE { \
  42. VALUES ?uri {<" + thisUrlParams.link + ">} \
  43. GRAPH ?graph {?uri rdfs:label ?label} \
  44. OPTIONAL {?uri crm:P3_has_note ?note } \
  45. ?uri crm:P128_carries ?Inf_Obj . \
  46. OPTIONAL {?Inf_Obj crm:P1_is_identified_by ?uriTitle . \
  47. ?uriTitle rdf:type crm:E35_Title; \
  48. rdfs:label ?title } \
  49. OPTIONAL {?Inf_Obj crm:P2_has_type ?uriType . \
  50. ?uriType rdfs:label ?type } \
  51. OPTIONAL {?uri crm:P43_has_dimension ?uriDimension . \
  52. ?uriDimension crm:P90_has_value ?value; \
  53. crm:P91_has_unit ?uri_unit . \
  54. ?uri_unit rdfs:label ?unit } \
  55. OPTIONAL {?uri crm:P1_is_identified_by ?uriIdentifier . \
  56. ?uriIdentifier rdfs:label ?identifier } \
  57. OPTIONAL {?uri crm:P45_consists_of ?uriMaterial . \
  58. ?uriMaterial rdfs:label ?material } \
  59. OPTIONAL {?uri crm:P44_has_condition ?uriCondition . \
  60. ?uriCondition crm:P2_has_type ?condition} \
  61. OPTIONAL {?uri crm:P54_has_current_permanent_location ?current_location } \
  62. OPTIONAL {?uri crm:P62_depicts ?uriSubject . \
  63. ?uriSubject rdfs:label ?subject; \
  64. crm:P2_has_type 'Identificazione Iconografica' .} \
  65. OPTIONAL {?uri crm:P52_has_current_owner ?uriOwner . \
  66. ?uriOwner rdfs:label ?current_owner } \
  67. }"
  68. queryProduction = prefixes + " SELECT DISTINCT (GROUP_CONCAT(DISTINCT CONCAT(?uriPerson, '; ', ?person, '; ', ?role) ; SEPARATOR = '<br />') AS ?Partecipants) (group_concat(distinct ?time_span ;separator='-') as ?time) (GROUP_CONCAT(DISTINCT CONCAT(?uriTecne, '; ', ?technique) ; SEPARATOR = '<br />') AS ?techniques) \
  69. WHERE { \
  70. VALUES ?uri {<" + thisUrlParams.link + ">} \
  71. ?uri crm:P128_carries ?Information_Object . \
  72. ?Information_Object crm:P108i_was_produced_by ?Production . \
  73. OPTIONAL {?Production crm:P4_has_time-span ?uriTS ; \
  74. crm:P32_used_general_technique ?uriTecne . \
  75. ?uriTS rdfs:label ?time_span . \
  76. ?uriTecne rdfs:label ?technique} \
  77. OPTIONAL {?pc crm:P01_has_domain ?Production ; \
  78. crm:P02_has_range ?uriPerson ; \
  79. crm:P14.1_in_the_role_of ?uriRole . \
  80. ?uriPerson rdfs:label ?person . \
  81. ?uriRole rdfs:label ?role} \
  82. }"
  83. queryURL = prepareQueryURL(queryInfo);
  84. queryPro = prepareQueryURL(queryProduction);
  85. response = $.ajax({
  86. url: queryURL,
  87. dataType: "json",
  88. success: function (data){
  89. handle_OAdata(data);
  90. },
  91. error: function (e) {}
  92. });
  93. response_Pro = $.ajax({
  94. url: queryPro,
  95. dataType: "json",
  96. success: function (data){
  97. handle_Production(data);
  98. },
  99. error: function (e) {}
  100. });
  101. function handle_OAdata(json) {
  102. console.log(json['results']['bindings']);
  103. $.each(
  104. json['results']['bindings'],
  105. function (index, value) {
  106. var graph = value['graph']['value'];
  107. var label = value['label']['value'];
  108. var title = "";
  109. var type = "";
  110. var current_owner = "";
  111. var current_location = "";
  112. var subject = "";
  113. var dimensions = "";
  114. var materials = "";
  115. var condition = "";
  116. var note = "";
  117. var identifier = "";
  118. var unit = "";
  119. var dataset = get_dataset_name(graph);
  120. if (value.hasOwnProperty('title')) {
  121. $("#SGTT").css("display", "flex");
  122. title = value['title']['value'];
  123. }
  124. if (value.hasOwnProperty('identifier')) {
  125. $("#NCT").css("display", "flex");
  126. identifier = value['identifier']['value'];
  127. }
  128. if (value.hasOwnProperty('type')) {
  129. $("#OGTD").css("display", "flex");
  130. type = "<div class='d-flex'><div class='mr-3'>" +
  131. value['type']['value'] + "</div><div class='d-flex ml-auto'><div class='mr-3'><a class='btn-icon' target='_blank' href='" +
  132. value['uriType']['value'] + "'><i class='fa fa-bullseye' aria-hidden='true'></i><p class='btn-text'>AAT</p></a></div></div></div></div>";
  133. }
  134. if (value.hasOwnProperty('current_owner')) {
  135. $("#LDCN").css("display", "flex");
  136. current_owner = "<div class='d-flex'><div class='mr-3'>" +
  137. value['current_owner']['value'] + "</div><div class='d-flex ml-auto'><div class='mr-3'><a class='btn-icon' target='_blank' href='" +
  138. value['uriOwner']['value'] + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i><p class='btn-text'>LINK</p></a></div></div></div></div>";
  139. }
  140. if (value.hasOwnProperty('current_location')) {
  141. $("#LDCS").css("display", "flex");
  142. current_location = value['current_location']['value'];
  143. }
  144. if (value.hasOwnProperty('unit')) {
  145. unit = value['unit']['value'];
  146. }
  147. if (value.hasOwnProperty('subject')) {
  148. $("#SGTI").css("display", "flex");
  149. subject = value['subject']['value'];
  150. }
  151. if (value.hasOwnProperty('dimensions')) {
  152. if (value['dimensions']['value'] != "") {
  153. $("#MIS").css("display", "flex");
  154. dimensions = value['dimensions']['value'];
  155. }
  156. }
  157. if (value.hasOwnProperty('condition')) {
  158. $("#STCC").css("display", "flex");
  159. condition = value['condition']['value'];
  160. }
  161. if (value.hasOwnProperty('note')) {
  162. $("#NSC").css("display", "flex");
  163. note = value['note']['value'];
  164. }
  165. if (value.hasOwnProperty('Materials')) {
  166. if (value['Materials']['value'] != "") {
  167. $("#MTC").css("display", "flex");
  168. mm = value['Materials']['value'];
  169. mat = mm.split("<br />");
  170. for (i in mat) {
  171. slice = mat[i].split("; ");
  172. /*materials += "<a href='" + slice[0] + "'>" + slice[1] + "</a><br />";*/
  173. materials += "<div class='d-flex'><div class='mr-3'>" +
  174. slice[1] + "</div><div class='d-flex ml-auto'><div class='mr-3'><a class='btn-icon' target='_blank' href='" +
  175. slice[0] + "'><i class='fa fa-bullseye' aria-hidden='true'></i><p class='btn-text'>AAT</p></a></div></div></div></div>";
  176. }
  177. }
  178. }
  179. document.getElementById("grafo").innerHTML = dataset;
  180. document.getElementById("nome_oggetto").innerHTML = label;
  181. /*document.getElementById("title").innerHTML = title;*/
  182. document.getElementById("identifier").innerHTML = identifier;
  183. document.getElementById("type").innerHTML = type;
  184. document.getElementById("owner").innerHTML = current_owner;
  185. /*document.getElementById("location").innerHTML = current_location;*/
  186. document.getElementById("subject").innerHTML = subject;
  187. document.getElementById("dimensions").innerHTML = dimensions + unit;
  188. document.getElementById("materials").innerHTML = materials;
  189. document.getElementById("condition").innerHTML = condition;
  190. document.getElementById("description").innerHTML = note;
  191. });
  192. }
  193. function get_dataset_name(graph) {
  194. var string = "Scheda Opera d'Arte";
  195. if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/martini") {
  196. string = string + " / Collezione Martini";
  197. }
  198. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale") {
  199. string = string + " / Collezione Ospedale";
  200. }
  201. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/datini") {
  202. string = string + " / Collezione Datini";
  203. }
  204. else {
  205. string = string;
  206. }
  207. return (string);
  208. }
  209. function handle_Production(json) {
  210. console.log(json['results']['bindings']);
  211. $.each(
  212. json['results']['bindings'],
  213. function (index, value) {
  214. var partecipants = "";
  215. var teche = "";
  216. var time = "";
  217. var client = "";
  218. var artist = "";
  219. var artist_name = "";
  220. if (value.hasOwnProperty('techniques')) {
  221. if (value['techniques']['value'] != "") {
  222. $("#MTC").css("display", "flex");
  223. tt = value['techniques']['value'];
  224. tec = tt.split("<br />");
  225. for (i in tec) {
  226. slice = tec[i].split("; ");
  227. /*teche += "<a href='" + slice[0] + "'>" + slice[1] + "</a><br />";*/
  228. teche += "<div class='d-flex'><div class='mr-3'>" +
  229. slice[1] + "</div><div class='d-flex ml-auto'><div class='mr-3'><a class='btn-icon' target='_blank' href='" +
  230. slice[0] + "'><i class='fa fa-bullseye' aria-hidden='true'></i><p class='btn-text'>AAT</p></a></div></div></div></div>";
  231. }
  232. }
  233. }
  234. if (value.hasOwnProperty('Partecipants')) {
  235. pp = value['Partecipants']['value'];
  236. people = pp.split("<br />");
  237. for (i in people) {
  238. slice = people[i].split("; ");
  239. if (slice[2] == "Committente") {
  240. $("#CMM").css("display", "flex");
  241. client += slice[1];
  242. } else {
  243. $("#AUT").css("display", "flex");
  244. artist_name += slice[1];
  245. artist += "<div class='d-flex'><div class='mr-3'>" +
  246. slice[1] + "</div><div class='d-flex ml-auto'><div class='mr-3'><a class='btn-icon' target='_blank' href='" +
  247. slice[0] + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i><p class='btn-text'>LINK</p></a></div><div class='persona btn-icon' style='cursor:pointer' id='" +
  248. slice[0] + "'><i class='fa fa-user'></i><p class='btn-text'>SCHEDA<br />PERSONA</p></div></div></div></div>";
  249. }
  250. }
  251. }
  252. if (value.hasOwnProperty('time')) {
  253. time = value['time']['value'];
  254. }
  255. document.getElementById("technique").innerHTML = teche;
  256. document.getElementById("time").innerHTML = time;
  257. /*document.getElementById("artist_name").innerHTML = artist_name;*/
  258. document.getElementById("artist").innerHTML = artist;
  259. document.getElementById("client").innerHTML = client;
  260. });
  261. }
  262. $(document).on("click", ".luogo", function (ev) {
  263. var link = this.id;
  264. //alert(nome_autore);
  265. //$('#myModal').text("");
  266. window.open("Luogo.html?link="+this.id);
  267. });
  268. $(document).on("click", ".persona", function (ev) {
  269. var link = this.id;
  270. //alert(nome_autore);
  271. //$('#myModal').text("");
  272. window.open("Persona.html?link="+this.id);
  273. });