advanced_search.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. const choiceArray = [
  2. ["Nome risorsa", "Object, OA, Person, Letter, Place", "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. ["Antroponimo", "Letter", "antroponym"],
  30. ["Toponimo", "Letter", "toponym"],
  31. ["Data", "Object, OA", "date"]
  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 Ospedale", "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. /*$('#inputchoiceSelector_' + numberId).val(inputText);
  139. $('#inputchoiceSelector_' + numberId).id(inputText);*/
  140. });
  141. }
  142. var val = 0;
  143. function addToList() {
  144. val = val+1;
  145. 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"> \
  146. <option selected value="0">Scegli un\'opzione</option> \
  147. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  148. </select></div></div>';
  149. $('#drop-down-content').append(sel);
  150. var selector = 'choice_selector-' + val;
  151. populateOptions(selector, choiceArray);
  152. }
  153. function addToListObject() {
  154. val = val+100;
  155. 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"> \
  156. <option selected value="0">Scegli un\'opzione</option> \
  157. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  158. </select></div></div>';
  159. $('#drop-down-content-Object').append(sel);
  160. var selector = 'choice_selector-' + val;
  161. populateOptions(selector, objectArray);
  162. }
  163. function addToListOA() {
  164. val = val+200;
  165. 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"> \
  166. <option selected value="0">Scegli un\'opzione</option> \
  167. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  168. </select></div></div>';
  169. $('#drop-down-content-OA').append(sel);
  170. var selector = 'choice_selector-' + val;
  171. populateOptions(selector, oaArray);
  172. }
  173. function addToListPerson() {
  174. val = val+300;
  175. 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"> \
  176. <option selected value="0">Scegli un\'opzione</option> \
  177. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  178. </select></div></div>';
  179. $('#drop-down-content-Person').append(sel);
  180. var selector = 'choice_selector-' + val;
  181. populateOptions(selector, personArray);
  182. }
  183. function addToListLetter() {
  184. val = val+400;
  185. 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"> \
  186. <option selected value="0">Scegli un\'opzione</option> \
  187. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  188. </select></div></div>';
  189. $('#drop-down-content-Letter').append(sel);
  190. var selector = 'choice_selector-' + val;
  191. populateOptions(selector, letterArray);
  192. }
  193. function addToListPlace() {
  194. val = val+500;
  195. 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"> \
  196. <option selected value="0">Scegli un\'opzione</option> \
  197. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  198. </select></div></div>';
  199. $('#drop-down-content-Place').append(sel);
  200. var selector = 'choice_selector-' + val;
  201. populateOptions(selector, placeArray);
  202. }
  203. //Get parameters from select and input options to build the query
  204. function getParameters() {
  205. var cc = document.getElementById("type_selector").value;
  206. if (cc != "General") {
  207. const arr = [];
  208. const collection = document.getElementsByClassName("advanced-form-select");
  209. for (let i = 0; i < collection.length; i++) {
  210. var x = collection[i].id;
  211. var t = document.getElementById(x);
  212. var e = t.options[t.selectedIndex].text;
  213. var numberId= x.split("-")[1]
  214. var inputId = "inputchoiceSelector_" + numberId;
  215. var inputText = document.getElementById(inputId).value;
  216. var el = [e, inputText];
  217. arr.push(el);
  218. }
  219. constructQuery(arr);
  220. }
  221. else {
  222. alert("Seleziona una categoria")
  223. }
  224. /*$('#query_results').append(arr);
  225. testo = $('input#writeText').val();*/
  226. }
  227. function removeElement(id_element) {
  228. const element = document.getElementById(id_element);
  229. element.remove();
  230. }
  231. //Build query with harvested parametes
  232. function constructQuery(params) {
  233. var g = document.getElementById("collection_selector");
  234. var graph = g.value;
  235. var search_graph = "?g";
  236. if (graph != "") {
  237. search_graph = '<' + graph + '>';
  238. }
  239. var search_type = "";
  240. var ct = document.getElementById("type_selector");
  241. var choosen_type = ct.value;
  242. console.log(choosen_type);
  243. var search_identifier = "";
  244. if (choosen_type == "Object") {
  245. search_type = "?subject rdf:type crm:E22_Man-Made_Object . ";
  246. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  247. ?uri_identifier rdfs:label ?identifier ; \
  248. crm:P2_has_type 'Segnatura' .";
  249. }
  250. if (choosen_type == "Letter") {
  251. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  252. ?uri_identifier rdfs:label ?identifier ; \
  253. crm:P2_has_type 'Segnatura' .";
  254. }
  255. if (choosen_type == "OA") {
  256. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  257. ?uri_identifier rdfs:label ?identifier ; \
  258. crm:P2_has_type 'Codice univoco del bene (NCT)' .";
  259. }
  260. if (choosen_type == "Person") {
  261. search_type = "?subject rdf:type crm:E21_Person . ";
  262. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  263. ?uri_identifier rdfs:label ?identifier .";
  264. }
  265. var label = ""; //
  266. var identificatore = ""; //
  267. var dimensione = ""; //
  268. var materia = ""; //
  269. var localizzazione = ""; //
  270. var tecnica = ""; //
  271. var artista = ""; //
  272. var soggetto = ""; //
  273. var titolo = ""; //
  274. var tipo = ""; //
  275. var note = ""; //
  276. var riferimenti = ""; //
  277. var nome_proprio = ""; //
  278. var nome_di_famiglia = ""; //
  279. var patronimico = ""; //
  280. var luogo_di_Nascita = ""; //
  281. var luogo_di_Morte = ""; //
  282. var genere = ""; //
  283. var data_di_Nascita = ""; //
  284. var data_di_Morte = ""; //
  285. var occupazione = ""; //
  286. var qualifica = ""; //
  287. var gruppi_di_appartenenza = ""; //
  288. var mittente = ""; //
  289. var destinatario = ""; //
  290. var luogo_di_Partenza = ""; //
  291. var luogo_di_Arrivo = ""; //
  292. var data_partenza = ""; //
  293. var data_arrivo = ""; //
  294. var lingua = ""; //
  295. var area_linguistica = ""; //
  296. var edizione = ""; //
  297. var antroponimo = ""; //
  298. var toponimo = ""; //
  299. var data = ""; //
  300. var letter_event = ""; //
  301. var infObj = ""; //
  302. var id = ""; //
  303. var dm = ""; //
  304. var mt = ""; //
  305. var locl = ""; //
  306. var tec = ""; //
  307. var at = ""; //
  308. var sg = ""; //
  309. var tt = ""; //
  310. var tp = ""; //
  311. var nt = ""; //
  312. var rf = ""; //
  313. var np = ""; //
  314. var nf = ""; //
  315. var pt = ""; //
  316. var ln = ""; //
  317. var lm = ""; //
  318. var gr = ""; //
  319. var dn = ""; //
  320. var dts = ""; //
  321. var oc = ""; //
  322. var qf = ""; //
  323. var ga = ""; //
  324. var mit = ""; //
  325. var des = ""; //
  326. var lp = ""; //
  327. var la = ""; //
  328. var dp = ""; //
  329. var da = ""; //
  330. var lin = ""; //
  331. var alin = ""; //
  332. var ed = ""; //
  333. var antr = ""; //
  334. var topo = ""; //
  335. var dt = ""; //
  336. for (let i = 0; i < params.length; i++) {
  337. if(params[i][0] == "Nome risorsa" && (params[i][1] != "")) {
  338. label = "?label bif:contains \"\' "+ params[i][1] + " \'\" . ";
  339. }
  340. if(params[i][0] == "Identificatore" && (params[i][1] != "")) {
  341. id = " ?identifier";
  342. identificatore = "FILTER (CONTAINS(?identifier, \'"+ params[i][1] +"\'))";
  343. }
  344. if(params[i][0] == "Dimensione" && (params[i][1] != "")) {
  345. dm = " ?dimension";
  346. dimensione = "?subject crm:P43_has_dimension ?uri_dimension . \
  347. ?uri_dimension rdfs:label ?dimension . \
  348. ?dimension bif:contains \"\'"+ params[i][1] +"\'\" ."
  349. }
  350. if(params[i][0] == "Materia" && (params[i][1] != "")) {
  351. mt = " ?material";
  352. materia = "?subject crm:P45_consists_of ?uri_material . \
  353. ?uri_material rdfs:label ?material . \
  354. ?material bif:contains \"\'"+ params[i][1] +"\'\" ."
  355. }
  356. if(params[i][0] == "Istituto di conservazione" && (params[i][1] != "")) {
  357. locl = " ?location";
  358. localizzazione = "?subject crm:P52_has_current_owner ?uri_location . \
  359. ?uri_location rdfs:label ?location . \
  360. ?location bif:contains \"\'"+ params[i][1] +"\'\" ."
  361. }
  362. if(params[i][0] == "Tecnica" && (params[i][1] != "")) {
  363. tec = " ?technique";
  364. tecnica = "?subject ?property ?event . \
  365. ?event crm:P32_used_general_technique ?uri_technique . \
  366. ?uri_technique rdfs:label ?technique . \
  367. ?technique bif:contains \"\'"+ params[i][1] +"\'\" . "
  368. }
  369. if (params[i][0] == "Artista" && (params[i][1] != "")) {
  370. at = " ?artist";
  371. artista = "?subject rdfs:label ?label . \
  372. ?production crm:P108_has_produced ?subject . \
  373. ?pc crm:P01_has_domain ?production . \
  374. ?pc crm:P02_has_range ?range . \
  375. ?range rdfs:label ?artist . \
  376. ?artist bif:contains \"\'"+ params[i][1] +"\'\" ."
  377. }
  378. if (params[i][0] == "Soggetto" && (params[i][1] != "")) {
  379. sg = " ?depiction";
  380. soggetto = "?subject crm:P62_depicts ?uri_depiction . \
  381. ?uri_depiction rdfs:label ?depiction . \
  382. ?depiction bif:contains \"\'"+ params[i][1] +"\'\" ."
  383. }
  384. if (params[i][0] == "Titolo" && (params[i][1] != "")) {
  385. tt = " ?title";
  386. infObj = "?subject crm:P128_carries ?information_object .";
  387. titolo = "?information_object crm:P1_is_identified_by ?uri_title . \
  388. ?uri_title rdfs:label ?title . \
  389. ?title bif:contains \"\'"+ params[i][1] +"\'\" ."
  390. }
  391. if (params[i][0] == "Tipo di risorsa" && (params[i][1] != "")) {
  392. tp = " ?type";
  393. infObj = "?subject crm:P128_carries ?information_object .";
  394. tipo = "?information_object crm:P2_has_type ?uri_type . \
  395. ?uri_type rdfs:label ?type . \
  396. ?type bif:contains \"\'"+ params[i][1] +"\'\" ."
  397. }
  398. if (params[i][0] == "Note" && (params[i][1] != "")) {
  399. nt = " ?note";
  400. note = "?subject crm:P3_has_note ?uri_note . \
  401. ?uri_note rdfs:label ?note . \
  402. ?note bif:contains \"\'"+ params[i][1] +"\'\" .";
  403. }
  404. if (params[i][0] == "Riferimenti" && (params[i][1] != "")) {
  405. rf = " ?ref";
  406. riferimenti = "?subject crm:P67_refers_to ?uri_ref . \
  407. ?uri_ref rdfs:label ?ref . \
  408. ?ref bif:contains \"\'"+ params[i][1] +"\'\" . "
  409. }
  410. if (params[i][0] == "Nome proprio" && (params[i][1] != "")) {
  411. np = " ?givenName";
  412. nome_proprio = "?subject foaf:givenName ?givenName . \
  413. ?givenName bif:contains \"\'"+ params[i][1] +"\'\" . "
  414. }
  415. if (params[i][0] == "Nome di famiglia" && (params[i][1] != "")) {
  416. nf = " ?familyName";
  417. nome_di_famiglia = "?subject foaf:familyName ?familyName . \
  418. ?familyName bif:contains \"\'"+ params[i][1] +"\'\" . "
  419. }
  420. if (params[i][0] == "Patronimico" && (params[i][1] != "")) {
  421. pt = " ?patronymic";
  422. patronimico = "?subject person:patronymicName ?patronymic . \
  423. ?patronymic bif:contains \"\'"+ params[i][1] +"\'\" . "
  424. }
  425. if (params[i][0] == "Luogo di Nascita" && (params[i][1] != "")) {
  426. ln = " ?birthPlace";
  427. luogo_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  428. ?Birth crm:P7_took_place_at ?uri_birthPlace . \
  429. ?uri_birthPlace rdfs:label ?birthPlace . \
  430. ?birthPlace bif:contains \""+ params[i][1] +"\" . "
  431. }
  432. if (params[i][0] == "Luogo di Morte" && (params[i][1] != "")) {
  433. lm = " ?deathPlace";
  434. luogo_di_Morte = "?subject crm:P100i_died_in ?Death . \
  435. ?Death crm:P7_took_place_at ?uri_deathPlace . \
  436. ?uri_deathPlace rdfs:label ?deathPlace \
  437. ?deathPlace bif:contains \""+ params[i][1] +"\" . "
  438. }
  439. if (params[i][0] == "Genere" && (params[i][1] != "")) {
  440. gr = "?genere";
  441. genere = "?subject foaf:gender ?genere . \
  442. ?genere bif:contains \""+ params[i][1] +"\" . "
  443. }
  444. if (params[i][0] == "Data di Nascita" && (params[i][1] != "")) {
  445. dn = " ?Birth_TS";
  446. data_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  447. ?Birth crm:P4_has_time-span ?Birth_TS . \
  448. ?Birth_TS rdfs:label \""+ params[i][1] +"\" ."
  449. }
  450. if (params[i][0] == "Data di Morte" && (params[i][1] != "")) {
  451. dts = " ?Death_TS";
  452. data_di_Morte = "?subject crm:P100i_died_in ?Death . \
  453. ?Death crm:P4_has_time-span ?Death_TS . \
  454. ?Death_TS rdfs:label \""+ params[i][1] +"\" . "
  455. }
  456. if (params[i][0] == "Qualifica" && (params[i][1] != "")) {
  457. qf = " ?qualification";
  458. qualifica = "?subject schema:honorificPrefix ?qualification . \
  459. ?qualification bif:contains \"\'"+ params[i][1] +"\'\" . "
  460. }
  461. if (params[i][0] == "Occupazione" && (params[i][1] != "")) {
  462. oc = " ?occupation";
  463. occupazione = "?subject schema:hasOccupation ?uriOccupation . \
  464. ?uriOccupation rdf:type schema:Occupation; \
  465. rdfs:label ?occupation . \
  466. ?occupation bif:contains \"\'"+ params[i][1] +"\'\" . "
  467. }
  468. if (params[i][0] == "Gruppi di appartenenza" && (params[i][1] != "")) {
  469. ga = " ?group";
  470. gruppi_di_appartenenza = "?subject crm:P107i_is_current_or_former_member_of ?uriGroup . \
  471. ?uriGroup rdfs:label ?group . \
  472. ?group bif:contains \"\'"+ params[i][1] +"\'\" . "
  473. }
  474. if (params[i][0] == "Mittente" && (params[i][1] != "")) {
  475. mit = " ?mittente";
  476. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  477. ?send rdfs:subClassOf ?mov_ev ; \
  478. rdf:type crm:EL2_Send_Letter . \
  479. ?receive rdfs:subClassOf ?mov_ev; \
  480. rdf:type crm:EL3_Receive_Letter . ";
  481. mittente = "?send crm:P01_has_domain ?pcS . \
  482. ?pcS crm:P02_has_range ?uriSender . \
  483. ?uriSender rdfs:label ?mittente . \
  484. ?mittente bif:contains \"\'"+ params[i][1] +"\'\" . "
  485. }
  486. if (params[i][0] == "Destinatario" && (params[i][1] != "")) {
  487. des = " ?destinatario";
  488. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  489. ?send rdfs:subClassOf ?mov_ev ; \
  490. rdf:type crm:EL2_Send_Letter . \
  491. ?receive rdfs:subClassOf ?mov_ev; \
  492. rdf:type crm:EL3_Receive_Letter . ";
  493. destinatario = "?receive crm:P01_has_domain ?pcR . \
  494. ?pcR crm:P02_has_range ?uriReceiver . \
  495. ?uriReceiver rdfs:label ?destinatario . \
  496. ?destinatario bif:contains \"\'"+ params[i][1] +"\'\" . "
  497. }
  498. if (params[i][0] == "Luogo di Partenza" && (params[i][1] != "")) {
  499. lp = " ?luogo_partenza";
  500. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  501. ?send rdfs:subClassOf ?mov_ev ; \
  502. rdf:type crm:EL2_Send_Letter . \
  503. ?receive rdfs:subClassOf ?mov_ev; \
  504. rdf:type crm:EL3_Receive_Letter . ";
  505. luogo_di_Partenza = "?send crm:P27_moved_from ?uriLuogoPartenza . \
  506. ?uriLuogoPartenza rdfs:label ?luogo_partenza . \
  507. ?luogo_partenza bif:contains \"\'"+ params[i][1] +"\'\" . "
  508. }
  509. if (params[i][0] == "Luogo di Arrivo" && (params[i][1] != "")) {
  510. la = " ?luogo_arrivo";
  511. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  512. ?send rdfs:subClassOf ?mov_ev ; \
  513. rdf:type crm:EL2_Send_Letter . \
  514. ?receive rdfs:subClassOf ?mov_ev; \
  515. rdf:type crm:EL3_Receive_Letter . ";
  516. luogo_di_Arrivo = "?receive crm:P26_moved_to ?uriLuogoArrivo . \
  517. ?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
  518. ?luogo_arrivo bif:contains \"\'"+ params[i][1] +"\'\" . "
  519. }
  520. if (params[i][0] == "Data partenza" && (params[i][1] != "")) {
  521. dp = " ?timeSpanSend";
  522. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  523. ?send rdfs:subClassOf ?mov_ev ; \
  524. rdf:type crm:EL2_Send_Letter . \
  525. ?receive rdfs:subClassOf ?mov_ev; \
  526. rdf:type crm:EL3_Receive_Letter . ";
  527. data_partenza = "?send crm:P4_has_time-span ?time_spanS . \
  528. ?time_spanS rdfs:label ?timeSpanSend . \
  529. ?timeSpanSend bif:contains \"\'"+ params[i][1] +"\'\" . "
  530. }
  531. if (params[i][0] == "Data arrivo" && (params[i][1] != "")) {
  532. da = " ?timeSpanReceive";
  533. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  534. ?send rdfs:subClassOf ?mov_ev ; \
  535. rdf:type crm:EL2_Send_Letter . \
  536. ?receive rdfs:subClassOf ?mov_ev; \
  537. rdf:type crm:EL3_Receive_Letter . ";
  538. data_arrivo = "?receive crm:P4_has_time-span ?time_spanR . \
  539. ?time_spanR rdfs:label ?timeSpanReceive .\
  540. ?timeSpanReceive bif:contains \"\'"+ params[i][1] +"\'\" . "
  541. }
  542. if (params[i][0] == "Lingua" && (params[i][1] != "")) {
  543. lin = " ?lingua";
  544. infObj = "?subject crm:P128_carries ?information_object .";
  545. lingua = "?information_object crm:P72_has_language ?language . \
  546. ?language rdfs:label ?lingua . \
  547. ?lingua bif:contains \"\'"+ params[i][1] +"\'\" ."
  548. }
  549. if (params[i][0] == "Area linguistica" && (params[i][1] != "")) {
  550. alin = " ?area_linguistica";
  551. infObj = "?subject crm:P128_carries ?information_object .";
  552. area_linguistica = "?information_object crm:P72_has_language ?language . \
  553. ?language crm:P3_has_note ?area . \
  554. ?area rdfs:label ?area_linguistica .\
  555. ?area_linguistica bif:contains \"\'"+ params[i][1] +"\'\" ."
  556. }
  557. if (params[i][0] == "Edizione" && (params[i][1] != "")) {
  558. ed = " ?edizione";
  559. infObj = "?subject crm:P128_carries ?information_object .";
  560. edizione = "?edition crm:P70_documents ?information_object ; \
  561. crm:P1_is_identified_by ?edition_id . \
  562. ?edition_id rdfs:label ?edizione . \
  563. ?edizione bif:contains \"\'"+ params[i][1] +"\'\" ."
  564. }
  565. if (params[i][0] == "Toponimo" && (params[i][1] != "")) {
  566. topo = " ?toponimo";
  567. infObj = "?subject crm:P128_carries ?information_object .";
  568. toponimo = "?information_object crm:P67_refers_to ?link_toponimo . \
  569. ?link_toponimo rdfs:label ?toponimo ; \
  570. crm:P2_has_type 'Toponimo' . \
  571. ?toponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
  572. }
  573. if (params[i][0] == "Antroponimo" && (params[i][1] != "")) {
  574. antr = " ?antroponimo";
  575. infObj = "?subject crm:P128_carries ?information_object .";
  576. antroponimo = "?information_object crm:P67_refers_to ?link_antroponimo . \
  577. ?link_antroponimo rdfs:label ?antroponimo; \
  578. crm:P2_has_type 'Antroponimo' . \
  579. ?antroponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
  580. }
  581. if (params[i][0] == "Data" && (params[i][1] != "")) {
  582. dt = " ?date";
  583. data = "?subject ?property ?event . \
  584. ?event crm:P4_has_time-span ?uri_date . \
  585. ?uri_date rdfs:label ?date . \
  586. ?date bif:contains \"\'"+ params[i][1] +"\'\" ."
  587. }
  588. }
  589. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  590. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  591. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  592. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  593. PREFIX schema: <http://schema.org/> \
  594. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  595. PREFIX person: <http://www.w3.org/ns/person#>"
  596. query = prefixes + " SELECT DISTINCT ?subject ?label ?identifier " + dm + mt + locl + tec + at
  597. + sg + tt + tp + nt + rf + np + nf + pt + ln + lm + gr + dn + dts + oc + qf + ga + mit
  598. + des + lp + la + dp + da + lin + alin + ed + antr + topo + dt + " \
  599. WHERE {GRAPH " + search_graph + " {?subject ?property ?object } \
  600. ?subject rdfs:label ?label . "
  601. + search_identifier + infObj + letter_event + label + search_type + dimensione + materia + localizzazione + tecnica
  602. + artista + titolo + tipo + note + riferimenti + nome_proprio + nome_di_famiglia
  603. + patronimico + luogo_di_Nascita + luogo_di_Morte + genere + data_di_Nascita
  604. + data_di_Morte + qualifica + occupazione + gruppi_di_appartenenza + mittente + destinatario
  605. +luogo_di_Partenza + luogo_di_Arrivo + data_partenza + data_arrivo + lingua
  606. + area_linguistica + edizione + toponimo + antroponimo + data + identificatore + "}"
  607. var query_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
  608. console.log(query);
  609. $.ajax({
  610. url: query_url + '&callback=?',
  611. dataType: "json",
  612. success: function (data) {
  613. query_handle_json(data, choosen_type);
  614. },
  615. error: function (e) {}
  616. });
  617. }
  618. function query_handle_json(json, choosen_type) {
  619. console.log(json);
  620. var resulType = "";
  621. if (choosen_type == "Object") {
  622. resulType = "object";
  623. }
  624. if (choosen_type == "Letter") {
  625. resulType = "object";
  626. }
  627. if (choosen_type == "OA") {
  628. resulType = "artwork";
  629. }
  630. if (choosen_type == "Person") {
  631. resulType = "persona";
  632. }
  633. $('#query_results').text("");
  634. var i = 0;
  635. const first_row = [];
  636. $.each(
  637. json['head']['vars'],
  638. function (index, value) {
  639. first_row.push(value);
  640. });
  641. var t_head = '<div class="row t_head">';
  642. for (let k = 1; k < first_row.length; k++) {
  643. var param = renameCol(first_row[k]);
  644. t_head += '<div class="col-auto">' + param + '</div>';
  645. }
  646. t_head += '</div>';
  647. $('#query_results').append(t_head);
  648. $.each(
  649. json['results']['bindings'],
  650. function (index, value) {
  651. var object = "";
  652. var link = value['subject']['value'];
  653. var label = value['label']['value'];
  654. object += '<div class="row"><div id="' + link + '" class="col-auto link ' + resulType + '">' + label + '</div>';
  655. if (value.hasOwnProperty('identifier')) {
  656. identifier = value['identifier']['value'];
  657. object += '<div class="col-auto">' + identifier + '</div>';
  658. }
  659. if (value.hasOwnProperty('dimension')) {
  660. dimension = value['dimension']['value'];
  661. object += '<div class="col-auto">' + dimension + '</div>';
  662. }
  663. if (value.hasOwnProperty('material')) {
  664. material = value['material']['value'];
  665. object += '<div class="col-auto">' + material + '</div>';
  666. }
  667. if (value.hasOwnProperty('location')) {
  668. localization = value['location']['value'];
  669. object += '<div class="col-auto">' + localization + '</div>';
  670. }
  671. if (value.hasOwnProperty('technique')) {
  672. technique = value['technique']['value'];
  673. object += '<div class="col-auto">' + technique + '</div>';
  674. }
  675. if (value.hasOwnProperty('artist')) {
  676. artist = value['artist']['value'];
  677. object += '<div class="col-auto">' + artist + '</div>';
  678. }
  679. if (value.hasOwnProperty('depiction')) {
  680. depiction = value['depiction']['value'];
  681. object += '<div class="col-auto">' + depiction + '</div>';
  682. }
  683. if (value.hasOwnProperty('title')) {
  684. title = value['title']['value'];
  685. object += '<div class="col-auto">' + title + '</div>';
  686. }
  687. if (value.hasOwnProperty('type')) {
  688. type = value['type']['value'];
  689. object += '<div class="col-auto">' + type + '</div>';
  690. }
  691. if (value.hasOwnProperty('note')) {
  692. note = value['note']['value'];
  693. object += '<div class="col-auto">' + note + '</div>';
  694. }
  695. if (value.hasOwnProperty('ref')) {
  696. ref = value['ref']['value'];
  697. object += '<div class="col-auto">' + ref + '</div>';
  698. }
  699. if (value.hasOwnProperty('givenName')) {
  700. givenName = value['givenName']['value'];
  701. object += '<div class="col-auto">' + givenName + '</div>';
  702. }
  703. if (value.hasOwnProperty('familyName')) {
  704. familyName = value['familyName']['value'];
  705. object += '<div class="col-auto">' + familyName + '</div>';
  706. }
  707. if (value.hasOwnProperty('patronymic')) {
  708. patronymic = value['patronymic']['value'];
  709. object += '<div class="col-auto">' + patronymic + '</div>';
  710. }
  711. if (value.hasOwnProperty('birthPlace')) {
  712. birthPlace = value['birthPlace']['value'];
  713. object += '<div class="col-auto">' + birthPlace + '</div>';
  714. }
  715. if (value.hasOwnProperty('deathPlace')) {
  716. deathPlace = value['deathPlace']['value'];
  717. object += '<div class="col-auto">' + deathPlace + '</div>';
  718. }
  719. if (value.hasOwnProperty('genere')) {
  720. genere = value['genere']['value'];
  721. object += '<div class="col-auto">' + genere + '</div>';
  722. }
  723. if (value.hasOwnProperty('Birth_TS')) {
  724. Birth_TS = value['Birth_TS']['value'];
  725. object += '<div class="col-auto">' + Birth_TS + '</div>';
  726. }
  727. if (value.hasOwnProperty('Death_TS')) {
  728. Death_TS = value['Death_TS']['value'];
  729. object += '<div class="col-auto">' + Death_TS + '</div>';
  730. }
  731. if (value.hasOwnProperty('qualification')) {
  732. qualification = value['qualification']['value'];
  733. object += '<div class="col-auto">' + qualification + '</div>';
  734. }
  735. if (value.hasOwnProperty('occupation')) {
  736. occupation = value['occupation']['value'];
  737. object += '<div class="col-auto">' + occupation + '</div>';
  738. }
  739. if (value.hasOwnProperty('group')) {
  740. group = value['group']['value'];
  741. object += '<div class="col-auto">' + group + '</div>';
  742. }
  743. if (value.hasOwnProperty('mittente')) {
  744. mittente = value['mittente']['value'];
  745. object += '<div class="col-auto">' + mittente + '</div>';
  746. }
  747. if (value.hasOwnProperty('destinatario')) {
  748. destinatario = value['destinatario']['value'];
  749. object += '<div class="col-auto">' + destinatario + '</div>';
  750. }
  751. if (value.hasOwnProperty('luogo_partenza')) {
  752. luogo_partenza = value['luogo_partenza']['value'];
  753. object += '<div class="col-auto">' + luogo_partenza + '</div>';
  754. }
  755. if (value.hasOwnProperty('luogo_arrivo')) {
  756. luogo_arrivo = value['luogo_arrivo']['value'];
  757. object += '<div class="col-auto">' + luogo_arrivo + '</div>';
  758. }
  759. if (value.hasOwnProperty('timeSpanSend')) {
  760. timeSpanSend = value['timeSpanSend']['value'];
  761. object += '<div class="col-auto">' + timeSpanSend + '</div>';
  762. }
  763. if (value.hasOwnProperty('timeSpanReceive')) {
  764. timeSpanReceive = value['timeSpanReceive']['value'];
  765. object += '<div class="col-auto">' + timeSpanReceive + '</div>';
  766. }
  767. if (value.hasOwnProperty('lingua')) {
  768. lingua = value['lingua']['value'];
  769. object += '<div class="col-auto">' + lingua + '</div>';
  770. }
  771. if (value.hasOwnProperty('area_linguistica')) {
  772. area_linguistica = value['area_linguistica']['value'];
  773. object += '<div class="col-auto">' + area_linguistica + '</div>';
  774. }
  775. if (value.hasOwnProperty('edizione')) {
  776. edizione = value['edizione']['value'];
  777. object += '<div class="col-auto">' + edizione + '</div>';
  778. }
  779. if (value.hasOwnProperty('toponimo')) {
  780. toponimo = value['toponimo']['value'];
  781. object += '<div class="col-auto">' + toponimo + '</div>';
  782. }
  783. if (value.hasOwnProperty('antroponimo')) {
  784. antroponimo = value['antroponimo']['value'];
  785. object += '<div class="col-auto">' + antroponimo + '</div>';
  786. }
  787. if (value.hasOwnProperty('date')) {
  788. date = value['date']['value'];
  789. object += '<div class="col-auto">' + date + '</div>';
  790. }
  791. object += '</div>';
  792. i++;
  793. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  794. $('#query_results').append(object);
  795. });
  796. if (i==0) {
  797. var message = '<p>Nessun risultato trovato</p>';
  798. $('#query_results').append(message);
  799. }
  800. document.getElementById("n_res").innerHTML = i;
  801. }
  802. function populateSelGraph(graphType) {
  803. let y = graphArray.length;
  804. collection_selector.innerHTML = "";
  805. if (graphType != "General") {
  806. collection_selector.style.color = '#202122';
  807. collection_selector.style.cursor = 'pointer';
  808. collection_selector.style.backgroundColor = '#f8f9fa';
  809. collection_selector.style.backgroundImage = 'linear-gradient(to top, #fff, #fff 33%)';
  810. } else {
  811. collection_selector.style.color = '#a1a1a1';
  812. collection_selector.style.cursor = 'not-allowed';
  813. collection_selector.style.backgroundColor = '#eee';
  814. collection_selector.style.backgroundImage = 'linear-gradient(to top, #ddd, #eee 33%)';
  815. }
  816. var genOpt = document.createElement("option");
  817. genOpt.value= "";
  818. genOpt.innerHTML = "Tutte le Collezioni";
  819. collection_selector.add(genOpt);
  820. for(var i=0; i<y; i++) {
  821. if (graphType == graphArray[i][2]) {
  822. var opt = document.createElement("option");
  823. opt.value= graphArray[i][1];
  824. opt.innerHTML = graphArray[i][0]; // whatever property it has
  825. // then append it to the select element
  826. collection_selector.add(opt);
  827. }
  828. }
  829. }
  830. function renameCol(param) {
  831. if (param == "label") {
  832. return ("Denominazione");
  833. }
  834. else if (param == "identifier") {
  835. return ("Identificatore");
  836. }
  837. else if (param == "dimension") {
  838. return ("Dimensioni");
  839. }
  840. else if (param == "material") {
  841. return ("Materiale");
  842. }
  843. else if (param == "location") {
  844. return ("Istituto di conservazione");
  845. }
  846. else if (param == "technique") {
  847. return ("Tecnica");
  848. }
  849. else if (param == "artist") {
  850. return ("Artista");
  851. }
  852. else if (param == "depiction") {
  853. return ("Soggetto");
  854. }
  855. else if (param == "title") {
  856. return ("Titolo");
  857. }
  858. else if (param == "type") {
  859. return ("Tipologia");
  860. }
  861. else if (param == "note") {
  862. return ("Note");
  863. }
  864. else if (param == "ref") {
  865. return ("Riferimenti");
  866. }
  867. else if (param == "givenName") {
  868. return ("Nome proprio");
  869. }
  870. else if (param == "familyName") {
  871. return ("Cognome");
  872. }
  873. else if (param == "birthPlace") {
  874. return ("Luogo di Nascita");
  875. }
  876. else if (param == "deathPlace") {
  877. return ("Luogo di morte");
  878. }
  879. else if (param == "genere") {
  880. return ("Genere");
  881. }
  882. else if (param == "Birth_TS") {
  883. return ("Data di nascita");
  884. }
  885. else if (param == "Death_TS") {
  886. return ("Data di morte");
  887. }
  888. else if (param == "qualification") {
  889. return ("Qualifica");
  890. }
  891. else if (param == "occupation") {
  892. return ("Occupazione");
  893. }
  894. else if (param == "mittente") {
  895. return ("Mittente");
  896. }
  897. else if (param == "destinatario") {
  898. return ("Destinatario");
  899. }
  900. else if (param == "luogo_partenza") {
  901. return ("Luogo di partenza");
  902. }
  903. else if (param == "luogo_arrivo") {
  904. return ("Luogo di arrivo");
  905. }
  906. else if (param == "timeSpanSend") {
  907. return ("Data partenza");
  908. }
  909. else if (param == "timeSpanReceive") {
  910. return ("Data arrivo");
  911. }
  912. else if (param == "area_linguistica") {
  913. return ("Area linguistica");
  914. }
  915. else if (param == "edizione") {
  916. return ("Edizione");
  917. }
  918. else if (param == "lemma") {
  919. return ("Lemma");
  920. }
  921. else if (param == "date") {
  922. return ("Data");
  923. }
  924. else {
  925. return (param);
  926. }
  927. }
  928. function download_table_as_csv(separator = ',') {
  929. // Select rows from table_id
  930. var rows = document.querySelectorAll('#query_results .row');
  931. // Construct csv
  932. var csv = [];
  933. for (var i = 0; i < rows.length; i++) {
  934. var row = [], cols = rows[i].querySelectorAll('.col-auto');
  935. for (var j = 0; j < cols.length; j++) {
  936. // Clean innertext to remove multiple spaces and jumpline (break csv)
  937. var data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ')
  938. // Escape double-quote with double-double-quote (see https://stackoverflow.com/questions/17808511/properly-escape-a-double-quote-in-csv)
  939. data = data.replace(/"/g, '""');
  940. // Push escaped string
  941. row.push('"' + data + '"');
  942. }
  943. csv.push(row.join(separator));
  944. }
  945. var csv_string = csv.join('\n');
  946. // Download it
  947. var filename = 'export_queryResults_' + new Date().toLocaleDateString() + '.csv';
  948. var link = document.createElement('a');
  949. link.style.display = 'none';
  950. link.setAttribute('target', '_blank');
  951. link.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv_string));
  952. link.setAttribute('download', filename);
  953. document.body.appendChild(link);
  954. link.click();
  955. document.body.removeChild(link);
  956. }