method.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. $(document).ready(function () {
  2. //#######################################
  3. const graphArray = [
  4. ["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini"],
  5. ["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale"],
  6. ["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi"],
  7. ["ASPO - Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli"],
  8. ["ASPO - Autori ASPO", "http://dev.restore.ovi.cnr.it:8890/aspo/actors"],
  9. ["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini"],
  10. ["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale"],
  11. ["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini"],
  12. ["MPP - Autori MPP", "http://dev.restore.ovi.cnr.it:8890/mpp/authors"],
  13. ["Luoghi", "http://dev.restore.ovi.cnr.it:8890/mpp/places"]
  14. ];
  15. var graph_selector = document.getElementById("graph_selector");
  16. let x = graphArray.length;
  17. for(var i=0; i<x; i++) {
  18. var opt = document.createElement("option");
  19. opt.value= graphArray[i][1];
  20. opt.innerHTML = graphArray[i][0]; // whatever property it has
  21. // then append it to the select element
  22. graph_selector.add(opt);
  23. }
  24. const entityArray = [
  25. ["Oggetti fisici", "http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object"],
  26. ["Contenuti Informativi", "http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object"],
  27. ["Titoli", "http://www.cidoc-crm.org/cidoc-crm/E35_Title"],
  28. ["Persone", "http://www.cidoc-crm.org/cidoc-crm/E21_Person"]
  29. ];
  30. var entity_selector = document.getElementById("entity_selector");
  31. let y = entityArray.length;
  32. for(var i=0; i<y; i++) {
  33. var opt = document.createElement("option");
  34. opt.value= entityArray[i][1];
  35. opt.innerHTML = entityArray[i][0]; // whatever property it has
  36. // then append it to the select element
  37. entity_selector.add(opt);
  38. }
  39. var search_name = "";
  40. var testo = "";
  41. function autori_retrieveData() {
  42. search_name = testo;
  43. var g = document.getElementById("graph_selector");
  44. var graph = g.value;
  45. var search_graph = "";
  46. if (graph != "") {
  47. search_graph = '<' + graph + '>';
  48. } else {
  49. search_graph = '?g';
  50. }
  51. var e = document.getElementById("entity_selector");
  52. var entity = e.value;
  53. var search_entity = "";
  54. if (entity != "") {
  55. search_entity = '<' + entity + '>';
  56. } else {
  57. search_entity = '?type';
  58. }
  59. //var query='SELECT DISTINCT ?nome WHERE { ?autore <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E39_Actor> . ?autore <http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by> ?nomeid. ?nomeid <http://www.w3.org/2000/01/rdf-schema#label> ?nome . FILTER regex(?nome, "'+ search_name +'") }' ;
  60. query = 'SELECT DISTINCT '+ search_graph +' AS ?graph ?link ?label ?entity WHERE { GRAPH '+ search_graph +' { ?link <http://www.w3.org/2000/01/rdf-schema#label> ?label ; <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> '+ search_entity +' . ?label bif:contains "\'' + search_name + '\'" .} '+ search_entity +' <http://www.w3.org/2000/01/rdf-schema#label> ?entity . FILTER (langMatches( lang(?entity), "en" )) } limit 100';
  61. //query = 'select distinct ?nome ?link where {?link <http://www.w3.org/2000/01/rdf-schema#label> ?nome . ?nome bif:contains "'+ search_name +'"}'
  62. //query = 'select distinct ?nome where {?nome <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E39_Actor> FILTER regex(?nome, "'+ search_name +'")}';
  63. var autori_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
  64. $.ajax({
  65. url: autori_url + '&callback=?',
  66. dataType: "json",
  67. success: function (data) {
  68. autori_handle_json(data);
  69. },
  70. error: function (e) {}
  71. });
  72. }
  73. function autori_handle_json(json) {
  74. console.log(json);
  75. $('#wb_Shape1').text("");
  76. $('#wb_Image1').text("");
  77. var i = 0;
  78. $.each(
  79. json['results']['bindings'],
  80. function (index, value) {
  81. var autore = "";
  82. autore += /*INIZIO DIV*/ '<tr><td style="width: 70%;">' /*DA QUA AUTORE ->*/ +
  83. '<div style="width:100%; height:auto; border:transparent;">' + value['graph']['value'] + '<br /><a href="' + value['link']['value'] + '" target="_blank">' + value['label']['value'] + '</a>' + '<br />' + value['entity']['value'] + '</td><td>' +
  84. /*DA QUI SCHEDA ->*/'<button type="button" id="' + value['link']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button>' + '</td><td>' +
  85. /*DA QUI CITAZIONE ->*/'<button type="button" id="' + value['link']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' + '</td><td>' +
  86. /*DA QUI HYPERLINK ->*/'<button type="button" id="' + value['link']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' + '</td><td>' +
  87. /*DA QUI LOD ->*/'<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['link']['value'] + '" target="_blank"><button type="button" id="lod ' + value['link']['value'] + '"class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a>' +
  88. '</td></tr>';/*FINE DIV*/
  89. i++;
  90. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  91. $('#wb_Shape1').append(autore);
  92. });
  93. if (i==0) {
  94. var message = '<tr id="error"><td><p>Questa ricerca non ha prodotto risultati</p></td></tr>';
  95. $('#wb_Shape1').append(message);
  96. }
  97. }
  98. $('#ClipArt1').click(function () {
  99. testo = $('input#TextArea1').val();
  100. autori_retrieveData();
  101. search_name = "";
  102. });
  103. //onlick hyperlink button
  104. $(document).on("click", ".hyp", function (ev) {
  105. var link = this.id;
  106. //alert(nome_autore);
  107. //$('#myModal').text("");
  108. $("#myModal").empty();
  109. $("#myModal").css("display", "block");
  110. $('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
  111. link + "</div><button id='copy_btn' class='btn btn-primary btn-lg' onclick='myFunction()'>Copia</button>");
  112. });
  113. $(document).on("click", ".close", function (ev) {
  114. var link = this.id;
  115. //alert(nome_autore);
  116. //$('#myModal').text("");
  117. $("#myModal").css("display", "none");
  118. });
  119. $(document).on("click", ".back", function (ev) {
  120. $("#myTab").css("display", "none");
  121. });
  122. $(document).on("click", ".cit", function (ev) {
  123. var author ="RESTORE. smart access to digital heritage and memory"
  124. var year = new Date().getFullYear()
  125. var today = new Date();
  126. var dd = String(today.getDate()).padStart(2, '0');
  127. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  128. var yyyy = today.getFullYear();
  129. today = dd + '/' + mm + '/' + yyyy;
  130. var link = this.id;
  131. //alert(nome_autore);
  132. //$('#myModal').text("");
  133. $("#myModal").empty();
  134. $("#myModal").css("display", "block");
  135. $('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
  136. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-primary btn-lg' onclick='myFunction()'>Copia</button>");
  137. });
  138. $(document).on("click", ".scheda", function (ev) {
  139. var link = this.id;
  140. var title = this.title;
  141. //alert(nome_autore);
  142. $("#myTab").empty();
  143. $("#myTab").css("display", "block");
  144. $('#myTab').append("<div class='tab-content'><span class='back'>&lt; Indietro</span><br /><h2><a href='" + link + "' target='_blank'>" + title + "</a></h2><div id='tab_container'><h3>Relazioni dirette</h3><br /><table id='info_link' class='table table-hover'></table><br /><table id='info_ico' class='table table-hover'></table><br /><h3>Relazioni inverse</h3><br /><table id='info_obj' class='table table-hover'></table></div></div>");
  145. /*var query_a = 'SELECT DISTINCT ?label WHERE { {<' + link +
  146. '> ?p ?object. OPTIONAL {?object ?property ?label . FILTER(?property = <http://www.w3.org/2004/02/skos/core#prefLabel> || ?property = <http://www.w3.org/2000/01/rdf-schema#label>) FILTER (langMatches( lang(?label), "en" )) } } UNION {<'+ link +
  147. '> ?p ?object. OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> ?propertyLabel .?object <http://www.w3.org/2000/01/rdf-schema#label> ?label } FILTER (?p != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>) FILTER (langMatches( lang(?propertyLabel), "en" )) }}';
  148. */
  149. var query_a = 'SELECT DISTINCT ?propLab ?object ?label WHERE {{<' + link +
  150. '> ?property ?object. ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propLab . OPTIONAL {?object <http://www.w3.org/2000/01/rdf-schema#label> ?label . } FILTER (?property != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?property != <http://www.cidoc-crm.org/cidoc-crm/P62_depicts>) FILTER (langMatches( lang(?propLab), "en" ))} UNION {<' + link +
  151. '> ?property ?object. ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propLab . OPTIONAL {?object <http://www.w3.org/2000/01/rdf-schema#label> ?label . } FILTER (?property != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?property != <http://www.w3.org/2000/01/rdf-schema#label>) FILTER(!regex(?property, "cidoc"))}}';
  152. var object_url_a = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_a) + '&output=json';
  153. var query_b = 'SELECT DISTINCT ?subject ?label ?property ?propertyLabel WHERE {?subject ?property <' + link +
  154. '> ; <http://www.w3.org/2000/01/rdf-schema#label> ?label . ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propertyLabel . FILTER (langMatches( lang(?propertyLabel), "en" ))}';
  155. var object_url_b = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_b) + '&output=json';
  156. var query_c = 'SELECT DISTINCT ?object ?label WHERE {{<' + link + '> <http://www.cidoc-crm.org/cidoc-crm/P62_depicts> ?object . ?object <http://www.w3.org/2000/01/rdf-schema#label> ?label .} UNION {<' + link +
  157. '> <http://www.cidoc-crm.org/cidoc-crm/P62_depicts> ?object . ?object <http://www.w3.org/2004/02/skos/core#prefLabel> ?label . FILTER (langMatches(lang(?label), "it" )) }}';
  158. var object_url_c = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_c) + '&output=json';
  159. $.ajax({//SOGGETTO
  160. url: object_url_a + '&callback=?',
  161. dataType: "json",
  162. success: function (data_a) {
  163. object_info_a(data_a);
  164. },
  165. error: function (e) {}
  166. });
  167. $.ajax({//OGGETTO
  168. url: object_url_b + '&callback=?',
  169. dataType: "json",
  170. success: function (data_b) {
  171. object_info_b(data_b);
  172. },
  173. error: function (e) {}
  174. });
  175. $.ajax({//ICONCLASS
  176. url: object_url_c + '&callback=?',
  177. dataType: "json",
  178. success: function (data_c) {
  179. object_info_c(data_c);
  180. },
  181. error: function (e) {}
  182. });
  183. });
  184. function object_info_a(json) {
  185. console.log(json);
  186. var j = 0;
  187. $('#info_link').text("");
  188. $.each(
  189. json['results']['bindings'],
  190. function (index, value) {
  191. var autore_a = "";
  192. var object = "";
  193. var object_type = value['object']['type'];
  194. if (object_type == "typed-literal" || object_type == "literal"){
  195. object = '<td>'+ value['object']['value'] + '</td>';
  196. }
  197. else{
  198. object = '<td style="width:60%;"><a href="'+ value['object']['value'] +'" target="_blank">'+ value['label']['value'] +'</a></td><td>' +
  199. '<button type="button" id="' + value['object']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
  200. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['object']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td>';
  201. }
  202. autore_a += /*INIZIO DIV*/ '<tr><td style="width:25%;">' + value['propLab']['value'] + '</td>' + object + '</tr>';/*FINE DIV*/
  203. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  204. j++;
  205. $('#info_link').append(autore_a);
  206. });
  207. if (j==0) {
  208. var message_a = '<tr id="error"><td><p>Non sono presenti relazioni dirette per questa risorsa</p></td></tr>';
  209. $('#info_link').append(message_a);
  210. }
  211. }
  212. function object_info_b(json) {
  213. console.log(json);
  214. var k = 0;
  215. $('#info_obj').text("");
  216. $.each(
  217. json['results']['bindings'],
  218. function (index, value) {
  219. var autore_b = "";
  220. autore_b += /*INIZIO DIV*/ '<tr><td style="width:60%;"><a href="' + value['subject']['value'] + '" target="_blank">' + value['label']['value'] + '</a></td><td style="width:25%;">' + value['propertyLabel']['value'] + '</td><td>' +
  221. '<button type="button" id="' + value['subject']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
  222. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td></tr>';
  223. /*FINE DIV*/
  224. k++;
  225. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  226. $('#info_obj').append(autore_b);
  227. });
  228. if (k==0) {
  229. var message_b = '<tr id="error"><td><p>Non sono presenti relazioni inverse per questa risorsa</p></td></tr>';
  230. $('#info_obj').append(message_b);
  231. }
  232. }
  233. function object_info_c(json) {
  234. console.log(json);
  235. $('#info_ico').text("");
  236. $.each(
  237. json['results']['bindings'],
  238. function (index, value) {
  239. var autore_c = "";
  240. autore_c += /*INIZIO DIV*/ '<tr><td style="width:25%;">depicts</td><td style="width:60%;"><a href="' + value['object']['value'] + '">' + value['label']['value'] + '</a></td><td>' +
  241. '<button type="button" id="' + value['object']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
  242. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['object']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td></tr>';
  243. /*FINE DIV*/
  244. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  245. $('#info_ico').append(autore_c);
  246. });
  247. }
  248. //VISUALIZZAZIONI DATI DELL'AUTORE
  249. //FUNZIONE LETTURA LUNGHEZZA FILE JSON
  250. /*
  251. function objLength(obj){
  252. var i=0;
  253. for (var x in obj){
  254. if(obj.hasOwnProperty(x)){
  255. i++;
  256. }
  257. }
  258. return i;
  259. }
  260. */
  261. //#######################################
  262. });
  263. function copyToClipboard(text) {
  264. var sampleTextarea = document.createElement("textarea");
  265. document.body.appendChild(sampleTextarea);
  266. sampleTextarea.value = text; //save main text in it
  267. sampleTextarea.select(); //select textarea contenrs
  268. document.execCommand("copy");
  269. document.body.removeChild(sampleTextarea);
  270. }
  271. function myFunction(){
  272. var copy = document.getElementById("myInput");
  273. copyText = copy.textContent;
  274. copyToClipboard(copyText);
  275. //copyToClipboard(copyText.value);
  276. }