OA.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 ?dimension ; separator='<br />') as ?dimensions) (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 rdfs:label ?dimension } \
  53. OPTIONAL {?uri crm:P1_is_identified_by ?uriIdentifier . \
  54. ?uriIdentifier rdfs:label ?identifier } \
  55. OPTIONAL {?uri crm:P45_consists_of ?uriMaterial . \
  56. ?uriMaterial rdfs:label ?material } \
  57. OPTIONAL {?uri crm:P44_has_condition ?uriCondition . \
  58. ?uriCondition crm:P2_has_type ?condition} \
  59. OPTIONAL {?uri crm:P54_has_current_permanent_location ?current_location } \
  60. OPTIONAL {?uri crm:P62_depicts ?uriSubject . \
  61. ?uriSubject rdfs:label ?subject; \
  62. crm:P2_has_type 'Identificazione Iconografica' .} \
  63. OPTIONAL {?uri crm:P52_has_current_owner ?uriOwner . \
  64. ?uriOwner rdfs:label ?current_owner } \
  65. }"
  66. 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) \
  67. WHERE { \
  68. VALUES ?uri {<" + thisUrlParams.link + ">} \
  69. ?uri crm:P128_carries ?Information_Object . \
  70. ?Information_Object crm:P108i_was_produced_by ?Production . \
  71. OPTIONAL {?Production crm:P4_has_time-span ?uriTS ; \
  72. crm:P32_used_general_technique ?uriTecne . \
  73. ?uriTS rdfs:label ?time_span . \
  74. ?uriTecne rdfs:label ?technique} \
  75. OPTIONAL {?pc crm:P01_has_domain ?Production ; \
  76. crm:P02_has_range ?uriPerson ; \
  77. crm:P14.1_in_the_role_of ?uriRole . \
  78. ?uriPerson rdfs:label ?person . \
  79. ?uriRole rdfs:label ?role} \
  80. }"
  81. queryURL = prepareQueryURL(queryInfo);
  82. queryPro = prepareQueryURL(queryProduction);
  83. response = $.ajax({
  84. url: queryURL,
  85. dataType: "json",
  86. success: function (data){
  87. handle_OAdata(data);
  88. },
  89. error: function (e) {}
  90. });
  91. response_Pro = $.ajax({
  92. url: queryPro,
  93. dataType: "json",
  94. success: function (data){
  95. handle_Production(data);
  96. },
  97. error: function (e) {}
  98. });
  99. function handle_OAdata(json) {
  100. console.log(json['results']['bindings']);
  101. $.each(
  102. json['results']['bindings'],
  103. function (index, value) {
  104. var graph = value['graph']['value'];
  105. var label = value['label']['value'];
  106. var title = "";
  107. var type = "";
  108. var current_owner = "";
  109. var current_location = "";
  110. var subject = "";
  111. var dimensions = "";
  112. var materials = "";
  113. var condition = "";
  114. var note = "";
  115. var identifier = "";
  116. if (value.hasOwnProperty('title')) {
  117. $("#SGTT").css("display", "flex");
  118. title = value['title']['value'];
  119. }
  120. if (value.hasOwnProperty('identifier')) {
  121. $("#NCT").css("display", "flex");
  122. identifier = value['identifier']['value'];
  123. }
  124. if (value.hasOwnProperty('type')) {
  125. $("#OGTD").css("display", "flex");
  126. type = "<a href='" + value['uriType']['value'] + "'>" + value['type']['value'] + "</a>";
  127. }
  128. if (value.hasOwnProperty('current_owner')) {
  129. $("#LDCN").css("display", "flex");
  130. current_owner = "<a href='" + value['uriOwner']['value'] + "'>" + value['current_owner']['value'] + "</a>";
  131. }
  132. if (value.hasOwnProperty('current_location')) {
  133. $("#LDCS").css("display", "flex");
  134. current_location = value['current_location']['value'];
  135. }
  136. if (value.hasOwnProperty('subject')) {
  137. $("#SGTI").css("display", "flex");
  138. subject = value['subject']['value'];
  139. }
  140. if (value.hasOwnProperty('dimensions')) {
  141. if (value['dimensions']['value'] != "") {
  142. $("#MIS").css("display", "flex");
  143. dimensions = value['dimensions']['value'];
  144. }
  145. }
  146. if (value.hasOwnProperty('condition')) {
  147. $("#STCC").css("display", "flex");
  148. condition = value['condition']['value'];
  149. }
  150. if (value.hasOwnProperty('note')) {
  151. $("#NSC").css("display", "flex");
  152. note = value['note']['value'];
  153. }
  154. if (value.hasOwnProperty('Materials')) {
  155. if (value['Materials']['value'] != "") {
  156. $("#MTC").css("display", "flex");
  157. mm = value['Materials']['value'];
  158. mat = mm.split("<br />");
  159. for (i in mat) {
  160. slice = mat[i].split("; ");
  161. materials += "<a href='" + slice[0] + "'>" + slice[1] + "</a><br />";
  162. }
  163. }
  164. }
  165. document.getElementById("grafo").innerHTML = graph;
  166. document.getElementById("nome_oggetto").innerHTML = label;
  167. document.getElementById("title").innerHTML = title;
  168. document.getElementById("identifier").innerHTML = identifier;
  169. document.getElementById("type").innerHTML = type;
  170. document.getElementById("owner").innerHTML = current_owner;
  171. document.getElementById("location").innerHTML = current_location;
  172. document.getElementById("subject").innerHTML = subject;
  173. document.getElementById("dimensions").innerHTML = dimensions;
  174. document.getElementById("materials").innerHTML = materials;
  175. document.getElementById("condition").innerHTML = condition;
  176. document.getElementById("description").innerHTML = note;
  177. });
  178. }
  179. function handle_Production(json) {
  180. console.log(json['results']['bindings']);
  181. $.each(
  182. json['results']['bindings'],
  183. function (index, value) {
  184. var partecipants = "";
  185. var teche = "";
  186. var time = "";
  187. var client = "";
  188. var artist = "";
  189. var artist_name = "";
  190. if (value.hasOwnProperty('techniques')) {
  191. if (value['techniques']['value'] != "") {
  192. $("#MTC").css("display", "flex");
  193. tt = value['techniques']['value'];
  194. tec = tt.split("<br />");
  195. for (i in tec) {
  196. slice = tec[i].split("; ");
  197. teche += "<a href='" + slice[0] + "'>" + slice[1] + "</a><br />";
  198. }
  199. }
  200. }
  201. if (value.hasOwnProperty('Partecipants')) {
  202. pp = value['Partecipants']['value'];
  203. people = pp.split("<br />");
  204. for (i in people) {
  205. slice = people[i].split("; ");
  206. if (slice[2] == "Committente") {
  207. $("#CMM").css("display", "flex");
  208. client += slice[1];
  209. } else {
  210. $("#AUT").css("display", "flex");
  211. artist_name += slice[1];
  212. artist += "<div class='d-flex'><div class='mr-3'>" +
  213. slice[1] + "</div><div class='d-flex ml-auto'><div class='mr-3'><a class='btn-icon' target='_blank' href='" +
  214. slice[0] + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div><div class='persona' id='" +
  215. slice[0] + "'><i class='fa fa-user' style='cursor:pointer'></i></div></div></div></div>";
  216. }
  217. }
  218. }
  219. if (value.hasOwnProperty('time')) {
  220. time = value['time']['value'];
  221. }
  222. document.getElementById("technique").innerHTML = teche;
  223. document.getElementById("time").innerHTML = time;
  224. document.getElementById("artist_name").innerHTML = artist_name;
  225. document.getElementById("artist").innerHTML = artist;
  226. document.getElementById("client").innerHTML = client;
  227. });
  228. }
  229. $(document).on("click", ".luogo", function (ev) {
  230. var link = this.id;
  231. //alert(nome_autore);
  232. //$('#myModal').text("");
  233. window.open("Luogo.html?link="+this.id);
  234. });
  235. $(document).on("click", ".persona", function (ev) {
  236. var link = this.id;
  237. //alert(nome_autore);
  238. //$('#myModal').text("");
  239. window.open("Persona.html?link="+this.id);
  240. });