search.js 28 KB

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