advanced_search.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. const choiceArray = [
  2. ["Nome risorsa", "Object, OA", "label"],
  3. ["Identificatore", "Object, OA, Person, Letter, Place", "identifier"],
  4. ["Materia", "Object, OA", "material"],
  5. ["Istituto di conservazione", "Object, OA", "localization"],
  6. ["Tecnica", "OA", "technique"],
  7. ["Artista", "OA", "artist"],
  8. ["Soggetto", "OA", "subject"],
  9. ["Titolo", "Object, Inf", "title"],
  10. ["Tipo di risorsa", "Object, Inf", "type"],
  11. ["Nome proprio", "Person", "givenName"],
  12. ["Nome di famiglia", "Person", "familyName"],
  13. ["Luogo di Nascita", "Person", "birthPlace"],
  14. ["Luogo di Morte", "Person", "deathPlace"],
  15. ["Genere", "Person", "sex"],
  16. ["Data di Nascita", "Person", "birthDate"],
  17. ["Data di Morte", "Person", "deathDate"],
  18. ["Occupazione", "Person", "occupation"],
  19. ["Qualifica", "Person", "qualification"],
  20. ["Mittente", "Letter", "sender"],
  21. ["Destinatario", "Letter", "receiver"],
  22. ["Luogo di Partenza", "Letter", "startPlace"],
  23. ["Luogo di Arrivo", "Letter", "endPlace"],
  24. ["Data partenza", "Letter", "startDate"],
  25. ["Data arrivo", "Letter", "endDate"],
  26. ["Lingua", "Letter", "language"],
  27. ["Area linguistica", "Letter", "languageArea"],
  28. ["Edizione", "Letter", "edition"],
  29. ["Data", "Object", "date"],
  30. ["Lemma", "Letter", "lemma"],
  31. ["Testo libero", "Letter", "keyword"]
  32. ];
  33. const typeArray = [
  34. ["Oggetto", "Object"],
  35. ["Lettera", "Letter"],
  36. ["Opera d'Arte", "OA"],
  37. ["Persona", "Person"]
  38. ];
  39. const graphArray = [
  40. ["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini", "Object"],
  41. ["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale", "Object"],
  42. ["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi", "Object"],
  43. ["ASPO - Onomastica Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli", "Person"],
  44. ["ASPO - Onomastica Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica", "Person"],
  45. ["MPP - Artisti", "http://dev.restore.ovi.cnr.it:8890/mpp/autori", "Person"],
  46. ["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini", "Artwork"],
  47. ["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale", "Artwork"],
  48. ["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini", "Artwork"],
  49. ["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini", "Letter"]
  50. ];
  51. const objectArray = [];
  52. const personArray = [];
  53. const placeArray = [];
  54. const oaArray = [];
  55. const letterArray = [];
  56. $(document).ready(function () {
  57. //#######################################
  58. var type_selector = document.getElementById("type_selector");
  59. var collection_selector = document.getElementById("collection_selector");
  60. let x = typeArray.length;
  61. for(var i=0; i<x; i++) {
  62. var opt = document.createElement("option");
  63. opt.value= typeArray[i][1];
  64. opt.innerHTML = typeArray[i][0]; // whatever property it has
  65. // then append it to the select element
  66. type_selector.add(opt);
  67. }
  68. let z = choiceArray.length;
  69. for(var i=0; i<z; i++) {
  70. var cat = choiceArray[i][1];
  71. if (cat.includes("Object")) {
  72. objectArray.push(choiceArray[i]);
  73. }
  74. if (cat.includes("OA")) {
  75. oaArray.push(choiceArray[i]);
  76. }
  77. if (cat.includes("Person")) {
  78. personArray.push(choiceArray[i]);
  79. }
  80. if (cat.includes("Letter")) {
  81. letterArray.push(choiceArray[i]);
  82. }
  83. if (cat.includes("Place")) {
  84. placeArray.push(choiceArray[i]);
  85. }
  86. }
  87. $("#type_selector").change(function(){
  88. var selOpt = "";
  89. $(this).find("option:selected").each(function(){
  90. var optionValue = $(this).attr("value");
  91. selOpt = optionValue;
  92. if(optionValue){
  93. $(".box").not("." + optionValue).hide();
  94. $("." + optionValue).show();
  95. } else{
  96. $(".box").hide();
  97. }
  98. });
  99. $( ".container_choice" ).remove();
  100. if (selOpt == "Object") {
  101. addToListObject();
  102. populateSelGraph("Object");
  103. }
  104. else if (selOpt == "OA") {
  105. addToListOA();
  106. populateSelGraph("Artwork");
  107. }
  108. else if (selOpt == "Person") {
  109. addToListPerson();
  110. populateSelGraph("Person");
  111. }
  112. else if (selOpt == "Letter") {
  113. addToListLetter();
  114. populateSelGraph("Letter");
  115. }
  116. else {
  117. addToList();
  118. populateSelGraph("General");
  119. }
  120. }).change();
  121. /*$('[name=sel-parent]').on('change', function() {
  122. $(this).attr("id", 'example' + $(this).name());
  123. });*/
  124. });
  125. function populateOptions(selector, myArray) {
  126. var choice_selector = document.getElementById(selector);
  127. let k = myArray.length;
  128. for(var i=0; i<k; i++) {
  129. var opt = document.createElement("option");
  130. opt.value= myArray[i][1];
  131. opt.innerHTML = myArray[i][0]; // whatever property it has
  132. // then append it to the select element
  133. choice_selector.add(opt);
  134. }
  135. $('#' + selector).on( "change", function() {
  136. var numberId= selector.split("-")[1];
  137. var inputText= $( this ).find(":selected").text();
  138. var inp = "";
  139. if (inputText == "Genere") {
  140. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  141. <option>F</option> \
  142. <option>M</option> \
  143. </select>';
  144. } else if (inputText == "Materia"){
  145. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  146. <option>Tempera</option> \
  147. <option>Tavola</option> \
  148. <option>Stucco</option> \
  149. <option>Rame</option> \
  150. <option>Carta</option> \
  151. <option>Tela</option> \
  152. </select>';
  153. } else if (inputText == "Tecnica"){
  154. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  155. <option>Pittura a olio</option> \
  156. <option>Doratura</option> \
  157. </select>';
  158. } else if (inputText == "Tipo di risorsa"){
  159. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  160. <option>Documento</option> \
  161. <option>Carteggio</option> \
  162. <option>Lettera</option> \
  163. <option>Libro</option> \
  164. <option>Documenti diversi</option> \
  165. </select>';
  166. } else if (inputText == "Data"){
  167. var inp = '<div id="box_' + numberId + 'a" class="container_choice"><div class="choice_box"><select id ="choice_selector-' + numberId + '_a" value=' + numberId + '_a" name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  168. <option selected value="0">Da</option> \
  169. <input type="date" id="inputchoiceSelector_'+ numberId +'_a" name="start" value="1300-01-01"> \
  170. </select></div></div> \
  171. <div id="box_' + numberId + '_b" class="container_choice"><div class="choice_box"><select id ="choice_selector-' + numberId + '_b" value=' + numberId + '_b" name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  172. <option selected value="0">A</option> \
  173. <input type="date" id="inputchoiceSelector_'+ numberId +'_b" name="end" value="1900-12-31"> \
  174. </select></div></div>';
  175. }
  176. else {
  177. inp = '<input type="text" id="inputchoiceSelector_'+ numberId +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2">';
  178. }
  179. var sect = 'sect-' + String(numberId);
  180. var inDiv = document.getElementById(sect);
  181. inDiv.innerHTML = inp;
  182. console.log(selector);
  183. /*$('#inputchoiceSelector_' + numberId).val(inputText);
  184. $('#inputchoiceSelector_' + numberId).id(inputText);*/
  185. });
  186. }
  187. var val = 0;
  188. function addToList() {
  189. val = val+1;
  190. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  191. <option selected value="0">Scegli un\'opzione</option> \
  192. </select><div id="sect-' + val + '"></div></div></div>';
  193. $('#drop-down-content').append(sel);
  194. var selector = 'choice_selector-' + val;
  195. populateOptions(selector, choiceArray);
  196. }
  197. function addToListObject() {
  198. val = val+100;
  199. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  200. <option selected value="0">Scegli un\'opzione</option> \
  201. </select><div id="sect-' + val + '"></div></div></div>';
  202. $('#drop-down-content-Object').append(sel);
  203. var selector = 'choice_selector-' + val;
  204. populateOptions(selector, objectArray);
  205. }
  206. function addToListOA() {
  207. val = val+200;
  208. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  209. <option selected value="0">Scegli un\'opzione</option> \
  210. </select><div id="sect-' + val + '"></div></div></div>';
  211. $('#drop-down-content-OA').append(sel);
  212. var selector = 'choice_selector-' + val;
  213. populateOptions(selector, oaArray);
  214. }
  215. function addToListPerson() {
  216. val = val+300;
  217. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  218. <option selected value="0">Scegli un\'opzione</option> \
  219. </select><div id="sect-' + val + '"></div></div></div>';
  220. $('#drop-down-content-Person').append(sel);
  221. var selector = 'choice_selector-' + val;
  222. populateOptions(selector, personArray);
  223. }
  224. function addToListLetter() {
  225. val = val+400;
  226. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  227. <option selected value="0">Scegli un\'opzione</option> \
  228. </select><div id="sect-' + val + '"></div></div></div>';
  229. $('#drop-down-content-Letter').append(sel);
  230. var selector = 'choice_selector-' + val;
  231. populateOptions(selector, letterArray);
  232. }
  233. function addToListPlace() {
  234. val = val+500;
  235. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  236. <option selected value="0">Scegli un\'opzione</option> \
  237. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  238. </select></div></div>';
  239. $('#drop-down-content-Place').append(sel);
  240. var selector = 'choice_selector-' + val;
  241. populateOptions(selector, placeArray);
  242. }
  243. //Get parameters from select and input options to build the query
  244. function getParameters() {
  245. $('#Loader').css("display", "block");
  246. var cc = document.getElementById("type_selector").value;
  247. if (cc != "General") {
  248. const arr = [];
  249. const collection = document.getElementsByClassName("advanced-form-select");
  250. for (let i = 0; i < collection.length; i++) {
  251. var x = collection[i].id;
  252. var t = document.getElementById(x);
  253. var e = t.options[t.selectedIndex].text;
  254. var numberId= x.split("-")[1]
  255. var inputId = "inputchoiceSelector_" + numberId;
  256. if (!!document.getElementById(inputId)) {
  257. var inputText = document.getElementById(inputId).value;
  258. var el = [e, inputText];
  259. console.log([inputText, el]);
  260. arr.push(el);
  261. }
  262. }
  263. constructQuery(arr);
  264. }
  265. else {
  266. alert("Seleziona una categoria")
  267. }
  268. /*$('#query_results').append(arr);
  269. testo = $('input#writeText').val();*/
  270. }
  271. function removeElement(id_element) {
  272. const element = document.getElementById(id_element);
  273. element.remove();
  274. }
  275. //Build query with harvested parametes
  276. function constructQuery(params) {
  277. var g = document.getElementById("collection_selector");
  278. var graph = g.value;
  279. var search_graph = "?g";
  280. if (graph != "") {
  281. search_graph = '<' + graph + '>';
  282. }
  283. var search_type = "";
  284. var ct = document.getElementById("type_selector");
  285. var choosen_type = ct.value;
  286. console.log(choosen_type);
  287. var search_identifier = "";
  288. if (choosen_type == "Object") {
  289. search_type = "?subject rdf:type crm:E22_Man-Made_Object . ";
  290. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  291. ?uri_identifier rdfs:label ?identifier ; \
  292. crm:P2_has_type 'Segnatura' .";
  293. }
  294. if (choosen_type == "Letter") {
  295. search_type = "?subject crm:P128_carries ?information_object . \
  296. ?information_object crm:P2_has_type ?uri_letter . \
  297. ?uri_letter rdfs:label 'lettera' ."
  298. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  299. ?uri_identifier rdfs:label ?identifier ; \
  300. crm:P2_has_type 'Segnatura' .";
  301. }
  302. if (choosen_type == "OA") {
  303. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  304. ?uri_identifier rdfs:label ?identifier ; \
  305. crm:P2_has_type 'Codice univoco del bene (NCT)' .";
  306. }
  307. if (choosen_type == "Person") {
  308. search_type = "?subject rdf:type crm:E21_Person . ";
  309. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  310. ?uri_identifier rdfs:label ?identifier .";
  311. }
  312. var label = ""; //
  313. var identificatore = ""; //
  314. var dimensione = ""; //
  315. var materia = ""; //
  316. var localizzazione = ""; //
  317. var tecnica = ""; //
  318. var artista = ""; //
  319. var soggetto = ""; //
  320. var titolo = ""; //
  321. var tipo = ""; //
  322. var note = ""; //
  323. var riferimenti = ""; //
  324. var nome_proprio = ""; //
  325. var nome_di_famiglia = ""; //
  326. var patronimico = ""; //
  327. var luogo_di_Nascita = ""; //
  328. var luogo_di_Morte = ""; //
  329. var genere = ""; //
  330. var data_di_Nascita = ""; //
  331. var data_di_Morte = ""; //
  332. var occupazione = ""; //
  333. var qualifica = ""; //
  334. var gruppi_di_appartenenza = ""; //
  335. var mittente = ""; //
  336. var destinatario = ""; //
  337. var luogo_di_Partenza = ""; //
  338. var luogo_di_Arrivo = ""; //
  339. var data_partenza = ""; //
  340. var data_arrivo = ""; //
  341. var lingua = ""; //
  342. var area_linguistica = ""; //
  343. var edizione = ""; //
  344. var lemma = ""; //
  345. var testo = ""; //
  346. var data = ""; //
  347. var start = "";
  348. var finish = "";
  349. var letter_event = ""; //
  350. var infObj = ""; //
  351. var id = ""; //
  352. var dm = ""; //
  353. var mt = ""; //
  354. var locl = ""; //
  355. var tec = ""; //
  356. var at = ""; //
  357. var sg = ""; //
  358. var tt = ""; //
  359. var tp = ""; //
  360. var nt = ""; //
  361. var rf = ""; //
  362. var np = ""; //
  363. var nf = ""; //
  364. var pt = ""; //
  365. var ln = ""; //
  366. var lm = ""; //
  367. var gr = ""; //
  368. var dn = ""; //
  369. var dts = ""; //
  370. var oc = ""; //
  371. var qf = ""; //
  372. var ga = ""; //
  373. var mit = ""; //
  374. var des = ""; //
  375. var lp = ""; //
  376. var la = ""; //
  377. var dp = ""; //
  378. var da = ""; //
  379. var lin = ""; //
  380. var alin = ""; //
  381. var ed = ""; //
  382. var lem = ""; //
  383. var ttx = ""; //
  384. var dt = ""; //
  385. var st = "";
  386. var fn = "";
  387. for (let i = 0; i < params.length; i++) {
  388. if(params[i][0] == "Nome risorsa" && (params[i][1] != "")) {
  389. label = "?label bif:contains \"\' "+ params[i][1] + " \'\" . ";
  390. }
  391. if(params[i][0] == "Identificatore" && (params[i][1] != "")) {
  392. id = " ?identifier";
  393. identificatore = "FILTER (CONTAINS(?identifier, \'"+ params[i][1] +"\'))";
  394. }
  395. if(params[i][0] == "Dimensione" && (params[i][1] != "")) {
  396. dm = " ?dimension";
  397. dimensione = "?subject crm:P43_has_dimension ?uri_dimension . \
  398. ?uri_dimension rdfs:label ?dimension . \
  399. ?dimension bif:contains \"\'"+ params[i][1] +"\'\" ."
  400. }
  401. if(params[i][0] == "Materia" && (params[i][1] != "")) {
  402. mt = " ?material";
  403. materia = "?subject crm:P45_consists_of ?uri_material . \
  404. ?uri_material rdfs:label ?material . \
  405. ?material bif:contains \"\'"+ params[i][1] +"\'\" ."
  406. }
  407. if(params[i][0] == "Istituto di conservazione" && (params[i][1] != "")) {
  408. locl = " ?location";
  409. localizzazione = "?subject crm:P52_has_current_owner ?uri_location . \
  410. ?uri_location rdfs:label ?location . \
  411. ?location bif:contains \"\'"+ params[i][1] +"\'\" ."
  412. }
  413. if(params[i][0] == "Tecnica" && (params[i][1] != "")) {
  414. tec = " ?technique";
  415. tecnica = "?event ?pp ?subject . \
  416. ?event crm:P32_used_general_technique ?uri_technique . \
  417. ?uri_technique rdfs:label ?technique . \
  418. ?technique bif:contains \"\'"+ params[i][1] +"\'\" . "
  419. }
  420. if (params[i][0] == "Artista" && (params[i][1] != "")) {
  421. at = " ?artist";
  422. artista = "?subject rdfs:label ?label . \
  423. ?production crm:P108_has_produced ?subject . \
  424. ?pc crm:P01_has_domain ?production . \
  425. ?pc crm:P02_has_range ?range . \
  426. ?range rdfs:label ?artist . \
  427. ?artist bif:contains \"\'"+ params[i][1] +"\'\" ."
  428. }
  429. if (params[i][0] == "Soggetto" && (params[i][1] != "")) {
  430. sg = " ?depiction";
  431. soggetto = "?subject crm:P62_depicts ?uri_depiction . \
  432. ?uri_depiction rdfs:label ?depiction . \
  433. ?depiction bif:contains \"\'"+ params[i][1] +"\'\" ."
  434. }
  435. if (params[i][0] == "Titolo" && (params[i][1] != "")) {
  436. tt = " ?title";
  437. infObj = "?subject crm:P128_carries ?information_object .";
  438. titolo = "?information_object crm:P1_is_identified_by ?uri_title . \
  439. ?uri_title rdfs:label ?title . \
  440. ?title bif:contains \"\'"+ params[i][1] +"\'\" ."
  441. }
  442. if (params[i][0] == "Tipo di risorsa" && (params[i][1] != "")) {
  443. tp = " ?type";
  444. infObj = "?subject crm:P128_carries ?information_object .";
  445. tipo = "?information_object crm:P2_has_type ?uri_type . \
  446. ?uri_type rdfs:label ?type . \
  447. ?type bif:contains \"\'"+ params[i][1] +"\'\" ."
  448. }
  449. if (params[i][0] == "Note" && (params[i][1] != "")) {
  450. nt = " ?note";
  451. note = "?subject crm:P3_has_note ?uri_note . \
  452. ?uri_note rdfs:label ?note . \
  453. ?note bif:contains \"\'"+ params[i][1] +"\'\" .";
  454. }
  455. if (params[i][0] == "Riferimenti" && (params[i][1] != "")) {
  456. rf = " ?ref";
  457. riferimenti = "?subject crm:P67_refers_to ?uri_ref . \
  458. ?uri_ref rdfs:label ?ref . \
  459. ?ref bif:contains \"\'"+ params[i][1] +"\'\" . "
  460. }
  461. if (params[i][0] == "Nome proprio" && (params[i][1] != "")) {
  462. np = " ?givenName";
  463. nome_proprio = "?subject foaf:givenName ?givenName . \
  464. ?givenName bif:contains \"\'"+ params[i][1] +"\'\" . "
  465. }
  466. if (params[i][0] == "Nome di famiglia" && (params[i][1] != "")) {
  467. nf = " ?familyName";
  468. nome_di_famiglia = "?subject foaf:familyName ?familyName . \
  469. ?familyName bif:contains \"\'"+ params[i][1] +"\'\" . "
  470. }
  471. if (params[i][0] == "Patronimico" && (params[i][1] != "")) {
  472. pt = " ?patronymic";
  473. patronimico = "?subject person:patronymicName ?patronymic . \
  474. ?patronymic bif:contains \"\'"+ params[i][1] +"\'\" . "
  475. }
  476. if (params[i][0] == "Luogo di Nascita" && (params[i][1] != "")) {
  477. ln = " ?birthPlace";
  478. luogo_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  479. ?Birth crm:P7_took_place_at ?uri_birthPlace . \
  480. ?uri_birthPlace rdfs:label ?birthPlace . \
  481. ?birthPlace bif:contains \""+ params[i][1] +"\" . "
  482. }
  483. if (params[i][0] == "Luogo di Morte" && (params[i][1] != "")) {
  484. lm = " ?deathPlace";
  485. luogo_di_Morte = "?subject crm:P100i_died_in ?Death . \
  486. ?Death crm:P7_took_place_at ?uri_deathPlace . \
  487. ?uri_deathPlace rdfs:label ?deathPlace \
  488. ?deathPlace bif:contains \""+ params[i][1] +"\" . "
  489. }
  490. if (params[i][0] == "Genere" && (params[i][1] != "")) {
  491. gr = "?genere";
  492. genere = "?subject foaf:gender ?genere . \
  493. ?genere bif:contains \""+ params[i][1] +"\" . "
  494. }
  495. if (params[i][0] == "Data di Nascita" && (params[i][1] != "")) {
  496. dn = " ?Birth_TS";
  497. data_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  498. ?Birth crm:P4_has_time-span ?Birth_TS . \
  499. ?Birth_TS rdfs:label \""+ params[i][1] +"\" ."
  500. }
  501. if (params[i][0] == "Data di Morte" && (params[i][1] != "")) {
  502. dts = " ?Death_TS";
  503. data_di_Morte = "?subject crm:P100i_died_in ?Death . \
  504. ?Death crm:P4_has_time-span ?Death_TS . \
  505. ?Death_TS rdfs:label \""+ params[i][1] +"\" . "
  506. }
  507. if (params[i][0] == "Qualifica" && (params[i][1] != "")) {
  508. qf = " ?qualification";
  509. qualifica = "?subject schema:honorificPrefix ?qualification . \
  510. ?qualification bif:contains \"\'"+ params[i][1] +"\'\" . "
  511. }
  512. if (params[i][0] == "Occupazione" && (params[i][1] != "")) {
  513. oc = " ?occupation";
  514. occupazione = "?subject schema:hasOccupation ?uriOccupation . \
  515. ?uriOccupation rdf:type schema:Occupation; \
  516. rdfs:label ?occupation . \
  517. ?occupation bif:contains \"\'"+ params[i][1] +"\'\" . "
  518. }
  519. if (params[i][0] == "Gruppi di appartenenza" && (params[i][1] != "")) {
  520. ga = " ?group";
  521. gruppi_di_appartenenza = "?subject crm:P107i_is_current_or_former_member_of ?uriGroup . \
  522. ?uriGroup rdfs:label ?group . \
  523. ?group bif:contains \"\'"+ params[i][1] +"\'\" . "
  524. }
  525. if (params[i][0] == "Mittente" && (params[i][1] != "")) {
  526. mit = " ?mittente";
  527. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  528. ?send rdfs:subClassOf ?mov_ev ; \
  529. rdf:type crm:EL2_Send_Letter . \
  530. ?receive rdfs:subClassOf ?mov_ev; \
  531. rdf:type crm:EL3_Receive_Letter . ";
  532. mittente = "?send crm:P01_has_domain ?pcS . \
  533. ?pcS crm:P02_has_range ?uriSender . \
  534. ?uriSender rdfs:label ?mittente . \
  535. ?mittente bif:contains \"\'"+ params[i][1] +"\'\" . "
  536. }
  537. if (params[i][0] == "Destinatario" && (params[i][1] != "")) {
  538. des = " ?destinatario";
  539. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  540. ?send rdfs:subClassOf ?mov_ev ; \
  541. rdf:type crm:EL2_Send_Letter . \
  542. ?receive rdfs:subClassOf ?mov_ev; \
  543. rdf:type crm:EL3_Receive_Letter . ";
  544. destinatario = "?receive crm:P01_has_domain ?pcR . \
  545. ?pcR crm:P02_has_range ?uriReceiver . \
  546. ?uriReceiver rdfs:label ?destinatario . \
  547. ?destinatario bif:contains \"\'"+ params[i][1] +"\'\" . "
  548. }
  549. if (params[i][0] == "Luogo di Partenza" && (params[i][1] != "")) {
  550. lp = " ?luogo_partenza";
  551. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  552. ?send rdfs:subClassOf ?mov_ev ; \
  553. rdf:type crm:EL2_Send_Letter . \
  554. ?receive rdfs:subClassOf ?mov_ev; \
  555. rdf:type crm:EL3_Receive_Letter . ";
  556. luogo_di_Partenza = "?send crm:P27_moved_from ?uriLuogoPartenza . \
  557. ?uriLuogoPartenza rdfs:label ?luogo_partenza . \
  558. ?luogo_partenza bif:contains \"\'"+ params[i][1] +"\'\" . "
  559. }
  560. if (params[i][0] == "Luogo di Arrivo" && (params[i][1] != "")) {
  561. la = " ?luogo_arrivo";
  562. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  563. ?send rdfs:subClassOf ?mov_ev ; \
  564. rdf:type crm:EL2_Send_Letter . \
  565. ?receive rdfs:subClassOf ?mov_ev; \
  566. rdf:type crm:EL3_Receive_Letter . ";
  567. luogo_di_Arrivo = "?receive crm:P26_moved_to ?uriLuogoArrivo . \
  568. ?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
  569. ?luogo_arrivo bif:contains \"\'"+ params[i][1] +"\'\" . "
  570. }
  571. if (params[i][0] == "Data partenza" && (params[i][1] != "")) {
  572. dp = " ?timeSpanSend";
  573. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  574. ?send rdfs:subClassOf ?mov_ev ; \
  575. rdf:type crm:EL2_Send_Letter . \
  576. ?receive rdfs:subClassOf ?mov_ev; \
  577. rdf:type crm:EL3_Receive_Letter . ";
  578. data_partenza = "?send crm:P4_has_time-span ?time_spanS . \
  579. ?time_spanS rdfs:label ?timeSpanSend . \
  580. ?timeSpanSend bif:contains \"\'"+ params[i][1] +"\'\" . "
  581. }
  582. if (params[i][0] == "Data arrivo" && (params[i][1] != "")) {
  583. da = " ?timeSpanReceive";
  584. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  585. ?send rdfs:subClassOf ?mov_ev ; \
  586. rdf:type crm:EL2_Send_Letter . \
  587. ?receive rdfs:subClassOf ?mov_ev; \
  588. rdf:type crm:EL3_Receive_Letter . ";
  589. data_arrivo = "?receive crm:P4_has_time-span ?time_spanR . \
  590. ?time_spanR rdfs:label ?timeSpanReceive .\
  591. ?timeSpanReceive bif:contains \"\'"+ params[i][1] +"\'\" . "
  592. }
  593. if (params[i][0] == "Lingua" && (params[i][1] != "")) {
  594. lin = " ?lingua";
  595. lingua = "?information_object crm:P72_has_language ?language . \
  596. ?language rdfs:label ?lingua . \
  597. ?lingua bif:contains \"\'"+ params[i][1] +"\'\" ."
  598. }
  599. if (params[i][0] == "Area linguistica" && (params[i][1] != "")) {
  600. alin = " ?area_linguistica";
  601. area_linguistica = "?information_object crm:P72_has_language ?language . \
  602. ?language crm:P3_has_note ?area . \
  603. ?area rdfs:label ?area_linguistica .\
  604. ?area_linguistica bif:contains \"\'"+ params[i][1] +"\'\" ."
  605. }
  606. if (params[i][0] == "Edizione" && (params[i][1] != "")) {
  607. ed = " ?edizione";
  608. edizione = "?edition crm:P70_documents ?information_object ; \
  609. crm:P1_is_identified_by ?edition_id . \
  610. ?edition_id rdfs:label ?edizione . \
  611. ?edizione bif:contains \"\'"+ params[i][1] +"\'\" ."
  612. }
  613. if (params[i][0] == "Lemma" && (params[i][1] != "")) {
  614. lem = " ?lemma";
  615. lemma = "?information_object crm:P67_refers_to ?link_lemma . \
  616. ?link_lemma rdfs:label ?lemma. \
  617. ?lemma bif:contains \"\'"+ params[i][1] +"\'\" ."
  618. }
  619. if (params[i][0] == "Testo libero" && (params[i][1] != "")) {
  620. ttx = " ?testo";
  621. testo = "?information_object crm:P190_has_symbolic_content ?testo . \
  622. ?testo bif:contains \"\'"+ params[i][1] +"\'\" ."
  623. }
  624. if (params[i][0] == "Data" && (params[i][1] != "")) {
  625. dt = " ?date";
  626. data = "?subject ?property ?event . \
  627. ?event crm:P4_has_time-span ?uri_date . \
  628. ?uri_date rdfs:label ?date . \
  629. ?date bif:contains \"\'"+ params[i][1] +"\'\" ."
  630. }
  631. if (params[i][0] == "Da" && (params[i][1] != "")) {
  632. st = " ?start";
  633. start = "?subject ?property ?event_start . \
  634. ?event_start crm:P4_has_time-span ?uri_date_start . \
  635. ?uri_date_start rdfs:label ?date_start ; \
  636. time:hasBeginning ?start . \
  637. FILTER (?start >= \""+ params[i][1] +"\"^^xsd:date)";
  638. }
  639. if (params[i][0] == "A" && (params[i][1] != "")) {
  640. fn = " ?end";
  641. finish = "?subject ?property ?event_end . \
  642. ?event_end crm:P4_has_time-span ?uri_date_end . \
  643. ?uri_date_end rdfs:label ?date_end ; \
  644. time:hasEnd ?end . \
  645. FILTER (?end <= \""+ params[i][1] +"\"^^xsd:date)";
  646. }
  647. }
  648. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  649. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  650. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  651. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  652. PREFIX schema: <http://schema.org/> \
  653. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  654. PREFIX person: <http://www.w3.org/ns/person#> \
  655. PREFIX time: <https://www.w3.org/TR/owl-time#>"
  656. query = prefixes + " SELECT DISTINCT ?subject ?label ?identifier " + dm + mt + locl + tec + at
  657. + sg + tt + tp + nt + rf + np + nf + pt + ln + lm + gr + dn + dts + oc + qf + ga + mit
  658. + des + lp + la + dp + da + lin + alin + ed + lem + dt + st + fn + ttx + " \
  659. WHERE {GRAPH " + search_graph + " {?subject ?property ?object } \
  660. ?subject rdfs:label ?label . "
  661. + search_identifier + infObj + letter_event + label + search_type + dimensione + materia + localizzazione + tecnica
  662. + artista + titolo + tipo + note + riferimenti + nome_proprio + nome_di_famiglia
  663. + patronimico + luogo_di_Nascita + luogo_di_Morte + genere + data_di_Nascita
  664. + data_di_Morte + qualifica + occupazione + gruppi_di_appartenenza + mittente + destinatario
  665. +luogo_di_Partenza + luogo_di_Arrivo + data_partenza + data_arrivo + lingua
  666. + area_linguistica + edizione + lemma + data + identificatore + start + finish + testo + "}"
  667. var query_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
  668. console.log(query);
  669. $.ajax({
  670. url: query_url + '&callback=?',
  671. dataType: "json",
  672. success: function (data) {
  673. query_handle_json(data, choosen_type);
  674. },
  675. error: function (e) {}
  676. });
  677. }
  678. function query_handle_json(json, choosen_type) {
  679. console.log(json);
  680. var resulType = "";
  681. if (choosen_type == "Object") {
  682. resulType = "object";
  683. }
  684. if (choosen_type == "Letter") {
  685. resulType = "object";
  686. }
  687. if (choosen_type == "OA") {
  688. resulType = "artwork";
  689. }
  690. if (choosen_type == "Person") {
  691. resulType = "persona";
  692. }
  693. $('#query_results').text("");
  694. var i = 0;
  695. const first_row = [];
  696. $.each(
  697. json['head']['vars'],
  698. function (index, value) {
  699. first_row.push(value);
  700. });
  701. var t_head = '<div class="row t_head">';
  702. for (let k = 1; k < first_row.length; k++) {
  703. var param = renameCol(first_row[k]);
  704. t_head += '<div class="col-auto">' + param + '</div>';
  705. }
  706. t_head += '</div>';
  707. $('#query_results').append(t_head);
  708. $.each(
  709. json['results']['bindings'],
  710. function (index, value) {
  711. var object = "";
  712. var link = value['subject']['value'];
  713. var label = value['label']['value'];
  714. object += '<div class="row"><div id="' + link + '" class="col-auto link ' + resulType + '">' + label + '</div>';
  715. if (value.hasOwnProperty('identifier')) {
  716. identifier = value['identifier']['value'];
  717. object += '<div class="col-auto">' + identifier + '</div>';
  718. }
  719. if (value.hasOwnProperty('dimension')) {
  720. dimension = value['dimension']['value'];
  721. object += '<div class="col-auto">' + dimension + '</div>';
  722. }
  723. if (value.hasOwnProperty('material')) {
  724. material = value['material']['value'];
  725. object += '<div class="col-auto">' + material + '</div>';
  726. }
  727. if (value.hasOwnProperty('location')) {
  728. localization = value['location']['value'];
  729. object += '<div class="col-auto">' + localization + '</div>';
  730. }
  731. if (value.hasOwnProperty('technique')) {
  732. technique = value['technique']['value'];
  733. object += '<div class="col-auto">' + technique + '</div>';
  734. }
  735. if (value.hasOwnProperty('artist')) {
  736. artist = value['artist']['value'];
  737. object += '<div class="col-auto">' + artist + '</div>';
  738. }
  739. if (value.hasOwnProperty('depiction')) {
  740. depiction = value['depiction']['value'];
  741. object += '<div class="col-auto">' + depiction + '</div>';
  742. }
  743. if (value.hasOwnProperty('title')) {
  744. title = value['title']['value'];
  745. object += '<div class="col-auto">' + title + '</div>';
  746. }
  747. if (value.hasOwnProperty('type')) {
  748. type = value['type']['value'];
  749. object += '<div class="col-auto">' + type + '</div>';
  750. }
  751. if (value.hasOwnProperty('note')) {
  752. note = value['note']['value'];
  753. object += '<div class="col-auto">' + note + '</div>';
  754. }
  755. if (value.hasOwnProperty('ref')) {
  756. ref = value['ref']['value'];
  757. object += '<div class="col-auto">' + ref + '</div>';
  758. }
  759. if (value.hasOwnProperty('givenName')) {
  760. givenName = value['givenName']['value'];
  761. object += '<div class="col-auto">' + givenName + '</div>';
  762. }
  763. if (value.hasOwnProperty('familyName')) {
  764. familyName = value['familyName']['value'];
  765. object += '<div class="col-auto">' + familyName + '</div>';
  766. }
  767. if (value.hasOwnProperty('patronymic')) {
  768. patronymic = value['patronymic']['value'];
  769. object += '<div class="col-auto">' + patronymic + '</div>';
  770. }
  771. if (value.hasOwnProperty('birthPlace')) {
  772. birthPlace = value['birthPlace']['value'];
  773. object += '<div class="col-auto">' + birthPlace + '</div>';
  774. }
  775. if (value.hasOwnProperty('deathPlace')) {
  776. deathPlace = value['deathPlace']['value'];
  777. object += '<div class="col-auto">' + deathPlace + '</div>';
  778. }
  779. if (value.hasOwnProperty('genere')) {
  780. genere = value['genere']['value'];
  781. object += '<div class="col-auto">' + genere + '</div>';
  782. }
  783. if (value.hasOwnProperty('Birth_TS')) {
  784. Birth_TS = value['Birth_TS']['value'];
  785. object += '<div class="col-auto">' + Birth_TS + '</div>';
  786. }
  787. if (value.hasOwnProperty('Death_TS')) {
  788. Death_TS = value['Death_TS']['value'];
  789. object += '<div class="col-auto">' + Death_TS + '</div>';
  790. }
  791. if (value.hasOwnProperty('qualification')) {
  792. qualification = value['qualification']['value'];
  793. object += '<div class="col-auto">' + qualification + '</div>';
  794. }
  795. if (value.hasOwnProperty('occupation')) {
  796. occupation = value['occupation']['value'];
  797. object += '<div class="col-auto">' + occupation + '</div>';
  798. }
  799. if (value.hasOwnProperty('group')) {
  800. group = value['group']['value'];
  801. object += '<div class="col-auto">' + group + '</div>';
  802. }
  803. if (value.hasOwnProperty('mittente')) {
  804. mittente = value['mittente']['value'];
  805. object += '<div class="col-auto">' + mittente + '</div>';
  806. }
  807. if (value.hasOwnProperty('destinatario')) {
  808. destinatario = value['destinatario']['value'];
  809. object += '<div class="col-auto">' + destinatario + '</div>';
  810. }
  811. if (value.hasOwnProperty('luogo_partenza')) {
  812. luogo_partenza = value['luogo_partenza']['value'];
  813. object += '<div class="col-auto">' + luogo_partenza + '</div>';
  814. }
  815. if (value.hasOwnProperty('luogo_arrivo')) {
  816. luogo_arrivo = value['luogo_arrivo']['value'];
  817. object += '<div class="col-auto">' + luogo_arrivo + '</div>';
  818. }
  819. if (value.hasOwnProperty('timeSpanSend')) {
  820. timeSpanSend = value['timeSpanSend']['value'];
  821. object += '<div class="col-auto">' + timeSpanSend + '</div>';
  822. }
  823. if (value.hasOwnProperty('timeSpanReceive')) {
  824. timeSpanReceive = value['timeSpanReceive']['value'];
  825. object += '<div class="col-auto">' + timeSpanReceive + '</div>';
  826. }
  827. if (value.hasOwnProperty('lingua')) {
  828. lingua = value['lingua']['value'];
  829. object += '<div class="col-auto">' + lingua + '</div>';
  830. }
  831. if (value.hasOwnProperty('area_linguistica')) {
  832. area_linguistica = value['area_linguistica']['value'];
  833. object += '<div class="col-auto">' + area_linguistica + '</div>';
  834. }
  835. if (value.hasOwnProperty('edizione')) {
  836. edizione = value['edizione']['value'];
  837. object += '<div class="col-auto">' + edizione + '</div>';
  838. }
  839. if (value.hasOwnProperty('lemma')) {
  840. lemma = value['lemma']['value'];
  841. object += '<div class="col-auto">' + lemma + '</div>';
  842. }
  843. if (value.hasOwnProperty('testo')) {
  844. testo = value['testo']['value'];
  845. object += '<div class="col-auto">' + testo + '</div>';
  846. }
  847. if (value.hasOwnProperty('date')) {
  848. date = value['date']['value'];
  849. object += '<div class="col-auto">' + date + '</div>';
  850. }
  851. if (value.hasOwnProperty('start')) {
  852. start = value['start']['value'];
  853. object += '<div class="col-auto">' + start + '</div>';
  854. }
  855. if (value.hasOwnProperty('end')) {
  856. end = value['end']['value'];
  857. object += '<div class="col-auto">' + end + '</div>';
  858. }
  859. object += '</div>';
  860. i++;
  861. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  862. $('#query_results').append(object);
  863. });
  864. if (i==0) {
  865. var message = '<p>Nessun risultato trovato</p>';
  866. $('#query_results').append(message);
  867. }
  868. $('#Loader').css("display", "none");
  869. document.getElementById("n_res").innerHTML = i;
  870. }
  871. function populateSelGraph(graphType) {
  872. let y = graphArray.length;
  873. collection_selector.innerHTML = "";
  874. if (graphType != "General") {
  875. collection_selector.style.color = '#202122';
  876. collection_selector.style.cursor = 'pointer';
  877. collection_selector.style.backgroundColor = '#f8f9fa';
  878. collection_selector.style.backgroundImage = 'linear-gradient(to top, #fff, #fff 33%)';
  879. } else {
  880. collection_selector.style.color = '#a1a1a1';
  881. collection_selector.style.cursor = 'not-allowed';
  882. collection_selector.style.backgroundColor = '#eee';
  883. collection_selector.style.backgroundImage = 'linear-gradient(to top, #ddd, #eee 33%)';
  884. }
  885. var genOpt = document.createElement("option");
  886. genOpt.value= "";
  887. genOpt.innerHTML = "Tutte le Collezioni";
  888. collection_selector.add(genOpt);
  889. for(var i=0; i<y; i++) {
  890. if (graphType == graphArray[i][2]) {
  891. var opt = document.createElement("option");
  892. opt.value= graphArray[i][1];
  893. opt.innerHTML = graphArray[i][0]; // whatever property it has
  894. // then append it to the select element
  895. collection_selector.add(opt);
  896. }
  897. }
  898. }
  899. function renameCol(param) {
  900. if (param == "label") {
  901. return ("Denominazione");
  902. }
  903. else if (param == "identifier") {
  904. return ("Identificatore");
  905. }
  906. else if (param == "dimension") {
  907. return ("Dimensioni");
  908. }
  909. else if (param == "material") {
  910. return ("Materiale");
  911. }
  912. else if (param == "location") {
  913. return ("Istituto di conservazione");
  914. }
  915. else if (param == "technique") {
  916. return ("Tecnica");
  917. }
  918. else if (param == "artist") {
  919. return ("Artista");
  920. }
  921. else if (param == "depiction") {
  922. return ("Soggetto");
  923. }
  924. else if (param == "title") {
  925. return ("Titolo");
  926. }
  927. else if (param == "type") {
  928. return ("Tipologia");
  929. }
  930. else if (param == "note") {
  931. return ("Note");
  932. }
  933. else if (param == "ref") {
  934. return ("Riferimenti");
  935. }
  936. else if (param == "givenName") {
  937. return ("Nome proprio");
  938. }
  939. else if (param == "familyName") {
  940. return ("Cognome");
  941. }
  942. else if (param == "birthPlace") {
  943. return ("Luogo di Nascita");
  944. }
  945. else if (param == "deathPlace") {
  946. return ("Luogo di morte");
  947. }
  948. else if (param == "genere") {
  949. return ("Genere");
  950. }
  951. else if (param == "Birth_TS") {
  952. return ("Data di nascita");
  953. }
  954. else if (param == "Death_TS") {
  955. return ("Data di morte");
  956. }
  957. else if (param == "qualification") {
  958. return ("Qualifica");
  959. }
  960. else if (param == "occupation") {
  961. return ("Occupazione");
  962. }
  963. else if (param == "mittente") {
  964. return ("Mittente");
  965. }
  966. else if (param == "destinatario") {
  967. return ("Destinatario");
  968. }
  969. else if (param == "luogo_partenza") {
  970. return ("Luogo di partenza");
  971. }
  972. else if (param == "luogo_arrivo") {
  973. return ("Luogo di arrivo");
  974. }
  975. else if (param == "timeSpanSend") {
  976. return ("Data partenza");
  977. }
  978. else if (param == "timeSpanReceive") {
  979. return ("Data arrivo");
  980. }
  981. else if (param == "area_linguistica") {
  982. return ("Area linguistica");
  983. }
  984. else if (param == "edizione") {
  985. return ("Edizione");
  986. }
  987. else if (param == "lemma") {
  988. return ("Lemma");
  989. }
  990. else if (param == "testo") {
  991. return ("Testo");
  992. }
  993. else if (param == "date") {
  994. return ("Data");
  995. }
  996. else if (param == "start") {
  997. return ("Estremo temporale inferiore");
  998. }
  999. else if (param == "end") {
  1000. return ("Estremo temporale superiore");
  1001. }
  1002. else {
  1003. return (param);
  1004. }
  1005. }
  1006. function download_table_as_csv(separator = ',') {
  1007. // Select rows from table_id
  1008. var rows = document.querySelectorAll('#query_results .row');
  1009. // Construct csv
  1010. var csv = [];
  1011. for (var i = 0; i < rows.length; i++) {
  1012. var row = [], cols = rows[i].querySelectorAll('.col-auto');
  1013. for (var j = 0; j < cols.length; j++) {
  1014. // Clean innertext to remove multiple spaces and jumpline (break csv)
  1015. var data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ')
  1016. // Escape double-quote with double-double-quote (see https://stackoverflow.com/questions/17808511/properly-escape-a-double-quote-in-csv)
  1017. data = data.replace(/"/g, '""');
  1018. // Push escaped string
  1019. row.push('"' + data + '"');
  1020. }
  1021. csv.push(row.join(separator));
  1022. }
  1023. var csv_string = csv.join('\n');
  1024. // Download it
  1025. var filename = 'export_queryResults_' + new Date().toLocaleDateString() + '.csv';
  1026. var link = document.createElement('a');
  1027. link.style.display = 'none';
  1028. link.setAttribute('target', '_blank');
  1029. link.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv_string));
  1030. link.setAttribute('download', filename);
  1031. document.body.appendChild(link);
  1032. link.click();
  1033. document.body.removeChild(link);
  1034. }