search.js 31 KB

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