method.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. ];
  14. var graph_selector = document.getElementById("graph_selector");
  15. let x = graphArray.length;
  16. for(var i=0; i<x; i++) {
  17. var opt = document.createElement("option");
  18. opt.value= graphArray[i][1];
  19. opt.innerHTML = graphArray[i][0]; // whatever property it has
  20. // then append it to the select element
  21. graph_selector.add(opt);
  22. }
  23. const entityArray = [
  24. ["Oggetti fisici", "http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object"],
  25. ["Persone", "http://www.cidoc-crm.org/cidoc-crm/E21_Person"],
  26. ["Luoghi", "http://www.cidoc-crm.org/cidoc-crm/E53_Place"]
  27. ];
  28. var entity_selector = document.getElementById("entity_selector");
  29. let y = entityArray.length;
  30. for(var i=0; i<y; i++) {
  31. var opt = document.createElement("option");
  32. opt.value= entityArray[i][1];
  33. opt.innerHTML = entityArray[i][0]; // whatever property it has
  34. // then append it to the select element
  35. entity_selector.add(opt);
  36. }
  37. var search_name = "";
  38. var testo = "";
  39. function autori_retrieveData() {
  40. search_name = testo;
  41. var g = document.getElementById("graph_selector");
  42. var graph = g.value;
  43. var search_graph = "";
  44. if (graph != "") {
  45. search_graph = '<' + graph + '>';
  46. } else {
  47. search_graph = '?g';
  48. }
  49. var e = document.getElementById("entity_selector");
  50. var entity = e.value;
  51. var search_entity = "";
  52. if (entity != "") {
  53. search_entity = '<' + entity + '>';
  54. } else {
  55. search_entity = '?type';
  56. }
  57. //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 +'") }' ;
  58. 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" )) }';
  59. //query = 'select distinct ?nome ?link where {?link <http://www.w3.org/2000/01/rdf-schema#label> ?nome . ?nome bif:contains "'+ search_name +'"}'
  60. //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 +'")}';
  61. entity = '';
  62. graph = '';
  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. $.each(
  77. json['results']['bindings'],
  78. function (index, value) {
  79. var autore = "";
  80. autore += /*INIZIO DIV*/ '<tr><td>' /*DA QUA AUTORE ->*/ +
  81. '<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>' +
  82. /*DA QUI SCHEDA ->*/'<button type="button" id="scheda ' + value['link']['value'] + '"class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button>' + '</td><td>' +
  83. /*DA QUI CITAZIONE ->*/'<button type="button" id="cit ' + value['link']['value'] + '"class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' + '</td><td>' +
  84. /*DA QUI HYPERLINK ->*/'<button type="button" id="hyp ' + value['link']['value'] + '"class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' + '</td><td>' +
  85. /*DA QUI LOD ->*/'<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>' +
  86. '</td></tr>';/*FINE DIV*/
  87. $('#wb_Shape1').append(autore);
  88. });
  89. }
  90. $('#ClipArt1').click(function () {
  91. testo = $('textarea#TextArea1').val();
  92. autori_retrieveData();
  93. search_name = "";
  94. });
  95. //VISUALIZZAZIONI DATI DELL'AUTORE
  96. //FUNZIONE LETTURA LUNGHEZZA FILE JSON
  97. /*
  98. function objLength(obj){
  99. var i=0;
  100. for (var x in obj){
  101. if(obj.hasOwnProperty(x)){
  102. i++;
  103. }
  104. }
  105. return i;
  106. }
  107. */
  108. //#######################################
  109. });