search.js 29 KB

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