OA.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 ?type ?current_owner ?current_location ?subject (group_concat(distinct ?dimension ; separator='<br />') as ?dimensions) (group_concat(distinct ?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 ?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 = value['type']['value'];
  127. }
  128. if (value.hasOwnProperty('current_owner')) {
  129. $("#LDCN").css("display", "flex");
  130. current_owner = value['current_owner']['value'];
  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('materials')) {
  147. if (value['materials']['value'] != "") {
  148. $("#MTC").css("display", "flex");
  149. materials = value['materials']['value'];
  150. }
  151. }
  152. if (value.hasOwnProperty('condition')) {
  153. $("#STCC").css("display", "flex");
  154. condition = value['condition']['value'];
  155. }
  156. if (value.hasOwnProperty('note')) {
  157. $("#NSC").css("display", "flex");
  158. note = value['note']['value'];
  159. }
  160. document.getElementById("grafo").innerHTML = graph;
  161. document.getElementById("nome_oggetto").innerHTML = label;
  162. document.getElementById("title").innerHTML = title;
  163. document.getElementById("identifier").innerHTML = identifier;
  164. document.getElementById("type").innerHTML = type;
  165. document.getElementById("owner").innerHTML = current_owner;
  166. document.getElementById("location").innerHTML = current_location;
  167. document.getElementById("subject").innerHTML = subject;
  168. document.getElementById("dimensions").innerHTML = dimensions;
  169. document.getElementById("materials").innerHTML = materials;
  170. document.getElementById("condition").innerHTML = condition;
  171. document.getElementById("description").innerHTML = note;
  172. });
  173. }
  174. function handle_Production(json) {
  175. console.log(json['results']['bindings']);
  176. $.each(
  177. json['results']['bindings'],
  178. function (index, value) {
  179. var partecipants = "";
  180. var teche = "";
  181. var time = "";
  182. var client = "";
  183. var artist = "";
  184. var artist_name = "";
  185. if (value.hasOwnProperty('techniques')) {
  186. if (value['techniques']['value'] != "") {
  187. teche = value['techniques']['value'];
  188. }
  189. }
  190. if (value.hasOwnProperty('Partecipants')) {
  191. pp = value['Partecipants']['value'];
  192. people = pp.split("<br />");
  193. for (i in people) {
  194. slice = people[i].split("; ");
  195. if (slice[2] == "Committente") {
  196. $("#CMM").css("display", "flex");
  197. client += slice[1];
  198. } else {
  199. $("#AUT").css("display", "flex");
  200. artist_name += slice[1];
  201. artist += "<div class='row'><div class='col-9'>" +
  202. slice[1] + "</div><div class='col'><a target='_blank' href='" +
  203. slice[0] + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div><div class='persona col' id='" +
  204. slice[0] + "'><i class='fa fa-user' style='cursor:pointer'></i></div></div></div>";
  205. }
  206. }
  207. }
  208. if (value.hasOwnProperty('time')) {
  209. time = value['time']['value'];
  210. }
  211. document.getElementById("technique").innerHTML = teche;
  212. document.getElementById("time").innerHTML = time;
  213. document.getElementById("artist_name").innerHTML = artist_name;
  214. document.getElementById("artist").innerHTML = artist;
  215. document.getElementById("client").innerHTML = client;
  216. });
  217. }
  218. $(document).on("click", ".luogo", function (ev) {
  219. var link = this.id;
  220. //alert(nome_autore);
  221. //$('#myModal').text("");
  222. window.open("Luogo.html?link="+this.id);
  223. });
  224. $(document).on("click", ".persona", function (ev) {
  225. var link = this.id;
  226. //alert(nome_autore);
  227. //$('#myModal').text("");
  228. window.open("Persona.html?link="+this.id);
  229. });