voiceSearch.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*var final_transcript = '';
  2. var recognizing = false;*/
  3. var Parole = "";
  4. /*if ('webkitSpeechRecognition' in window) {
  5. var recognition = new webkitSpeechRecognition();
  6. recognition.continuous = false;
  7. recognition.interimResults = true;
  8. recognition.onstart = function () {
  9. recognizing = true;
  10. };
  11. recognition.onerror = function (event) {
  12. console.log(event.error);
  13. };
  14. recognition.onend = function () {
  15. recognizing = false;
  16. };
  17. recognition.onresult = function (event) {
  18. var interim_transcript = '';
  19. for (var i = event.resultIndex; i < event.results.length; ++i) {
  20. if (event.results[i].isFinal) {
  21. final_transcript += event.results[i][0].transcript;
  22. Parole = final_transcript;
  23. console.log(Parole);
  24. setTimeout(function () {
  25. $("#ClipArt1" ).click();
  26. }, 3000);
  27. } else {
  28. interim_transcript += event.results[i][0].transcript;
  29. }
  30. }
  31. final_transcript = capitalize(final_transcript);
  32. final_span.innerHTML = linebreak(final_transcript);
  33. TextArea1.value = linebreak(final_transcript);
  34. interim_span.innerHTML = linebreak(interim_transcript);
  35. };
  36. }
  37. var two_line = /\n\n/g;
  38. var one_line = /\n/g;
  39. function linebreak(s) {
  40. return s.replace(two_line, '<p></p>').replace(one_line, '<br>');
  41. }
  42. function capitalize(s) {
  43. return s.replace(s.substr(0, 1), function (m) {
  44. return m.toUpperCase();
  45. });
  46. }
  47. function startDictation(event) {
  48. if (recognizing) {
  49. recognition.stop();
  50. return;
  51. }
  52. final_transcript = '';
  53. recognition.lang = 'it-it';
  54. recognition.start();
  55. final_span.innerHTML = '';
  56. TextArea1.value = '';
  57. interim_span.innerHTML = '';
  58. }*/
  59. let mmoQueries = 0;
  60. let infQueries = 0;
  61. let perQueries = 0;
  62. let lgQueries = 0;
  63. $(document).ready(function () {
  64. //#######################################
  65. populateOption();
  66. var search_name = "";
  67. var Label = "";
  68. var object_Label = "";
  69. var id_label = "";
  70. var name_per = "";
  71. var note_per = "";
  72. var occupation_per = "";
  73. var place_search = "";
  74. var testo = "";
  75. $('#ClipArt1').on("click", function () {
  76. $('#Man-Made_Object').text("");
  77. $('#n_mmo').text("0");
  78. $('#Information_Object').text("");
  79. $('#n_io').text("0");
  80. $('#Person').text("");
  81. $('#n_ps').text("0");
  82. $('#Place').text("");
  83. $('#n_pl').text("0");
  84. $('#licenza').css("display", "block");
  85. testo = $('input#TextArea1').val();
  86. console.log(testo);
  87. Parole = testo;
  88. //questo era il contenuto di results_retrieveData()
  89. mmoQueries = 0;
  90. infQueries = 0;
  91. perQueries = 0;
  92. lgQueries = 0;
  93. $("#mmoLoader").css("display", "block");
  94. $("#infLoader").css("display", "block");
  95. $("#perLoader").css("display", "block");
  96. $("#lgLoader").css("display", "block");
  97. $('#wb_Image1').text("");
  98. $('.results').css("display", "none");
  99. next_text = testo.split(" ");
  100. search_name = "\"'" + next_text[0] + "'";
  101. if (next_text.length > 1) {
  102. for (var i=1; i<next_text.length; i++) {
  103. search_name = search_name + " AND '" + next_text[i] + "'";
  104. }
  105. }
  106. search_name = search_name + "\"";
  107. if (testo != "") {
  108. Label = " ?label bif:contains "+ search_name + " . ";
  109. object_Label = " ?object_Label bif:contains "+ search_name + " . ";
  110. id_label = " ?id bif:contains "+ search_name + " . ";
  111. name_per = "?name bif:contains "+ search_name + " . ";
  112. note_per = " ?note bif:contains " + search_name + " . ";
  113. occupation_per = " ?occupation bif:contains " + search_name + " . ";
  114. place_search = " ?label bif:contains" + search_name + " . ";
  115. }
  116. else {
  117. Label = "";
  118. object_Label = "";
  119. id_label = "";
  120. name_per = "";
  121. note_per = " ?note bif:contains 'NNNNNN' . ";;
  122. place_search = "";
  123. occupation_per = " ?occupation bif:contains 'NNNNN' . ";;
  124. }
  125. var g = document.getElementById("graph_selector");
  126. var g2 = document.getElementById("graph_selector2");
  127. var graph1 = g.value;
  128. var graph2 = g2.value;
  129. if (graph1 == 'MPP') {
  130. object_Label = " ?object_Label bif:contains 'NNNNNNNN' . ";
  131. }
  132. var search_graph = getGraph(graph1, graph2);
  133. var pref = queryManager['prefixes']['all'];
  134. var query1 = pref + (queryManager['queryMMO']['queryLabel']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', Label);
  135. var query2 = pref + (queryManager['queryMMO']['queryArte']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', Label);
  136. var query3 = pref + (queryManager['queryMMO']['queryIdentificatore']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', testo);
  137. var query4 = pref + (queryManager['queryINF']['queryContenuti1']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', object_Label);
  138. var query5 = pref + (queryManager['queryINF']['queryContenuti2']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', object_Label);
  139. var query6 = pref + (queryManager['queryINF']['queryContenuti3']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', object_Label);
  140. var query7 = pref + (queryManager['queryPER']['queryNome']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', name_per);
  141. var query8 = pref + (queryManager['queryPER']['queryNote']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', note_per);
  142. var query9 = pref + (queryManager['queryPER']['queryOccupazione']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', occupation_per);
  143. var query10 = pref + (queryManager['queryLG']['queryLuoghi']).replace('<{GRAPH}>', search_graph).replace('<{WORD}>', place_search);
  144. // la funzione doJsonQuery restituisce direttamente l'oggetto della chiamata ajax in json.
  145. // Una volta effettuata la chiamata, il risultato è passato alla funzione manage...
  146. doJsonQuery(query1).done(function(r) { manageMMO(r); });
  147. doJsonQuery(query2).done(function(r) { manageMMO(r); });
  148. doJsonQuery(query3).done(function(r) { manageMMO(r); });
  149. doJsonQuery(query4).done(function(r) { manageINF(r); });
  150. doJsonQuery(query5).done(function(r) { manageINF(r); });
  151. doJsonQuery(query6).done(function(r) { manageINF(r); });
  152. doJsonQuery(query7).done(function(r) { managePER(r); });
  153. doJsonQuery(query8).done(function(r) { managePER(r); });
  154. doJsonQuery(query9).done(function(r) { managePER(r); });
  155. doJsonQuery(query10).done(function(r) { manageLG(r); });
  156. });
  157. $('input#TextArea1').keypress(function(e) {
  158. var key = e.which;
  159. if (key == 13) // the enter key code
  160. {
  161. $('#ClipArt1').click();
  162. return false;
  163. }
  164. });
  165. });
  166. function checkEmpty() {
  167. if ($("#Man-Made_Object").is(':empty')) {
  168. var message = '<p class="no-results">Nessun <span>Oggetto Fisico</span> trovato</p>';
  169. $('#Man-Made_Object').append(message);
  170. }
  171. if ($("#Information_Object").is(':empty')) {
  172. var message = '<p class="no-results">Nessun <span>Oggetto Informativo</span> trovato</p>';
  173. $('#Information_Object').append(message);
  174. }
  175. if ($("#Person").is(':empty')) {
  176. var message = '<p class="no-results">Nessuna <span>Persona</span> trovata</p>';
  177. $('#Person').append(message);
  178. }
  179. if ($("#Place").is(':empty')) {
  180. var message = '<p class="no-results">Nessun <span>Luogo</span> trovato</p>';
  181. $('#Place').append(message);
  182. }
  183. }
  184. function rewrite_graph(graph) {
  185. var graph_name = ""
  186. if (graph == "http://147.213.76.182:8890/aspo/datini") {
  187. graph_name = "Archivio di Stato di Prato - Fondo Datini";
  188. }
  189. else if (graph == "http://147.213.76.182:8890/aspo/ospedale") {
  190. graph_name = "Archivio di Stato di Prato - Fondo Ospedale Misericordia e Dolce";
  191. }
  192. else if (graph == "http://147.213.76.182:8890/aspo/marcovaldi") {
  193. graph_name = "Archivio di Stato di Prato - Fondo Marcolvaldi";
  194. }
  195. else if (graph == "http://147.213.76.182:8890/aspo/gettatelli") {
  196. graph_name = "Archivio di Stato di Prato - Fondo Ospedale Misericordia e Dolce";
  197. }
  198. else if (graph == "http://147.213.76.182:8890/aspo/actors") {
  199. graph_name = "Archivio di Stato di Prato";
  200. }
  201. else if (graph == "http://147.213.76.182:8890/mpp/martini") {
  202. graph_name = "Museo di Palazzo Pretorio di Prato";
  203. }
  204. else if (graph == "http://147.213.76.182:8890/mpp/ospedale") {
  205. graph_name = "Museo di Palazzo Pretorio di Prato";
  206. }
  207. else if (graph == "http://147.213.76.182:8890/mpp/datini") {
  208. graph_name = "Museo di Palazzo Pretorio di Prato";
  209. }
  210. else if (graph == "http://147.213.76.182:8890/mpp/authors") {
  211. graph_name = "Museo di Palazzo Pretorio di Prato";
  212. }
  213. else if (graph == "http://147.213.76.182:8890/ovi/datini") {
  214. graph_name = "Opera del Vocabolario Italiano";
  215. }
  216. else if (graph == "http://147.213.76.182:8890/ovi/datini/trascr") {
  217. graph_name = "Opera del Vocabolario Italiano";
  218. }
  219. else if (graph == "http://147.213.76.182:8890/places") {
  220. graph_name = "Luoghi";
  221. }
  222. else if (graph == "http://147.213.76.182:8890/mpp/places") {
  223. graph_name = "Museo di Palazzo Pretorio di Prato";
  224. }
  225. else if (graph == "http://147.213.76.182:8890/label/toponimi") {
  226. graph_name = "Toponimi Archivio di Stato di Prato";
  227. }
  228. else if (graph == "http://147.213.76.182:8890/aspo/onomastica") {
  229. graph_name = "Archivio di Stato di Prato - Onomatica Datini";
  230. }
  231. else if (graph == "http://147.213.76.182:8890/aspo/gettatelli/newdataset") {
  232. graph_name = "Archivio di Stato di Prato - Fondo Ospedale Misericordia e Dolce";
  233. }
  234. else if (graph == "http://147.213.76.182:8890/aspo/onomastica/gruppi") {
  235. graph_name = "Archivio di Stato di Prato - Onomastica Datini";
  236. }
  237. else if (graph == "http://147.213.76.182:8890/mpp/autori") {
  238. graph_name = "Museo di Palazzo Pretorio";
  239. }
  240. else if (graph == "http://147.213.76.182:8890/aspo/onomastica/datini") {
  241. graph_name = "Archivio di Stato di Prato - Onomastica Datini";
  242. }
  243. else if (graph == "http://147.213.76.182:8890/onomastica/ospedale") {
  244. graph_name = "Archivio di Stato di Prato - Fondo Ospedale Misericordia e Dolce";
  245. }
  246. else if (graph == "http://147.213.76.182:8890/mpp/ulan/viaf") {
  247. graph_name = "Persone";
  248. }
  249. else if (graph == "http://147.213.76.182:8890/places/microtoponimi") {
  250. graph_name = "Luoghi";
  251. }
  252. else {graph_name = graph;
  253. }
  254. return graph_name;
  255. }
  256. function MMO_handle_json(json) {
  257. // console.log(json);
  258. mmoQueries = mmoQueries+1;
  259. if(mmoQueries==3){
  260. $('#mmoLoader').css("display", "none");
  261. }
  262. $('#wb_Shape1').text("");
  263. $(".results").css("display", "block");
  264. var n_mmo = $('#n_mmo').text();
  265. var b = parseInt(n_mmo);
  266. var i = 0;
  267. $.each(
  268. json['results']['bindings'],
  269. function (index, value) {
  270. var object = ""; /*Inserisci VALUE TIPOLOGIA*/
  271. var graph = value['graph']['value'];
  272. var graph_name = rewrite_graph(graph);
  273. var mmoType = "";
  274. var mmoId = "";
  275. var object_button = "";
  276. var object_type = "";
  277. if (value.hasOwnProperty('type')) {
  278. mmoType = value['type']['value'];
  279. }
  280. if (value.hasOwnProperty('identifier')) {
  281. mmoId = value['identifier']['value'];
  282. }
  283. if (mmoType.includes("Opera d'Arte")) {
  284. object_type = "artwork";
  285. object_button += '<button type="button" id="' + value['subject']['value'] +
  286. '" class="artwork btn btn-default" alt="opera d\'arte" title="' + value['label']['value'] +
  287. '"><i class="fas fa-paint-brush"></i><p class="btn-text">Scheda Opera d\'Arte</p></button>';
  288. } else {
  289. object_type = "object";
  290. object_button += '<button type="button" id="' + value['subject']['value'] +
  291. '" class="object btn btn-default" alt="oggetto" title="' + value['label']['value'] +
  292. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  293. }
  294. object += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
  295. '<span id="' + value['subject']['value'] + '" class="title_doc ' + object_type +'">' + value['label']['value'] + '</span><br />' +
  296. '<i>' + mmoType + ' ' + mmoId + '</i></div>' +
  297. '<div class="col d-flex align-items-start justify-content-end">' + object_button +
  298. '<button type="button" value="' + object_type + '" 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>' +
  299. /*DA QUI HYPERLINK ->*/'<button type="button" value="' + object_type + '" 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>' +
  300. /*DA QUI LOD ->*/'<a href="http://147.213.76.182/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>';
  301. i++;
  302. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  303. $('#Man-Made_Object').append(object);
  304. });
  305. var n_oggetto = b + i;
  306. $('#n_mmo').text("");
  307. $('#n_mmo').append(n_oggetto);
  308. if (n_oggetto == 0) {
  309. $('#Man-Made_Object').text("");
  310. var message = '<p id="no_mmo" class="no-results">Nessun <span>Oggetto Fisico</span> trovato</p>';
  311. $('#Man-Made_Object').append(message);
  312. } else {
  313. $('#no_mmo').remove("");
  314. }
  315. }
  316. function InfObj_handle_json(json) {
  317. // console.log(json);
  318. infQueries = infQueries+1;
  319. if(infQueries==3){
  320. $('#infLoader').css("display", "none");
  321. }
  322. var n_io = $('#n_io').text();
  323. var b = parseInt(n_io);
  324. var i = 0;
  325. $.each(
  326. json['results']['bindings'],
  327. function (index, value) {
  328. var information = ""; /*Inserisci VALUE TIPOLOGIA*/
  329. var graph = value['graph']['value'];
  330. var graph_name = rewrite_graph(graph);
  331. var tipo = "";
  332. var id = "";
  333. var infObject_button = "";
  334. if (value['text']['type'] != 'uri') {
  335. var myString = value['text']['value'];
  336. var str = myString.replace(/<[^>]*>?/gm, '');
  337. let string_text = str.toLowerCase();
  338. let string_len = str.length;
  339. var word = Parole;
  340. let ind = string_text.indexOf(word);
  341. let length = word.length;
  342. var wl = ind + length;
  343. var resource_type = "";
  344. var link_type = "";
  345. /*var start = 0;
  346. var end = 0
  347. var bb = pp - 50;
  348. var ee = pp + length + 150;*/
  349. var pp = ind;
  350. before = str.substring(0, ind);
  351. after = str.substring(wl, string_len);
  352. let bb = before.lastIndexOf(".");
  353. let point = bb + pp;
  354. let ee = str.indexOf(".", point);
  355. if (bb < 0) {
  356. start = 0;
  357. } else {
  358. start = bb+1;
  359. }
  360. if (ee < 0) {
  361. end = string_len;
  362. } else {
  363. end = ee;
  364. }
  365. first_chunk = str.substring(start, ind);
  366. highlight = str.substring(ind, wl);
  367. second_chunk = str.substring(wl, end);
  368. var snippet = first_chunk + highlight + second_chunk ;
  369. //var snippet = first_chunk + "<span class='sharp'>" + highlight + "</span>" + second_chunk ;
  370. if (value.hasOwnProperty('types')) {
  371. tipo = value['types']['value'];
  372. }
  373. if (value.hasOwnProperty('id')) {
  374. id = " (" + value['id']['value'] + ")";
  375. }
  376. if (tipo.includes("lettera")) {
  377. link_name = value['subject']['value'];
  378. resource_type = "lettera";
  379. link_type = "lettera";
  380. infObject_button += '<button type="button" id="' + value['subject']['value'] +
  381. '" class="lettera btn btn-default" alt="lettera" title="' + value['label']['value'] +
  382. '"><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  383. } else {
  384. link_name = value['Physical_Object']['value'];
  385. resource_type = "object";
  386. link_type = "object";
  387. infObject_button += '<button type="button" id="' + value['Physical_Object']['value'] +
  388. '" class="object btn btn-default" alt="oggetto" title="' + value['label']['value'] +
  389. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  390. }
  391. //'<div class="row res"><div class="col-8"><p>' + graph_name + '<br />' +
  392. //'<span id="' + value['subject']['value'] + '" class="title_doc luogo">' + value['label']['value'] + '</span></p></div>'
  393. information += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>'+ snippet+'</p>' +
  394. 'In: ' + graph_name + ';<br />' +
  395. '<span id="' + link_name + '" class="title_doc ' + link_type + '">' + value['label']['value'] + id +
  396. '</span>;<br /><i>' + tipo + '</i><br /></div>' +
  397. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  398. '<button type="button" value="' + resource_type + '" 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>' +
  399. /*DA QUI HYPERLINK ->*/'<button type="button" value="' + resource_type + '" 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>' +
  400. /*DA QUI LOD ->*/'<a href="http://147.213.76.182/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>';
  401. i++;
  402. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  403. $('#Information_Object').append(information);
  404. }
  405. });
  406. var n_oggetto = b + i;
  407. $('#n_io').text("");
  408. $('#n_io').append(n_oggetto);
  409. if (n_oggetto == 0) {
  410. $('#Information_Object').text("");
  411. var message = '<p id="no_io" class="no-results">Nessun <span>Testo</span> trovato</p>';
  412. $('#Information_Object').append(message);
  413. } else {
  414. $('#no_io').remove("");
  415. }
  416. }
  417. function Person_handle_json(json) {
  418. console.log(json);
  419. perQueries = perQueries+1;
  420. if(perQueries==3){
  421. $('#perLoader').css("display", "none");
  422. }
  423. var n_ps = $('#n_ps').text();
  424. var b = parseInt(n_ps);
  425. var i = 0;
  426. $.each(
  427. json['results']['bindings'],
  428. function (index, value) {
  429. var person = ""; /*Inserisci VALUE TIPOLOGIA*/
  430. var graph = value['graph']['value'];
  431. var graph_name = rewrite_graph(graph);
  432. person += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>' + graph_name + '<br />' +
  433. '<span id="' + value['subject']['value'] + '" class="title_doc persona">' + value['name']['value'] + '</span></p></div>' +
  434. '<div class="col d-flex align-items-start justify-content-end"><button type="button" id="' + value['subject']['value'] + '" class="persona btn btn-default" alt="persona" title="' +
  435. value['name']['value'] + '"><i class="fa fa-user"></i><p class="btn-text">Scheda Persona</p></button>' +
  436. '<button type="button" value="Persona" 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>' +
  437. /*DA QUI HYPERLINK ->*/'<button type="button" value="Persona" 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>' +
  438. /*DA QUI LOD ->*/'<a href="http://147.213.76.182/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>';
  439. i++;
  440. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  441. $('#Person').append(person);
  442. });
  443. var n_oggetto = b + i;
  444. $('#n_ps').text("");
  445. $('#n_ps').append(n_oggetto);
  446. if (n_oggetto == 0) {
  447. $('#Person').text("");
  448. var message = '<p id="no_ps" class="no-results">Nessun <span>Persona</span> trovata</p>';
  449. $('#Person').append(message);
  450. } else {
  451. $('#no_ps').remove("");
  452. }
  453. }
  454. function Place_handle_json(json) {
  455. // console.log(json);
  456. lgQueries = lgQueries+1;
  457. if(lgQueries==1){
  458. $('#lgLoader').css("display", "none");
  459. }
  460. var n_pl = $('#n_pl').text();
  461. var b = parseInt(n_pl);
  462. var i = 0;
  463. $.each(
  464. json['results']['bindings'],
  465. function (index, value) {
  466. var place = ""; /*Inserisci VALUE TIPOLOGIA*/
  467. var graph = value['graph']['value'];
  468. var graph_name = rewrite_graph(graph);
  469. place += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>' + graph_name + '<br />' +
  470. '<span id="' + value['subject']['value'] + '" class="title_doc luogo">' + value['label']['value'] + '</span></p></div>' +
  471. '<div class="col d-flex align-items-start justify-content-end"><button type="button" id="' + value['subject']['value'] + '" class="luogo btn btn-default" alt="luogo" title="' +
  472. value['label']['value'] + '"><i class="fa fa-map"></i><p class="btn-text">Scheda Luogo</p></button>' +
  473. '<button type="button" value="Luogo" 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>' +
  474. /*DA QUI HYPERLINK ->*/'<button type="button" value="Luogo" 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>' +
  475. /*DA QUI LOD ->*/'<a href="http://147.213.76.182/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>';
  476. i++;
  477. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  478. $('#Place').append(place);
  479. });
  480. var n_oggetto = b + i;
  481. $('#n_pl').text("");
  482. $('#n_pl').append(n_oggetto);
  483. if (n_oggetto == 0) {
  484. $('#Place').text("");
  485. var message = '<p id="no_pl" class="no-results">Nessun <span>Luogo</span> trovato</p>';
  486. $('#Place').append(message);
  487. } else {
  488. $('#no_pl').remove("");
  489. }
  490. }
  491. //onlick hyperlink button
  492. $(document).on("click", ".hyp", function (ev) {
  493. var baseurl = window.location.origin+window.location.pathname;
  494. let slash = baseurl.lastIndexOf("/");
  495. var type = $(this).val() + '.html';
  496. var link = this.id;
  497. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  498. var link = this.id;
  499. $("#myModal").empty();
  500. $("#myModal").css("display", "block");
  501. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  502. url + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  503. });
  504. $(document).on("click", ".lettera", function (ev) {
  505. var link = this.id;
  506. //alert(nome_autore);
  507. //$('#myModal').text("");
  508. window.open("lettera.html?link="+this.id);
  509. });
  510. $(document).on("click", ".object", function (ev) {
  511. var link = this.id;
  512. //alert(nome_autore);
  513. //$('#myModal').text("");
  514. window.open("object.html?link="+this.id);
  515. });
  516. $(document).on("click", ".artwork", function (ev) {
  517. var link = this.id;
  518. //alert(nome_autore);
  519. //$('#myModal').text("");
  520. window.open("OA.html?link="+this.id);
  521. });
  522. $(document).on("click", ".persona", function (ev) {
  523. var link = this.id;
  524. //alert(nome_autore);
  525. //$('#myModal').text("");
  526. window.open("Persona.html?link="+this.id);
  527. });
  528. $(document).on("click", ".luogo", function (ev) {
  529. var link = this.id;
  530. //alert(nome_autore);
  531. //$('#myModal').text("");
  532. window.open("Luogo.html?link="+this.id);
  533. });
  534. $(document).on("click", ".close", function (ev) {
  535. var link = this.id;
  536. //alert(nome_autore);
  537. //$('#myModal').text("");
  538. $("#myModal").css("display", "none");
  539. });
  540. $(document).on("click", ".back", function (ev) {
  541. $("#myTab").css("display", "none");
  542. });
  543. $(document).on("click", ".cit", function (ev) {
  544. var author ="RESTORE. smart access to digital heritage and memory"
  545. var year = new Date().getFullYear()
  546. var today = new Date();
  547. var dd = String(today.getDate()).padStart(2, '0');
  548. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  549. var yyyy = today.getFullYear();
  550. today = dd + '/' + mm + '/' + yyyy;
  551. var baseurl = window.location.origin+window.location.pathname;
  552. let slash = baseurl.lastIndexOf("/");
  553. var type = $(this).val() + '.html';
  554. var link = this.id;
  555. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  556. //alert(nome_autore);
  557. //$('#myModal').text("");
  558. $("#myModal").empty();
  559. $("#myModal").css("display", "block");
  560. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  561. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  562. });
  563. //#######################################
  564. function prepareQueryURL(query){
  565. sparqlEndpoint = 'http://147.213.76.182:8890/sparql/';
  566. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  567. return sparqlEndpoint + sparqlUrlParams;
  568. }
  569. // Esegue una query sull'endpoint SPARQL il cui testo completo deve essere fornito nel parametro-stringa 'query'
  570. // Restituisce una lista di oggetti json nel formato di Virtuoso
  571. // Il parametro opzionale 'isUnique', se messo a 'true' controlla che ci sia un unico risultato (un array di
  572. // lunghezza 1) e se non è così restituisce un errore.
  573. //restituisce direttamente l'oggetto della chiamata ajax
  574. function doJsonQuery(query) {
  575. queryURL = prepareQueryURL(query);
  576. return $.ajax({
  577. url: queryURL,
  578. dataType: "json",
  579. type: 'GET'
  580. });
  581. }
  582. //funzione che prende il risultato della chiamata ajax e fa tutto quello che serve dopo
  583. function manageMMO(result){
  584. // console.log(result);
  585. MMO_handle_json(result);
  586. }
  587. function manageINF(result){
  588. // console.log(result);
  589. InfObj_handle_json(result);
  590. }
  591. function managePER(result){
  592. // console.log(result);
  593. Person_handle_json(result);
  594. }
  595. function manageLG(result){
  596. // console.log(result);
  597. Place_handle_json(result);
  598. }
  599. function populateOption() {
  600. const graph_selector = document.getElementById("graph_selector");
  601. const graph_selector2 = document.getElementById("graph_selector2");
  602. const createOption = (graph_selector, text, value) => {
  603. const opt = document.createElement('option');
  604. opt.value = value;
  605. opt.text = text;
  606. graph_selector.options.add(opt);
  607. }
  608. const configureDropDownLists = (graph_selector, graph_selector2) => {
  609. const ASPO = [
  610. ['Tutti Fondi', ''],
  611. ['Fondo Datini', 'aspo_datini'],
  612. ['Fondo Ospedale Misericordia e Dolce', 'aspo_ospedale'],
  613. ['Fondo Marcovaldi', 'aspo_marcovaldi'],
  614. ['Fondo Gettatelli', 'aspo_gettatelli']
  615. ];
  616. const MPP = [
  617. ['Tutte', ''],
  618. ['Galleria Martini', 'mpp_martini'],
  619. ['Opere provenienti dall’Ospedale', 'mpp_ospedale'],
  620. ['Iconografia Datini', 'mpp_datini']
  621. ];
  622. const OVI = [
  623. ['Tutte le risorse', ''],
  624. ['Lettere', 'ovi_lettere']
  625. ];
  626. graph_selector2.options.length = 0
  627. switch (graph_selector.value) {
  628. case 'ASPO':
  629. for (const c of ASPO) {
  630. createOption(graph_selector2, c[0], c[1]);
  631. }
  632. break;
  633. case 'MPP':
  634. for (const s of MPP) {
  635. createOption(graph_selector2, s[0], s[1]);
  636. }
  637. break;
  638. case 'OVI':
  639. for (const n of OVI) {
  640. createOption(graph_selector2, n[0], n[1]);
  641. }
  642. break;
  643. default:
  644. break;
  645. }
  646. }
  647. graph_selector.addEventListener('change', () => {
  648. $("#graph_selector2").css("display", "block");
  649. configureDropDownLists(graph_selector, graph_selector2)
  650. });
  651. }
  652. function getGraph(graph1, graph2) {
  653. var search_graph = "";
  654. if ((graph1 == '') && (graph2 == '')) {
  655. search_graph = "";
  656. }
  657. else if ((graph1 != '') && (graph2 == '')) {
  658. if (graph1 == "ASPO") {
  659. search_graph = "VALUES ?g {<http://147.213.76.182:8890/aspo/datini> \
  660. <http://147.213.76.182:8890/aspo/ospedale> \
  661. <http://147.213.76.182:8890/aspo/marcovaldi> \
  662. <http://147.213.76.182:8890/aspo/gettatelli>}";
  663. }
  664. if (graph1 == "MPP") {
  665. search_graph = "VALUES ?g {<http://147.213.76.182:8890/mpp/martini> \
  666. <http://147.213.76.182:8890/mpp/ospedale> \
  667. <http://147.213.76.182:8890/mpp/datini> \
  668. <http://147.213.76.182:8890/mpp/autori> }";
  669. }
  670. if (graph1 == "OVI") {
  671. search_graph = "VALUES ?g {<http://147.213.76.182:8890/ovi/datini>}";
  672. }
  673. }
  674. else if (graph2 != '') {
  675. if (graph2 == "aspo_datini") {
  676. search_graph = "VALUES ?g {<http://147.213.76.182:8890/aspo/datini>}";
  677. }
  678. if (graph2 == "aspo_ospedale") {
  679. search_graph = "VALUES ?g {<http://147.213.76.182:8890/aspo/ospedale>}";
  680. }
  681. if (graph2 == "aspo_marcovaldi") {
  682. search_graph = "VALUES ?g {<http://147.213.76.182:8890/aspo/marcovaldi>}";
  683. }
  684. if (graph2 == "aspo_gettatelli") {
  685. search_graph = "VALUES ?g {<http://147.213.76.182:8890/aspo/gettatelli>}";
  686. }
  687. if (graph2 == "mpp_martini") {
  688. search_graph = "VALUES ?g {<http://147.213.76.182:8890/mpp/martini>}";
  689. }
  690. if (graph2 == "mpp_ospedale") {
  691. search_graph = "VALUES ?g {<http://147.213.76.182:8890/mpp/ospedale>}";
  692. }
  693. if (graph2 == "mpp_datini") {
  694. search_graph = "VALUES ?g {<http://147.213.76.182:8890/mpp/datini>}";
  695. }
  696. if (graph2 == "ovi_lettere") {
  697. search_graph = "VALUES ?g {<http://147.213.76.182:8890/ovi/datini>}";
  698. }
  699. } else {
  700. search_graph = "";
  701. }
  702. return search_graph;
  703. }
  704. function copyToClipboard(text) {
  705. var sampleTextarea = document.createElement("textarea");
  706. document.body.appendChild(sampleTextarea);
  707. sampleTextarea.value = text; //save main text in it
  708. sampleTextarea.select(); //select textarea contenrs
  709. document.execCommand("copy");
  710. document.body.removeChild(sampleTextarea);
  711. }
  712. function myFunction(){
  713. var copy = document.getElementById("myInput");
  714. copyText = copy.textContent;
  715. copyToClipboard(copyText);
  716. //copyToClipboard(copyText.value);
  717. }