search.js 29 KB

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