search.js 29 KB

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