search.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. ["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini"],
  14. ["Luoghi", "http://dev.restore.ovi.cnr.it:8890/mpp/places"]
  15. ];
  16. var graph_selector = document.getElementById("graph_selector");
  17. let x = graphArray.length;
  18. for(var i=0; i<x; i++) {
  19. var opt = document.createElement("option");
  20. opt.value= graphArray[i][1];
  21. opt.innerHTML = graphArray[i][0]; // whatever property it has
  22. // then append it to the select element
  23. graph_selector.add(opt);
  24. }
  25. var search_name = "";
  26. var testo = "";
  27. function results_retrieveData() {
  28. search_name = testo;
  29. var g = document.getElementById("graph_selector");
  30. var graph = g.value;
  31. var search_graph = "?g";
  32. var gg = "?g";
  33. if (graph != "") {
  34. search_graph = '<' + graph + '>';
  35. gg = "";
  36. }
  37. //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 +'") }' ;
  38. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  39. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  40. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>"
  41. queryMMO = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?label (group_concat(distinct ?type ;separator=', ') as ?types) \
  42. WHERE {GRAPH "+ search_graph +" { ?subject ?property ?object } \
  43. ?subject rdf:type crm:E22_Man-Made_Object ; \
  44. rdfs:label ?label ; \
  45. ?property ?object . \
  46. OPTIONAL {?subject crm:P2_has_type ?type } \
  47. ?object bif:contains \"\' "+ search_name + " \'\" . \
  48. }"
  49. queryInfObj = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?label ?id (group_concat(distinct ?type ;separator=', ') as ?types) ?object_type ?object_Label \
  50. WHERE { \
  51. GRAPH "+ search_graph +" {?subject rdf:type crm:E73_Information_Object ; \
  52. rdfs:label ?label .} \
  53. OPTIONAL {?subject crm:P1_is_identified_by ?id_subject . \
  54. ?id_subject rdfs:label ?id ; \
  55. rdf:type crm:E42_Identifier . } \
  56. OPTIONAL {?subject crm:P2_has_type ?entity_type . \
  57. ?entity_type rdfs:label ?type .} \
  58. {?subject ?property ?object_Label . \
  59. ?object_Label bif:contains \"\' "+ search_name + " \'\" . \
  60. } UNION { \
  61. ?subject ?property ?object . \
  62. ?object rdfs:label ?object_Label ; \
  63. rdf:type ?object_type . \
  64. ?object_Label bif:contains \"\' "+ search_name + " \'\" . \
  65. } \
  66. FILTER NOT EXISTS { ?property rdfs:label 'label' } \
  67. } ORDER BY ?id ?types"
  68. queryPerson = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?label \
  69. WHERE {GRAPH "+ search_graph +" { ?subject rdfs:label ?label ;\
  70. rdf:type crm:E21_Person .\
  71. ?label bif:contains \"\' "+ search_name + " \'\" .}\
  72. }"
  73. queryPlace = prefixes + " SELECT DISTINCT "+ search_graph +" AS ?graph ?subject ?label \
  74. WHERE {GRAPH "+ search_graph +" { ?subject rdfs:label ?label ;\
  75. rdf:type crm:E53_Place .\
  76. ?label bif:contains \"\' "+ search_name + " \'\" .}\
  77. }"
  78. //query = 'SELECT DISTINCT '+ search_graph +' AS ?graph ?link ?label ?entity ?object ?objLab 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" )) OPTIONAL {?link <http://www.cidoc-crm.org/cidoc-crm/P2_has_type> ?object } OPTIONAL {?link <http://www.cidoc-crm.org/cidoc-crm/P2_has_type> ?link_object . ?link_object <http://www.w3.org/2000/01/rdf-schema#label> ?objLab }} limit 100';
  79. var ManMadeObject_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryMMO) + '&output=json';
  80. var InformationObject_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryInfObj) + '&output=json';
  81. var Persons_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryPerson) + '&output=json';
  82. var Places_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(queryPlace) + '&output=json';
  83. $.ajax({
  84. url: ManMadeObject_url + '&callback=?',
  85. dataType: "json",
  86. success: function (data) {
  87. MMO_handle_json(data);
  88. },
  89. error: function (e) {}
  90. });
  91. $.ajax({
  92. url: InformationObject_url + '&callback=?',
  93. dataType: "json",
  94. success: function (data) {
  95. InfObj_handle_json(data);
  96. },
  97. error: function (e) {}
  98. });
  99. $.ajax({
  100. url: Persons_url + '&callback=?',
  101. dataType: "json",
  102. success: function (data) {
  103. Person_handle_json(data);
  104. },
  105. error: function (e) {}
  106. });
  107. $.ajax({
  108. url: Places_url + '&callback=?',
  109. dataType: "json",
  110. success: function (data) {
  111. Place_handle_json(data);
  112. },
  113. error: function (e) {}
  114. });
  115. }
  116. function rewrite_graph(graph) {
  117. var graph_name = ""
  118. if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/datini") {
  119. graph_name = "Archivio di Stato di Prato";
  120. }
  121. else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale") {
  122. graph_name = "Archivio di Stato di Prato";
  123. }
  124. else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi") {
  125. graph_name = "Archivio di Stato di Prato";
  126. }
  127. else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli") {
  128. graph_name = "Archivio di Stato di Prato";
  129. }
  130. else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/actors") {
  131. graph_name = "Archivio di Stato di Prato";
  132. }
  133. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/martini") {
  134. graph_name = "Museo di Palazzo Pretorio di Prato";
  135. }
  136. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale") {
  137. graph_name = "Museo di Palazzo Pretorio di Prato";
  138. }
  139. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/datini") {
  140. graph_name = "Museo di Palazzo Pretorio di Prato";
  141. }
  142. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/authors") {
  143. graph_name = "Museo di Palazzo Pretorio di Prato";
  144. }
  145. else if (graph == "http://dev.restore.ovi.cnr.it:8890/ovi/datini") {
  146. graph_name = "Opera del Vocabolario Italiano";
  147. }
  148. else if (graph == "http://dev.restore.ovi.cnr.it:8890/ovi/datini/trascr") {
  149. graph_name = "Opera del Vocabolario Italiano";
  150. }
  151. else if (graph == "http://dev.restore.ovi.cnr.it:8890/places") {
  152. graph_name = "Luoghi";
  153. }
  154. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/places") {
  155. graph_name = "Museo di Palazzo Pretorio di Prato";
  156. }
  157. else if (graph == "http://dev.restore.ovi.cnr.it:8890/label/toponimi") {
  158. graph_name = "Toponimi Archivio di Stato di Prato";
  159. }
  160. else {graph_name = graph;
  161. }
  162. return graph_name;
  163. }
  164. function MMO_handle_json(json) {
  165. console.log(json);
  166. $('#wb_Shape1').text("");
  167. $('#wb_Image1').text("");
  168. $('#Man-Made_Object').text("");
  169. $(".results").css("display", "block");
  170. $('#n_mmo').text("");
  171. var i = 0;
  172. $.each(
  173. json['results']['bindings'],
  174. function (index, value) {
  175. var object = ""; /*Inserisci VALUE TIPOLOGIA*/
  176. var graph = value['graph']['value'];
  177. var graph_name = rewrite_graph(graph);
  178. var mmoType = "";
  179. var artwork_button = "";
  180. if (value.hasOwnProperty('types')) {
  181. mmoType = value['types']['value'];
  182. }
  183. if (mmoType.includes("Opera d'Arte")) {
  184. artwork_button += '<button type="button" id="' + value['subject']['value'] +
  185. '" class="artwork btn btn-default" alt="opera d\'arte" title="' + value['label']['value'] +
  186. '"><i class="fas fa-paint-brush"></i><p class="btn-text">Scheda Opera d\'Arte</p></button>';
  187. }
  188. object += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
  189. '<a href=' + value['subject']['value'] + '>' + value['label']['value'] + '</a><br />' +
  190. '<i>' + mmoType + '</i></div>' +
  191. '<div class="col">' + artwork_button + '</div>' +
  192. '<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
  193. /*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
  194. /*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  195. i++;
  196. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  197. $('#Man-Made_Object').append(object);
  198. });
  199. $('#n_mmo').append(i);
  200. if (i==0) {
  201. var message = '<p>Nessun Oggetto Fisico trovato</p>';
  202. $('#Man-Made_Object').append(message);
  203. }
  204. }
  205. function InfObj_handle_json(json) {
  206. console.log(json);
  207. $('#Information_Object').text("");
  208. $('#n_io').text("");
  209. var i = 0;
  210. $.each(
  211. json['results']['bindings'],
  212. function (index, value) {
  213. var information = ""; /*Inserisci VALUE TIPOLOGIA*/
  214. var graph = value['graph']['value'];
  215. var graph_name = rewrite_graph(graph);
  216. var tipo = "";
  217. var id = "";
  218. var envelope_button = "";
  219. var myString = value['object_Label']['value'];
  220. var str = myString.replace(/<[^>]*>?/gm, '');
  221. let string_text = str.toLowerCase();
  222. let string_len = str.length;
  223. var word = testo;
  224. let ind = string_text.indexOf(word);
  225. let length = word.length;
  226. var wl = ind + length;
  227. /*var start = 0;
  228. var end = 0
  229. var bb = pp - 50;
  230. var ee = pp + length + 150;*/
  231. var pp = ind;
  232. before = str.substring(0, ind);
  233. after = str.substring(wl, string_len);
  234. let bb = before.lastIndexOf(".");
  235. let point = bb + pp;
  236. let ee = str.indexOf(".", point);
  237. console.log(bb, ee);
  238. if (bb < 0) {
  239. start = 0;
  240. } else {
  241. start = bb+1;
  242. }
  243. if (ee < 0) {
  244. end = string_len;
  245. } else {
  246. end = ee;
  247. }
  248. console.log(start, bb, end, ee);
  249. /*if (bb<=0) {
  250. start = 0;
  251. } else {
  252. start = bb;
  253. }
  254. if (ee>=string_len) {
  255. end = string_len;
  256. } else {
  257. end = ee;
  258. }*/
  259. first_chunk = str.substring(start, ind);
  260. highlight = str.substring(ind, wl);
  261. second_chunk = str.substring(wl, end);
  262. var snippet = first_chunk + "<span class='sharp'>" + highlight + "</span>" + second_chunk ;
  263. console.log(snippet);
  264. if (value.hasOwnProperty('types')) {
  265. tipo = value['types']['value'];
  266. }
  267. if (value.hasOwnProperty('id')) {
  268. id = " (" + value['id']['value'] + ")";
  269. }
  270. if (tipo.includes("Testo annotato OVI")) {
  271. envelope_button += '<button type="button" id="' + value['subject']['value'] +
  272. '" class="lettera btn btn-default" alt="lettera" title="' + value['label']['value'] +
  273. '"><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  274. }
  275. information += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>'+ snippet+'</p>' +
  276. 'In: ' + graph_name + ';<br />' +
  277. '<a href=' + value['subject']['value'] + '>' + value['label']['value'] + id +
  278. '</a>;<br /><i>' + tipo + '</i><br /></div>' +
  279. '<div class="col">' + envelope_button + '</div>' +
  280. '<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
  281. /*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
  282. /*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  283. i++;
  284. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  285. $('#Information_Object').append(information);
  286. });
  287. $('#n_io').append(i);
  288. if (i==0) {
  289. var message = '<p>Nessun Oggetto Informativo trovato</p>';
  290. $('#Information_Object').append(message);
  291. }
  292. }
  293. function Person_handle_json(json) {
  294. console.log(json);
  295. $('#Person').text("");
  296. $('#n_ps').text("");
  297. var i = 0;
  298. $.each(
  299. json['results']['bindings'],
  300. function (index, value) {
  301. var person = ""; /*Inserisci VALUE TIPOLOGIA*/
  302. var graph = value['graph']['value'];
  303. var graph_name = rewrite_graph(graph);
  304. person += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
  305. '<a href=' + value['subject']['value'] + '>' + value['label']['value'] + '</a></div>' +
  306. '<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="persona btn btn-default" alt="persona" title="' +
  307. value['label']['value'] + '"><i class="fa fa-user"></i><p class="btn-text">Scheda Persona</p></button></div>' +
  308. '<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
  309. /*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
  310. /*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  311. i++;
  312. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  313. $('#Person').append(person);
  314. });
  315. $('#n_ps').append(i);
  316. if (i==0) {
  317. var message = '<p>Nessuna Persona trovata</p>';
  318. $('#Person').append(message);
  319. }
  320. }
  321. function Place_handle_json(json) {
  322. console.log(json);
  323. $('#Place').text("");
  324. $('#n_pl').text("");
  325. var i = 0;
  326. $.each(
  327. json['results']['bindings'],
  328. function (index, value) {
  329. var place = ""; /*Inserisci VALUE TIPOLOGIA*/
  330. var graph = value['graph']['value'];
  331. var graph_name = rewrite_graph(graph);
  332. place += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
  333. '<a href=' + value['subject']['value'] + '>' + value['label']['value'] + '</a></div>' +
  334. '<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="luogo btn btn-default" alt="luogo" title="' +
  335. value['label']['value'] + '"><i class="fa fa-map"></i><p class="btn-text">Scheda Luogo</p></button></div>' +
  336. '<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button></div>' +
  337. /*DA QUI HYPERLINK ->*/'<div class="col"><button type="button" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button></div>' +
  338. /*DA QUI LOD ->*/'<div class="col"><a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  339. i++;
  340. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  341. $('#Place').append(place);
  342. });
  343. $('#n_pl').append(i);
  344. if (i==0) {
  345. var message = '<p>Nessun Luogo trovato</p>';
  346. $('#Place').append(message);
  347. }
  348. }
  349. $('#ClipArt1').click(function () {
  350. testo = $('input#TextArea1').val();
  351. results_retrieveData();
  352. search_name = "";
  353. });
  354. $('input#TextArea1').keypress(function(e) {
  355. var key = e.which;
  356. if (key == 13) // the enter key code
  357. {
  358. $('#ClipArt1').click();
  359. return false;
  360. }
  361. });
  362. //onlick hyperlink button
  363. $(document).on("click", ".hyp", function (ev) {
  364. var link = this.id;
  365. //alert(nome_autore);
  366. //$('#myModal').text("");
  367. $("#myModal").empty();
  368. $("#myModal").css("display", "block");
  369. $('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
  370. link + "</div><button id='copy_btn' class='btn btn-primary btn-lg' onclick='myFunction()'>Copia</button>");
  371. });
  372. $(document).on("click", ".lettera", function (ev) {
  373. var link = this.id;
  374. //alert(nome_autore);
  375. //$('#myModal').text("");
  376. window.open("lettera.html?link="+this.id);
  377. });
  378. $(document).on("click", ".artwork", function (ev) {
  379. var link = this.id;
  380. //alert(nome_autore);
  381. //$('#myModal').text("");
  382. window.open("OA.html?link="+this.id);
  383. });
  384. $(document).on("click", ".persona", function (ev) {
  385. var link = this.id;
  386. //alert(nome_autore);
  387. //$('#myModal').text("");
  388. window.open("Persona.html?link="+this.id);
  389. });
  390. $(document).on("click", ".luogo", function (ev) {
  391. var link = this.id;
  392. //alert(nome_autore);
  393. //$('#myModal').text("");
  394. window.open("Luogo.html?link="+this.id);
  395. });
  396. $(document).on("click", ".close", function (ev) {
  397. var link = this.id;
  398. //alert(nome_autore);
  399. //$('#myModal').text("");
  400. $("#myModal").css("display", "none");
  401. });
  402. $(document).on("click", ".back", function (ev) {
  403. $("#myTab").css("display", "none");
  404. });
  405. $(document).on("click", ".cit", function (ev) {
  406. var author ="RESTORE. smart access to digital heritage and memory"
  407. var year = new Date().getFullYear()
  408. var today = new Date();
  409. var dd = String(today.getDate()).padStart(2, '0');
  410. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  411. var yyyy = today.getFullYear();
  412. today = dd + '/' + mm + '/' + yyyy;
  413. var link = this.id;
  414. //alert(nome_autore);
  415. //$('#myModal').text("");
  416. $("#myModal").empty();
  417. $("#myModal").css("display", "block");
  418. $('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
  419. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-primary btn-lg' onclick='myFunction()'>Copia</button>");
  420. });
  421. $(document).on("click", ".scheda", function (ev) {
  422. var link = this.id;
  423. var title = this.title;
  424. //alert(nome_autore);
  425. $("#myTab").empty();
  426. $("#myTab").css("display", "block");
  427. $('#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>");
  428. /*var query_a = 'SELECT DISTINCT ?label WHERE { {<' + link +
  429. '> ?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 +
  430. '> ?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" )) }}';
  431. */
  432. var query_a = 'SELECT DISTINCT ?propLab ?object ?label WHERE {{<' + link +
  433. '> ?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 +
  434. '> ?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"))}}';
  435. var object_url_a = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_a) + '&output=json';
  436. var query_b = 'SELECT DISTINCT ?subject ?label ?property ?propertyLabel WHERE {?subject ?property <' + link +
  437. '> ; <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" ))}';
  438. var object_url_b = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_b) + '&output=json';
  439. 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 +
  440. '> <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" )) }}';
  441. var object_url_c = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_c) + '&output=json';
  442. $.ajax({//SOGGETTO
  443. url: object_url_a + '&callback=?',
  444. dataType: "json",
  445. success: function (data_a) {
  446. object_info_a(data_a);
  447. },
  448. error: function (e) {}
  449. });
  450. $.ajax({//OGGETTO
  451. url: object_url_b + '&callback=?',
  452. dataType: "json",
  453. success: function (data_b) {
  454. object_info_b(data_b);
  455. },
  456. error: function (e) {}
  457. });
  458. $.ajax({//ICONCLASS
  459. url: object_url_c + '&callback=?',
  460. dataType: "json",
  461. success: function (data_c) {
  462. object_info_c(data_c);
  463. },
  464. error: function (e) {}
  465. });
  466. });
  467. function object_info_a(json) {
  468. console.log(json);
  469. var j = 0;
  470. $('#info_link').text("");
  471. $.each(
  472. json['results']['bindings'],
  473. function (index, value) {
  474. var autore_a = "";
  475. var object = "";
  476. var object_type = value['object']['type'];
  477. if (object_type == "typed-literal" || object_type == "literal"){
  478. object = '<td>'+ value['object']['value'] + '</td>';
  479. }
  480. else{
  481. object = '<td style="width:60%;"><a href="'+ value['object']['value'] +'" target="_blank">'+ value['label']['value'] +'</a></td><td>' +
  482. '<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>' +
  483. '<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>';
  484. }
  485. autore_a += /*INIZIO DIV*/ '<tr><td style="width:25%;">' + value['propLab']['value'] + '</td>' + object + '</tr>';/*FINE DIV*/
  486. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  487. j++;
  488. $('#info_link').append(autore_a);
  489. });
  490. if (j==0) {
  491. var message_a = '<tr id="error"><td><p>Non sono presenti relazioni dirette per questa risorsa</p></td></tr>';
  492. $('#info_link').append(message_a);
  493. }
  494. }
  495. function object_info_b(json) {
  496. console.log(json);
  497. var k = 0;
  498. $('#info_obj').text("");
  499. $.each(
  500. json['results']['bindings'],
  501. function (index, value) {
  502. var autore_b = "";
  503. 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>' +
  504. '<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>' +
  505. '<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>';
  506. /*FINE DIV*/
  507. k++;
  508. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  509. $('#info_obj').append(autore_b);
  510. });
  511. if (k==0) {
  512. var message_b = '<tr id="error"><td><p>Non sono presenti relazioni inverse per questa risorsa</p></td></tr>';
  513. $('#info_obj').append(message_b);
  514. }
  515. }
  516. function object_info_c(json) {
  517. console.log(json);
  518. $('#info_ico').text("");
  519. $.each(
  520. json['results']['bindings'],
  521. function (index, value) {
  522. var autore_c = "";
  523. 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>' +
  524. '<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>' +
  525. '<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>';
  526. /*FINE DIV*/
  527. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  528. $('#info_ico').append(autore_c);
  529. });
  530. }
  531. //VISUALIZZAZIONI DATI DELL'AUTORE
  532. //FUNZIONE LETTURA LUNGHEZZA FILE JSON
  533. /*
  534. function objLength(obj){
  535. var i=0;
  536. for (var x in obj){
  537. if(obj.hasOwnProperty(x)){
  538. i++;
  539. }
  540. }
  541. return i;
  542. }
  543. */
  544. //#######################################
  545. });
  546. function copyToClipboard(text) {
  547. var sampleTextarea = document.createElement("textarea");
  548. document.body.appendChild(sampleTextarea);
  549. sampleTextarea.value = text; //save main text in it
  550. sampleTextarea.select(); //select textarea contenrs
  551. document.execCommand("copy");
  552. document.body.removeChild(sampleTextarea);
  553. }
  554. function myFunction(){
  555. var copy = document.getElementById("myInput");
  556. copyText = copy.textContent;
  557. copyToClipboard(copyText);
  558. //copyToClipboard(copyText.value);
  559. }