object.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 ?g AS ?graph ?uri ?label ?id (group_concat(distinct ?dimension ; separator='<br />') as ?dimensions) ?material ?location ?note \
  41. WHERE { \
  42. VALUES ?uri {<" + thisUrlParams.link + ">} \
  43. GRAPH ?g { ?uri rdfs:label ?label } \
  44. OPTIONAL {?uri crm:P1_is_identified_by ?uri_id . \
  45. ?uri_id rdfs:label ?id } \
  46. OPTIONAL { ?uri crm:P43_has_dimension ?uri_dimension . \
  47. ?uri_dimension rdfs:label ?dimension } \
  48. OPTIONAL { ?uri crm:P45_consist_of ?uri_material . \
  49. ?uri_material rdfs:label ?material } \
  50. OPTIONAL { ?uri crm:P54_has_current_permanent_location ?uri_location . \
  51. ?uri_location rdfs:label ?location } \
  52. OPTIONAL { ?uri crm:P3_has_note ?uri_note . \
  53. ?uri_note rdfs:label ?note } \
  54. } "
  55. queryContent = prefixes + " SELECT DISTINCT ?g AS ?graph ?uri ?titolo ?tipo ?ref \
  56. WHERE { \
  57. VALUES ?object {<" + thisUrlParams.link + ">} \
  58. ?object crm:P128_carries ?uri . \
  59. GRAPH ?g { ?uri rdfs:label ?label } \
  60. OPTIONAL {?uri crm:P1_is_identified_by ?uri_titolo . \
  61. ?uri_titolo rdfs:label ?titolo . } \
  62. OPTIONAL { ?uri crm:P2_has_type ?uri_tipo . \
  63. ?uri_tipo rdfs:label ?tipo . } \
  64. OPTIONAL { ?uri crm:P67_refers_to ?uri_ref . \
  65. ?uri_ref rdfs:label ?ref . } \
  66. }"
  67. queryURL = prepareQueryURL(queryInfo);
  68. queryINF = prepareQueryURL(queryContent);
  69. response = $.ajax({
  70. url: queryURL,
  71. dataType: "json",
  72. success: function (data){
  73. handle_objectData(data);
  74. },
  75. error: function (e) {}
  76. });
  77. response_info = $.ajax({
  78. url: queryINF,
  79. dataType: "json",
  80. success: function (data){
  81. handle_objectInfo(data);
  82. },
  83. error: function (e) {}
  84. });
  85. function handle_objectData(json) {
  86. console.log(json['results']['bindings']);
  87. $.each(
  88. json['results']['bindings'],
  89. function (index, value) {
  90. var graph = value['graph']['value'];
  91. var label = value['label']['value'];
  92. var identifier = "";
  93. var dimensions = "";
  94. var materials = "";
  95. var current_location = "";
  96. var description = "";
  97. if (value.hasOwnProperty('id')) {
  98. $("#ID").css("display", "flex");
  99. identifier = value['id']['value'];
  100. }
  101. if (value.hasOwnProperty('dimensions')) {
  102. if (value['dimensions']['value'] != "") {
  103. $("#consistenza").css("display", "flex");
  104. dimensions = value['dimensions']['value'];
  105. }
  106. }
  107. if (value.hasOwnProperty('condition')) {
  108. $("#STCC").css("display", "flex");
  109. condition = value['condition']['value'];
  110. }
  111. if (value.hasOwnProperty('material')) {
  112. $("#materia").css("display", "flex");
  113. materials = value['material']['value'];
  114. }
  115. if (value.hasOwnProperty('location')) {
  116. $("#localizzazione").css("display", "flex");
  117. current_location = value['location']['value'];
  118. }
  119. if (value.hasOwnProperty('note')) {
  120. $("#notes").css("display", "flex");
  121. description = value['note']['value'];
  122. }
  123. document.getElementById("grafo").innerHTML = graph;
  124. document.getElementById("nome_oggetto").innerHTML = label;
  125. document.getElementById("identifier").innerHTML = identifier;
  126. document.getElementById("location").innerHTML = current_location;
  127. document.getElementById("nota").innerHTML = description;
  128. document.getElementById("dimensions").innerHTML = dimensions;
  129. document.getElementById("materials").innerHTML = materials;
  130. });
  131. }
  132. function handle_objectInfo(json) {
  133. console.log(json['results']['bindings']);
  134. $.each(
  135. json['results']['bindings'],
  136. function (index, value) {
  137. var title = "";
  138. var type = "";
  139. var subject = "";
  140. if (value.hasOwnProperty('titolo')) {
  141. $("#titolo").css("display", "flex");
  142. title = value['titolo']['value'];
  143. }
  144. if (value.hasOwnProperty('tipo')) {
  145. $("#tipo").css("display", "flex");
  146. type = value['tipo']['value'];
  147. }
  148. if (value.hasOwnProperty('ref')) {
  149. $("#argomento").css("display", "flex");
  150. subject = value['ref']['value'];
  151. }
  152. document.getElementById("title").innerHTML = title;
  153. document.getElementById("type").innerHTML = type;
  154. document.getElementById("subject").innerHTML = subject;
  155. });
  156. }
  157. $(document).on("click", ".luogo", function (ev) {
  158. var link = this.id;
  159. //alert(nome_autore);
  160. //$('#myModal').text("");
  161. window.open("Luogo.html?link="+this.id);
  162. });
  163. $(document).on("click", ".persona", function (ev) {
  164. var link = this.id;
  165. //alert(nome_autore);
  166. //$('#myModal').text("");
  167. window.open("Persona.html?link="+this.id);
  168. });