search.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. var object_type = "";
  211. if (value.hasOwnProperty('types')) {
  212. mmoType = value['types']['value'];
  213. }
  214. if (value.hasOwnProperty('identifiers')) {
  215. mmoId = value['identifiers']['value'];
  216. }
  217. if (mmoType.includes("Opera d'Arte")) {
  218. object_type = "OA";
  219. object_button += '<button type="button" id="' + value['subject']['value'] +
  220. '" class="artwork btn btn-default" alt="opera d\'arte" title="' + value['label']['value'] +
  221. '"><i class="fas fa-paint-brush"></i><p class="btn-text">Scheda Opera d\'Arte</p></button>';
  222. } else {
  223. object_type = "object";
  224. object_button += '<button type="button" id="' + value['subject']['value'] +
  225. '" class="object btn btn-default" alt="oggetto" title="' + value['label']['value'] +
  226. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  227. }
  228. object += /*INIZIO DIV*/ '<div class="row res"><div class="col-8">' + graph_name + '<br />' +
  229. '<span id="' + value['subject']['value'] + '" class="title_doc ' + object_type +'">' + value['label']['value'] + '</span><br />' +
  230. '<i>' + mmoType + ' ' + mmoId + '</i></div>' +
  231. '<div class="col d-flex align-items-start justify-content-end">' + object_button +
  232. '<button type="button" value="' + object_type + '" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  233. /*DA QUI HYPERLINK ->*/'<button type="button" value="' + object_type + '" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  234. /*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>';
  235. i++;
  236. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  237. $('#Man-Made_Object').append(object);
  238. });
  239. $('#n_mmo').append(i);
  240. if (i==0) {
  241. var message = '<p class="no-results">Nessun <span>Oggetto Fisico</span> trovato</p>';
  242. $('#Man-Made_Object').append(message);
  243. }
  244. }
  245. function InfObj_handle_json(json) {
  246. console.log(json);
  247. $('#Information_Object').text("");
  248. $('#n_io').text("");
  249. var i = 0;
  250. $.each(
  251. json['results']['bindings'],
  252. function (index, value) {
  253. var information = ""; /*Inserisci VALUE TIPOLOGIA*/
  254. var graph = value['graph']['value'];
  255. var graph_name = rewrite_graph(graph);
  256. var tipo = "";
  257. var id = "";
  258. var infObject_button = "";
  259. if (value['text']['type'] != 'uri') {
  260. var myString = value['text']['value'];
  261. var str = myString.replace(/<[^>]*>?/gm, '');
  262. let string_text = str.toLowerCase();
  263. let string_len = str.length;
  264. var word = testo;
  265. let ind = string_text.indexOf(word);
  266. let length = word.length;
  267. var wl = ind + length;
  268. var resource_type = "";
  269. var link_type = "";
  270. /*var start = 0;
  271. var end = 0
  272. var bb = pp - 50;
  273. var ee = pp + length + 150;*/
  274. var pp = ind;
  275. before = str.substring(0, ind);
  276. after = str.substring(wl, string_len);
  277. let bb = before.lastIndexOf(".");
  278. let point = bb + pp;
  279. let ee = str.indexOf(".", point);
  280. console.log(bb, ee);
  281. if (bb < 0) {
  282. start = 0;
  283. } else {
  284. start = bb+1;
  285. }
  286. if (ee < 0) {
  287. end = string_len;
  288. } else {
  289. end = ee;
  290. }
  291. console.log(start, bb, end, ee);
  292. /*if (bb<=0) {
  293. start = 0;
  294. } else {
  295. start = bb;
  296. }
  297. if (ee>=string_len) {
  298. end = string_len;
  299. } else {
  300. end = ee;
  301. }*/
  302. first_chunk = str.substring(start, ind);
  303. highlight = str.substring(ind, wl);
  304. second_chunk = str.substring(wl, end);
  305. var snippet = first_chunk + "<span class='sharp'>" + highlight + "</span>" + second_chunk ;
  306. console.log(snippet);
  307. if (value.hasOwnProperty('types')) {
  308. tipo = value['types']['value'];
  309. }
  310. if (value.hasOwnProperty('id')) {
  311. id = " (" + value['id']['value'] + ")";
  312. }
  313. if (tipo.includes("lettera")) {
  314. resource_type = "lettera";
  315. link_type = "lettera";
  316. infObject_button += '<button type="button" id="' + value['subject']['value'] +
  317. '" class="lettera btn btn-default" alt="lettera" title="' + value['label']['value'] +
  318. '"><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  319. } else {
  320. resource_type = "object";
  321. link_type = "object";
  322. infObject_button += '<button type="button" id="' + value['Physical_Object']['value'] +
  323. '" class="object btn btn-default" alt="oggetto" title="' + value['label']['value'] +
  324. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  325. }
  326. '<div class="row res"><div class="col-8"><p>' + graph_name + '<br />' +
  327. '<span id="' + value['subject']['value'] + '" class="title_doc luogo">' + value['label']['value'] + '</span></p></div>'
  328. information += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>'+ snippet+'</p>' +
  329. 'In: ' + graph_name + ';<br />' +
  330. '<span id="' + value['subject']['value'] + '" class="title_doc ' + link_type + '">' + value['label']['value'] + id +
  331. '</span>;<br /><i>' + tipo + '</i><br /></div>' +
  332. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  333. '<button type="button" value="' + resource_type + '" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  334. /*DA QUI HYPERLINK ->*/'<button type="button" value="' + resource_type + '" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  335. /*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>';
  336. i++;
  337. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  338. $('#Information_Object').append(information);
  339. }
  340. });
  341. $('#n_io').append(i);
  342. if (i==0) {
  343. var message = '<p class="no-results">Nessun <span>Oggetto Informativo</span> trovato</p>';
  344. $('#Information_Object').append(message);
  345. }
  346. }
  347. function Person_handle_json(json) {
  348. console.log(json);
  349. $('#Person').text("");
  350. $('#n_ps').text("");
  351. var i = 0;
  352. $.each(
  353. json['results']['bindings'],
  354. function (index, value) {
  355. var person = ""; /*Inserisci VALUE TIPOLOGIA*/
  356. var graph = value['graph']['value'];
  357. var graph_name = rewrite_graph(graph);
  358. person += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>' + graph_name + '<br />' +
  359. '<span id="' + value['subject']['value'] + '" class="title_doc persona">' + value['name']['value'] + '</span></p></div>' +
  360. '<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="' +
  361. value['name']['value'] + '"><i class="fa fa-user"></i><p class="btn-text">Scheda Persona</p></button>' +
  362. '<button type="button" value="Persona" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  363. /*DA QUI HYPERLINK ->*/'<button type="button" value="Persona" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  364. /*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>';
  365. i++;
  366. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  367. $('#Person').append(person);
  368. });
  369. $('#n_ps').append(i);
  370. if (i==0) {
  371. var message = '<p class="no-results">Nessuna <span>Persona</span> trovata</p>';
  372. $('#Person').append(message);
  373. }
  374. }
  375. function Place_handle_json(json) {
  376. console.log(json);
  377. $('#Place').text("");
  378. $('#n_pl').text("");
  379. var i = 0;
  380. $.each(
  381. json['results']['bindings'],
  382. function (index, value) {
  383. var place = ""; /*Inserisci VALUE TIPOLOGIA*/
  384. var graph = value['graph']['value'];
  385. var graph_name = rewrite_graph(graph);
  386. place += /*INIZIO DIV*/ '<div class="row res"><div class="col-8"><p>' + graph_name + '<br />' +
  387. '<span id="' + value['subject']['value'] + '" class="title_doc luogo">' + value['label']['value'] + '</span></p></div>' +
  388. '<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="' +
  389. value['label']['value'] + '"><i class="fa fa-map"></i><p class="btn-text">Scheda Luogo</p></button>' +
  390. '<button type="button" value="Luogo" id="' + value['subject']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  391. /*DA QUI HYPERLINK ->*/'<button type="button" value="Luogo" id="' + value['subject']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  392. /*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>';
  393. i++;
  394. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  395. $('#Place').append(place);
  396. });
  397. $('#n_pl').append(i);
  398. if (i==0) {
  399. var message = '<p class="no-results">Nessun <span>Luogo</span> trovato</p>';
  400. $('#Place').append(message);
  401. }
  402. }
  403. $('#ClipArt1').click(function () {
  404. testo = $('input#TextArea1').val();
  405. results_retrieveData();
  406. search_name = "";
  407. });
  408. $('input#TextArea1').keypress(function(e) {
  409. var key = e.which;
  410. if (key == 13) // the enter key code
  411. {
  412. $('#ClipArt1').click();
  413. return false;
  414. }
  415. });
  416. //onlick hyperlink button
  417. $(document).on("click", ".hyp", function (ev) {
  418. var baseurl = window.location.origin+window.location.pathname;
  419. let slash = baseurl.lastIndexOf("/");
  420. var type = $(this).val() + '.html';
  421. var link = this.id;
  422. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  423. var link = this.id;
  424. $("#myModal").empty();
  425. $("#myModal").css("display", "block");
  426. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  427. url + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  428. });
  429. $(document).on("click", ".lettera", function (ev) {
  430. var link = this.id;
  431. //alert(nome_autore);
  432. //$('#myModal').text("");
  433. window.open("lettera.html?link="+this.id);
  434. });
  435. $(document).on("click", ".object", function (ev) {
  436. var link = this.id;
  437. //alert(nome_autore);
  438. //$('#myModal').text("");
  439. window.open("object.html?link="+this.id);
  440. });
  441. $(document).on("click", ".artwork", function (ev) {
  442. var link = this.id;
  443. //alert(nome_autore);
  444. //$('#myModal').text("");
  445. window.open("OA.html?link="+this.id);
  446. });
  447. $(document).on("click", ".persona", function (ev) {
  448. var link = this.id;
  449. //alert(nome_autore);
  450. //$('#myModal').text("");
  451. window.open("Persona.html?link="+this.id);
  452. });
  453. $(document).on("click", ".luogo", function (ev) {
  454. var link = this.id;
  455. //alert(nome_autore);
  456. //$('#myModal').text("");
  457. window.open("Luogo.html?link="+this.id);
  458. });
  459. $(document).on("click", ".close", function (ev) {
  460. var link = this.id;
  461. //alert(nome_autore);
  462. //$('#myModal').text("");
  463. $("#myModal").css("display", "none");
  464. });
  465. $(document).on("click", ".back", function (ev) {
  466. $("#myTab").css("display", "none");
  467. });
  468. $(document).on("click", ".cit", function (ev) {
  469. var author ="RESTORE. smart access to digital heritage and memory"
  470. var year = new Date().getFullYear()
  471. var today = new Date();
  472. var dd = String(today.getDate()).padStart(2, '0');
  473. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  474. var yyyy = today.getFullYear();
  475. today = dd + '/' + mm + '/' + yyyy;
  476. var baseurl = window.location.origin+window.location.pathname;
  477. let slash = baseurl.lastIndexOf("/");
  478. var type = $(this).val() + '.html';
  479. var link = this.id;
  480. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  481. //alert(nome_autore);
  482. //$('#myModal').text("");
  483. $("#myModal").empty();
  484. $("#myModal").css("display", "block");
  485. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  486. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  487. });
  488. $(document).on("click", ".scheda", function (ev) {
  489. var link = this.id;
  490. var title = this.title;
  491. //alert(nome_autore);
  492. $("#myTab").empty();
  493. $("#myTab").css("display", "block");
  494. $('#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>");
  495. /*var query_a = 'SELECT DISTINCT ?label WHERE { {<' + link +
  496. '> ?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 +
  497. '> ?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" )) }}';
  498. */
  499. var query_a = 'SELECT DISTINCT ?propLab ?object ?label WHERE {{<' + link +
  500. '> ?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 +
  501. '> ?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"))}}';
  502. var object_url_a = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_a) + '&output=json';
  503. var query_b = 'SELECT DISTINCT ?subject ?label ?property ?propertyLabel WHERE {?subject ?property <' + link +
  504. '> ; <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" ))}';
  505. var object_url_b = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_b) + '&output=json';
  506. 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 +
  507. '> <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" )) }}';
  508. var object_url_c = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_c) + '&output=json';
  509. $.ajax({//SOGGETTO
  510. url: object_url_a + '&callback=?',
  511. dataType: "json",
  512. success: function (data_a) {
  513. object_info_a(data_a);
  514. },
  515. error: function (e) {}
  516. });
  517. $.ajax({//OGGETTO
  518. url: object_url_b + '&callback=?',
  519. dataType: "json",
  520. success: function (data_b) {
  521. object_info_b(data_b);
  522. },
  523. error: function (e) {}
  524. });
  525. $.ajax({//ICONCLASS
  526. url: object_url_c + '&callback=?',
  527. dataType: "json",
  528. success: function (data_c) {
  529. object_info_c(data_c);
  530. },
  531. error: function (e) {}
  532. });
  533. });
  534. function object_info_a(json) {
  535. console.log(json);
  536. var j = 0;
  537. $('#info_link').text("");
  538. $.each(
  539. json['results']['bindings'],
  540. function (index, value) {
  541. var autore_a = "";
  542. var object = "";
  543. var object_type = value['object']['type'];
  544. if (object_type == "typed-literal" || object_type == "literal"){
  545. object = '<td>'+ value['object']['value'] + '</td>';
  546. }
  547. else{
  548. object = '<td style="width:60%;"><a href="'+ value['object']['value'] +'" target="_blank">'+ value['label']['value'] +'</a></td><td>' +
  549. '<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>' +
  550. '<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>';
  551. }
  552. autore_a += /*INIZIO DIV*/ '<tr><td style="width:25%;">' + value['propLab']['value'] + '</td>' + object + '</tr>';/*FINE DIV*/
  553. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  554. j++;
  555. $('#info_link').append(autore_a);
  556. });
  557. if (j==0) {
  558. var message_a = '<tr id="error"><td><p>Non sono presenti relazioni dirette per questa risorsa</p></td></tr>';
  559. $('#info_link').append(message_a);
  560. }
  561. }
  562. function object_info_b(json) {
  563. console.log(json);
  564. var k = 0;
  565. $('#info_obj').text("");
  566. $.each(
  567. json['results']['bindings'],
  568. function (index, value) {
  569. var autore_b = "";
  570. 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>' +
  571. '<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>' +
  572. '<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>';
  573. /*FINE DIV*/
  574. k++;
  575. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  576. $('#info_obj').append(autore_b);
  577. });
  578. if (k==0) {
  579. var message_b = '<tr id="error"><td><p>Non sono presenti relazioni inverse per questa risorsa</p></td></tr>';
  580. $('#info_obj').append(message_b);
  581. }
  582. }
  583. function object_info_c(json) {
  584. console.log(json);
  585. $('#info_ico').text("");
  586. $.each(
  587. json['results']['bindings'],
  588. function (index, value) {
  589. var autore_c = "";
  590. 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>' +
  591. '<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>' +
  592. '<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>';
  593. /*FINE DIV*/
  594. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  595. $('#info_ico').append(autore_c);
  596. });
  597. }
  598. //VISUALIZZAZIONI DATI DELL'AUTORE
  599. //FUNZIONE LETTURA LUNGHEZZA FILE JSON
  600. /*
  601. function objLength(obj){
  602. var i=0;
  603. for (var x in obj){
  604. if(obj.hasOwnProperty(x)){
  605. i++;
  606. }
  607. }
  608. return i;
  609. }
  610. */
  611. //#######################################
  612. });
  613. function copyToClipboard(text) {
  614. var sampleTextarea = document.createElement("textarea");
  615. document.body.appendChild(sampleTextarea);
  616. sampleTextarea.value = text; //save main text in it
  617. sampleTextarea.select(); //select textarea contenrs
  618. document.execCommand("copy");
  619. document.body.removeChild(sampleTextarea);
  620. }
  621. function myFunction(){
  622. var copy = document.getElementById("myInput");
  623. copyText = copy.textContent;
  624. copyToClipboard(copyText);
  625. //copyToClipboard(copyText.value);
  626. }