advanced_search.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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. ["Luogo", "Place"]
  39. ];
  40. const graphArray = [
  41. ["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini"],
  42. ["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale"],
  43. ["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi"],
  44. ["ASPO - Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli"],
  45. ["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini"],
  46. ["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale"],
  47. ["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini"],
  48. ["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini"]
  49. ];
  50. const objectArray = [];
  51. const personArray = [];
  52. const placeArray = [];
  53. const oaArray = [];
  54. const letterArray = [];
  55. $(document).ready(function () {
  56. //#######################################
  57. var type_selector = document.getElementById("type_selector");
  58. var collection_selector = document.getElementById("collection_selector");
  59. let x = typeArray.length;
  60. for(var i=0; i<x; i++) {
  61. var opt = document.createElement("option");
  62. opt.value= typeArray[i][1];
  63. opt.innerHTML = typeArray[i][0]; // whatever property it has
  64. // then append it to the select element
  65. type_selector.add(opt);
  66. }
  67. let y = graphArray.length;
  68. for(var i=0; i<y; i++) {
  69. var opt = document.createElement("option");
  70. opt.value= graphArray[i][1];
  71. opt.innerHTML = graphArray[i][0]; // whatever property it has
  72. // then append it to the select element
  73. collection_selector.add(opt);
  74. }
  75. let z = choiceArray.length;
  76. for(var i=0; i<z; i++) {
  77. var cat = choiceArray[i][1];
  78. if (cat.includes("Object")) {
  79. objectArray.push(choiceArray[i]);
  80. }
  81. if (cat.includes("OA")) {
  82. oaArray.push(choiceArray[i]);
  83. }
  84. if (cat.includes("Person")) {
  85. personArray.push(choiceArray[i]);
  86. }
  87. if (cat.includes("Letter")) {
  88. letterArray.push(choiceArray[i]);
  89. }
  90. if (cat.includes("Place")) {
  91. placeArray.push(choiceArray[i]);
  92. }
  93. }
  94. $("#type_selector").change(function(){
  95. var selOpt = "";
  96. $(this).find("option:selected").each(function(){
  97. var optionValue = $(this).attr("value");
  98. selOpt = optionValue;
  99. if(optionValue){
  100. $(".box").not("." + optionValue).hide();
  101. $("." + optionValue).show();
  102. } else{
  103. $(".box").hide();
  104. }
  105. });
  106. $( ".container_choice" ).remove();
  107. if (selOpt == "Object") {
  108. addToListObject();
  109. }
  110. if (selOpt == "OA") {
  111. addToListOA();
  112. }
  113. if (selOpt == "Person") {
  114. addToListPerson();
  115. }
  116. if (selOpt == "Letter") {
  117. addToListLetter();
  118. }
  119. }).change();
  120. /*$('[name=sel-parent]').on('change', function() {
  121. $(this).attr("id", 'example' + $(this).name());
  122. });*/
  123. addToList();
  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. const arr = [];
  206. const collection = document.getElementsByClassName("advanced-form-select");
  207. for (let i = 0; i < collection.length; i++) {
  208. var x = collection[i].id;
  209. var t = document.getElementById(x);
  210. var e = t.options[t.selectedIndex].text;
  211. var numberId= x.split("-")[1]
  212. var inputId = "inputchoiceSelector_" + numberId;
  213. var inputText = document.getElementById(inputId).value;
  214. var el = [e, inputText];
  215. arr.push(el);
  216. }
  217. constructQuery(arr);
  218. /*$('#query_results').append(arr);
  219. testo = $('input#writeText').val();*/
  220. }
  221. function removeElement(id_element) {
  222. const element = document.getElementById(id_element);
  223. element.remove();
  224. }
  225. //Build query with harvested parametes
  226. function constructQuery(params) {
  227. var g = document.getElementById("collection_selector");
  228. var graph = g.value;
  229. var search_graph = "?g";
  230. if (graph != "") {
  231. search_graph = '<' + graph + '>';
  232. }
  233. var search_type = "";
  234. var ct = document.getElementById("type_selector");
  235. var choosen_type = ct.value;
  236. console.log(choosen_type);
  237. var search_identifier = "";
  238. if (choosen_type == "Object") {
  239. search_type = "?subject rdf:type crm:E22_Man-Made_Object . ";
  240. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  241. ?uri_identifier rdfs:label ?identifier ; \
  242. crm:P2_has_type 'Segnatura' .";
  243. }
  244. if (choosen_type == "Letter") {
  245. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  246. ?uri_identifier rdfs:label ?identifier ; \
  247. crm:P2_has_type 'Segnatura' .";
  248. }
  249. if (choosen_type == "OA") {
  250. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  251. ?uri_identifier rdfs:label ?identifier ; \
  252. crm:P2_has_type 'Codice univoco del bene (NCT)' .";
  253. }
  254. if (choosen_type == "Person") {
  255. search_type = "?subject rdf:type crm:E21_Person . ";
  256. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  257. ?uri_identifier rdfs:label ?identifier .";
  258. }
  259. var label = ""; //
  260. var identificatore = ""; //
  261. var dimensione = ""; //
  262. var materia = ""; //
  263. var localizzazione = ""; //
  264. var tecnica = ""; //
  265. var artista = ""; //
  266. var soggetto = ""; //
  267. var titolo = ""; //
  268. var tipo = ""; //
  269. var note = ""; //
  270. var riferimenti = ""; //
  271. var nome_proprio = ""; //
  272. var nome_di_famiglia = ""; //
  273. var patronimico = ""; //
  274. var luogo_di_Nascita = ""; //
  275. var luogo_di_Morte = ""; //
  276. var genere = ""; //
  277. var data_di_Nascita = ""; //
  278. var data_di_Morte = ""; //
  279. var occupazione = ""; //
  280. var qualifica = ""; //
  281. var gruppi_di_appartenenza = ""; //
  282. var mittente = ""; //
  283. var destinatario = ""; //
  284. var luogo_di_Partenza = ""; //
  285. var luogo_di_Arrivo = ""; //
  286. var data_partenza = ""; //
  287. var data_arrivo = ""; //
  288. var lingua = ""; //
  289. var area_linguistica = ""; //
  290. var edizione = ""; //
  291. var antroponimo = ""; //
  292. var toponimo = ""; //
  293. var data = ""; //
  294. var letter_event = ""; //
  295. var infObj = ""; //
  296. var id = ""; //
  297. var dm = ""; //
  298. var mt = ""; //
  299. var locl = ""; //
  300. var tec = ""; //
  301. var at = ""; //
  302. var sg = ""; //
  303. var tt = ""; //
  304. var tp = ""; //
  305. var nt = ""; //
  306. var rf = ""; //
  307. var np = ""; //
  308. var nf = ""; //
  309. var pt = ""; //
  310. var ln = ""; //
  311. var lm = ""; //
  312. var gr = ""; //
  313. var dn = ""; //
  314. var dts = ""; //
  315. var oc = ""; //
  316. var qf = ""; //
  317. var ga = ""; //
  318. var mit = ""; //
  319. var des = ""; //
  320. var lp = ""; //
  321. var la = ""; //
  322. var dp = ""; //
  323. var da = ""; //
  324. var lin = ""; //
  325. var alin = ""; //
  326. var ed = ""; //
  327. var antr = ""; //
  328. var topo = ""; //
  329. var dt = ""; //
  330. for (let i = 0; i < params.length; i++) {
  331. if(params[i][0] == "Nome risorsa" && (params[i][1] != "")) {
  332. label = "?label bif:contains \"\' "+ params[i][1] + " \'\" . ";
  333. }
  334. if(params[i][0] == "Identificatore" && (params[i][1] != "")) {
  335. id = " ?identifier";
  336. identificatore = "FILTER (CONTAINS(?identifier, \'"+ params[i][1] +"\'))";
  337. }
  338. if(params[i][0] == "Dimensione" && (params[i][1] != "")) {
  339. dm = " ?dimension";
  340. dimensione = "?subject crm:P43_has_dimension ?uri_dimension . \
  341. ?uri_dimension rdfs:label ?dimension . \
  342. ?dimension bif:contains \"\'"+ params[i][1] +"\'\" ."
  343. }
  344. if(params[i][0] == "Materia" && (params[i][1] != "")) {
  345. mt = " ?material";
  346. materia = "?subject crm:P45_consists_of ?uri_material . \
  347. ?uri_material rdfs:label ?material . \
  348. ?material bif:contains \"\'"+ params[i][1] +"\'\" ."
  349. }
  350. if(params[i][0] == "Istituto di conservazione" && (params[i][1] != "")) {
  351. locl = " ?location";
  352. localizzazione = "?subject crm:P52_has_current_owner ?uri_location . \
  353. ?uri_location rdfs:label ?location . \
  354. ?location bif:contains \"\'"+ params[i][1] +"\'\" ."
  355. }
  356. if(params[i][0] == "Tecnica" && (params[i][1] != "")) {
  357. tec = " ?technique";
  358. tecnica = "?subject ?property ?event . \
  359. ?event crm:P32_used_general_technique ?uri_technique . \
  360. ?uri_technique rdfs:label ?technique . \
  361. ?technique bif:contains \"\'"+ params[i][1] +"\'\" . "
  362. }
  363. if (params[i][0] == "Artista" && (params[i][1] != "")) {
  364. at = " ?artist";
  365. artista = "?subject rdfs:label ?label . \
  366. ?production crm:P108_has_produced ?subject . \
  367. ?pc crm:P01_has_domain ?production . \
  368. ?pc crm:P02_has_range ?range . \
  369. ?range rdfs:label ?artist . \
  370. ?artist bif:contains \"\'"+ params[i][1] +"\'\" ."
  371. }
  372. if (params[i][0] == "Soggetto" && (params[i][1] != "")) {
  373. sg = " ?depiction";
  374. soggetto = "?subject crm:P62_depicts ?uri_depiction . \
  375. ?uri_depiction rdfs:label ?depiction . \
  376. ?depiction bif:contains \"\'"+ params[i][1] +"\'\" ."
  377. }
  378. if (params[i][0] == "Titolo" && (params[i][1] != "")) {
  379. tt = " ?title";
  380. infObj = "?subject crm:P128_carries ?information_object .";
  381. titolo = "?information_object crm:P1_is_identified_by ?uri_title . \
  382. ?uri_title rdfs:label ?title . \
  383. ?title bif:contains \"\'"+ params[i][1] +"\'\" ."
  384. }
  385. if (params[i][0] == "Tipo di risorsa" && (params[i][1] != "")) {
  386. tp = " ?type";
  387. infObj = "?subject crm:P128_carries ?information_object .";
  388. tipo = "?information_object crm:P2_has_type ?uri_type . \
  389. ?uri_type rdfs:label ?type . \
  390. ?type bif:contains \"\'"+ params[i][1] +"\'\" ."
  391. }
  392. if (params[i][0] == "Note" && (params[i][1] != "")) {
  393. nt = " ?note";
  394. note = "?subject crm:P3_has_note ?uri_note . \
  395. ?uri_note rdfs:label ?note . \
  396. ?note bif:contains \"\'"+ params[i][1] +"\'\" .";
  397. }
  398. if (params[i][0] == "Riferimenti" && (params[i][1] != "")) {
  399. rf = " ?ref";
  400. riferimenti = "?subject crm:P67_refers_to ?uri_ref . \
  401. ?uri_ref rdfs:label ?ref . \
  402. ?ref bif:contains \"\'"+ params[i][1] +"\'\" . "
  403. }
  404. if (params[i][0] == "Nome proprio" && (params[i][1] != "")) {
  405. np = " ?givenName";
  406. nome_proprio = "?subject foaf:givenName ?givenName . \
  407. ?givenName bif:contains \"\'"+ params[i][1] +"\'\" . "
  408. }
  409. if (params[i][0] == "Nome di famiglia" && (params[i][1] != "")) {
  410. nf = " ?familyName";
  411. nome_di_famiglia = "?subject foaf:familyName ?familyName . \
  412. ?familyName bif:contains \"\'"+ params[i][1] +"\'\" . "
  413. }
  414. if (params[i][0] == "Patronimico" && (params[i][1] != "")) {
  415. pt = " ?patronymic";
  416. patronimico = "?subject person:patronymicName ?patronymic . \
  417. ?patronymic bif:contains \"\'"+ params[i][1] +"\'\" . "
  418. }
  419. if (params[i][0] == "Luogo di Nascita" && (params[i][1] != "")) {
  420. ln = " ?birthPlace";
  421. luogo_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  422. ?Birth crm:P7_took_place_at ?uri_birthPlace . \
  423. ?uri_birthPlace rdfs:label ?birthPlace . \
  424. ?birthPlace bif:contains \""+ params[i][1] +"\" . "
  425. }
  426. if (params[i][0] == "Luogo di Morte" && (params[i][1] != "")) {
  427. lm = " ?deathPlace";
  428. luogo_di_Morte = "?subject crm:P100i_died_in ?Death . \
  429. ?Death crm:P7_took_place_at ?uri_deathPlace . \
  430. ?uri_deathPlace rdfs:label ?deathPlace \
  431. ?deathPlace bif:contains \""+ params[i][1] +"\" . "
  432. }
  433. if (params[i][0] == "Genere" && (params[i][1] != "")) {
  434. gr = "?genere";
  435. genere = "?subject foaf:gender ?genere . \
  436. ?genere bif:contains \""+ params[i][1] +"\" . "
  437. }
  438. if (params[i][0] == "Data di Nascita" && (params[i][1] != "")) {
  439. dn = " ?Birth_TS";
  440. data_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  441. ?Birth crm:P4_has_time-span ?Birth_TS . \
  442. ?Birth_TS rdfs:label \""+ params[i][1] +"\" ."
  443. }
  444. if (params[i][0] == "Data di Morte" && (params[i][1] != "")) {
  445. dts = " ?Death_TS";
  446. data_di_Morte = "?subject crm:P100i_died_in ?Death . \
  447. ?Death crm:P4_has_time-span ?Death_TS . \
  448. ?Death_TS rdfs:label \""+ params[i][1] +"\" . "
  449. }
  450. if (params[i][0] == "Qualifica" && (params[i][1] != "")) {
  451. qf = " ?qualification";
  452. qualifica = "?subject schema:honorificPrefix ?qualification . \
  453. ?qualification bif:contains \"\'"+ params[i][1] +"\'\" . "
  454. }
  455. if (params[i][0] == "Occupazione" && (params[i][1] != "")) {
  456. oc = " ?occupation";
  457. occupazione = "?subject schema:hasOccupation ?uriOccupation . \
  458. ?uriOccupation rdf:type schema:Occupation; \
  459. rdfs:label ?occupation . \
  460. ?occupation bif:contains \"\'"+ params[i][1] +"\'\" . "
  461. }
  462. if (params[i][0] == "Gruppi di appartenenza" && (params[i][1] != "")) {
  463. ga = " ?group";
  464. gruppi_di_appartenenza = "?subject crm:P107i_is_current_or_former_member_of ?uriGroup . \
  465. ?uriGroup rdfs:label ?group . \
  466. ?group bif:contains \"\'"+ params[i][1] +"\'\" . "
  467. }
  468. if (params[i][0] == "Mittente" && (params[i][1] != "")) {
  469. mit = " ?mittente";
  470. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  471. ?send rdfs:subClassOf ?mov_ev ; \
  472. rdf:type crm:EL2_Send_Letter . \
  473. ?receive rdfs:subClassOf ?mov_ev; \
  474. rdf:type crm:EL3_Receive_Letter . ";
  475. mittente = "?send crm:P01_has_domain ?pcS . \
  476. ?pcS crm:P02_has_range ?uriSender . \
  477. ?uriSender rdfs:label ?mittente . \
  478. ?mittente bif:contains \"\'"+ params[i][1] +"\'\" . "
  479. }
  480. if (params[i][0] == "Destinatario" && (params[i][1] != "")) {
  481. des = " ?destinatario";
  482. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  483. ?send rdfs:subClassOf ?mov_ev ; \
  484. rdf:type crm:EL2_Send_Letter . \
  485. ?receive rdfs:subClassOf ?mov_ev; \
  486. rdf:type crm:EL3_Receive_Letter . ";
  487. destinatario = "?receive crm:P01_has_domain ?pcR . \
  488. ?pcR crm:P02_has_range ?uriReceiver . \
  489. ?uriReceiver rdfs:label ?destinatario . \
  490. ?destinatario bif:contains \"\'"+ params[i][1] +"\'\" . "
  491. }
  492. if (params[i][0] == "Luogo di Partenza" && (params[i][1] != "")) {
  493. lp = " ?luogo_partenza";
  494. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  495. ?send rdfs:subClassOf ?mov_ev ; \
  496. rdf:type crm:EL2_Send_Letter . \
  497. ?receive rdfs:subClassOf ?mov_ev; \
  498. rdf:type crm:EL3_Receive_Letter . ";
  499. luogo_di_Partenza = "?send crm:P27_moved_from ?uriLuogoPartenza . \
  500. ?uriLuogoPartenza rdfs:label ?luogo_partenza . \
  501. ?luogo_partenza bif:contains \"\'"+ params[i][1] +"\'\" . "
  502. }
  503. if (params[i][0] == "Luogo di Arrivo" && (params[i][1] != "")) {
  504. la = " ?luogo_arrivo";
  505. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  506. ?send rdfs:subClassOf ?mov_ev ; \
  507. rdf:type crm:EL2_Send_Letter . \
  508. ?receive rdfs:subClassOf ?mov_ev; \
  509. rdf:type crm:EL3_Receive_Letter . ";
  510. luogo_di_Arrivo = "?receive crm:P26_moved_to ?uriLuogoArrivo . \
  511. ?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
  512. ?luogo_arrivo bif:contains \"\'"+ params[i][1] +"\'\" . "
  513. }
  514. if (params[i][0] == "Data partenza" && (params[i][1] != "")) {
  515. dp = " ?timeSpanSend";
  516. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  517. ?send rdfs:subClassOf ?mov_ev ; \
  518. rdf:type crm:EL2_Send_Letter . \
  519. ?receive rdfs:subClassOf ?mov_ev; \
  520. rdf:type crm:EL3_Receive_Letter . ";
  521. data_partenza = "?send crm:P4_has_time-span ?time_spanS . \
  522. ?time_spanS rdfs:label ?timeSpanSend . \
  523. ?timeSpanSend bif:contains \"\'"+ params[i][1] +"\'\" . "
  524. }
  525. if (params[i][0] == "Data arrivo" && (params[i][1] != "")) {
  526. da = " ?timeSpanReceive";
  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. data_arrivo = "?receive crm:P4_has_time-span ?time_spanR . \
  533. ?time_spanR rdfs:label ?timeSpanReceive .\
  534. ?timeSpanReceive bif:contains \"\'"+ params[i][1] +"\'\" . "
  535. }
  536. if (params[i][0] == "Lingua" && (params[i][1] != "")) {
  537. lin = " ?lingua";
  538. infObj = "?subject crm:P128_carries ?information_object .";
  539. lingua = "?information_object crm:P72_has_language ?language . \
  540. ?language rdfs:label ?lingua . \
  541. ?lingua bif:contains \"\'"+ params[i][1] +"\'\" ."
  542. }
  543. if (params[i][0] == "Area linguistica" && (params[i][1] != "")) {
  544. alin = " ?area_linguistica";
  545. infObj = "?subject crm:P128_carries ?information_object .";
  546. area_linguistica = "?information_object crm:P72_has_language ?language . \
  547. ?language crm:P3_has_note ?area . \
  548. ?area rdfs:label ?area_linguistica .\
  549. ?area_linguistica bif:contains \"\'"+ params[i][1] +"\'\" ."
  550. }
  551. if (params[i][0] == "Edizione" && (params[i][1] != "")) {
  552. ed = " ?edizione";
  553. infObj = "?subject crm:P128_carries ?information_object .";
  554. edizione = "?edition crm:P70_documents ?information_object ; \
  555. crm:P1_is_identified_by ?edition_id . \
  556. ?edition_id rdfs:label ?edizione . \
  557. ?edizione bif:contains \"\'"+ params[i][1] +"\'\" ."
  558. }
  559. if (params[i][0] == "Toponimo" && (params[i][1] != "")) {
  560. topo = " ?toponimo";
  561. infObj = "?subject crm:P128_carries ?information_object .";
  562. toponimo = "?information_object crm:P67_refers_to ?link_toponimo . \
  563. ?link_toponimo rdfs:label ?toponimo ; \
  564. crm:P2_has_type 'Toponimo' . \
  565. ?toponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
  566. }
  567. if (params[i][0] == "Antroponimo" && (params[i][1] != "")) {
  568. antr = " ?antroponimo";
  569. infObj = "?subject crm:P128_carries ?information_object .";
  570. antroponimo = "?information_object crm:P67_refers_to ?link_antroponimo . \
  571. ?link_antroponimo rdfs:label ?antroponimo; \
  572. crm:P2_has_type 'Antroponimo' . \
  573. ?antroponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
  574. }
  575. if (params[i][0] == "Data" && (params[i][1] != "")) {
  576. dt = " ?date";
  577. data = "?subject ?property ?event . \
  578. ?event crm:P4_has_time-span ?uri_date . \
  579. ?uri_date rdfs:label ?date . \
  580. ?date bif:contains \"\'"+ params[i][1] +"\'\" ."
  581. }
  582. }
  583. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  584. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  585. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  586. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  587. PREFIX schema: <http://schema.org/> \
  588. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  589. PREFIX person: <http://www.w3.org/ns/person#>"
  590. query = prefixes + " SELECT DISTINCT ?subject ?label ?identifier " + dm + mt + locl + tec + at
  591. + sg + tt + tp + nt + rf + np + nf + pt + ln + lm + gr + dn + dts + oc + qf + ga + mit
  592. + des + lp + la + dp + da + lin + alin + ed + antr + topo + dt + " \
  593. WHERE {GRAPH " + search_graph + " {?subject ?property ?object } \
  594. ?subject rdfs:label ?label . "
  595. + search_identifier + infObj + letter_event + label + search_type + dimensione + materia + localizzazione + tecnica
  596. + artista + titolo + tipo + note + riferimenti + nome_proprio + nome_di_famiglia
  597. + patronimico + luogo_di_Nascita + luogo_di_Morte + genere + data_di_Nascita
  598. + data_di_Morte + qualifica + occupazione + gruppi_di_appartenenza + mittente + destinatario
  599. +luogo_di_Partenza + luogo_di_Arrivo + data_partenza + data_arrivo + lingua
  600. + area_linguistica + edizione + toponimo + antroponimo + data + identificatore + "}"
  601. var query_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
  602. console.log(query);
  603. $.ajax({
  604. url: query_url + '&callback=?',
  605. dataType: "json",
  606. success: function (data) {
  607. query_handle_json(data, choosen_type);
  608. },
  609. error: function (e) {}
  610. });
  611. }
  612. function query_handle_json(json, choosen_type) {
  613. console.log(json);
  614. var resulType = "";
  615. if (choosen_type == "Object") {
  616. resulType = "object";
  617. }
  618. if (choosen_type == "Letter") {
  619. resulType = "object";
  620. }
  621. if (choosen_type == "OA") {
  622. resulType = "artwork";
  623. }
  624. if (choosen_type == "Person") {
  625. resulType = "persona";
  626. }
  627. $('#query_results').text("");
  628. var i = 0;
  629. const first_row = [];
  630. $.each(
  631. json['head']['vars'],
  632. function (index, value) {
  633. first_row.push(value);
  634. });
  635. var t_head = '<div class="row t_head">';
  636. for (let k = 1; k < first_row.length; k++) {
  637. var param = renameCol(first_row[k]);
  638. t_head += '<div class="col-auto">' + param + '</div>';
  639. }
  640. t_head += '</div>';
  641. $('#query_results').append(t_head);
  642. $.each(
  643. json['results']['bindings'],
  644. function (index, value) {
  645. var object = "";
  646. var link = value['subject']['value'];
  647. var label = value['label']['value'];
  648. object += '<div class="row"><div id="' + link + '" class="col-auto link ' + resulType + '">' + label + '</div>';
  649. if (value.hasOwnProperty('identifier')) {
  650. identifier = value['identifier']['value'];
  651. object += '<div class="col-auto">' + identifier + '</div>';
  652. }
  653. if (value.hasOwnProperty('dimension')) {
  654. dimension = value['dimension']['value'];
  655. object += '<div class="col-auto">' + dimension + '</div>';
  656. }
  657. if (value.hasOwnProperty('material')) {
  658. material = value['material']['value'];
  659. object += '<div class="col-auto">' + material + '</div>';
  660. }
  661. if (value.hasOwnProperty('location')) {
  662. localization = value['location']['value'];
  663. object += '<div class="col-auto">' + localization + '</div>';
  664. }
  665. if (value.hasOwnProperty('technique')) {
  666. technique = value['technique']['value'];
  667. object += '<div class="col-auto">' + technique + '</div>';
  668. }
  669. if (value.hasOwnProperty('artist')) {
  670. artist = value['artist']['value'];
  671. object += '<div class="col-auto">' + artist + '</div>';
  672. }
  673. if (value.hasOwnProperty('depiction')) {
  674. depiction = value['depiction']['value'];
  675. object += '<div class="col-auto">' + depiction + '</div>';
  676. }
  677. if (value.hasOwnProperty('title')) {
  678. title = value['title']['value'];
  679. object += '<div class="col-auto">' + title + '</div>';
  680. }
  681. if (value.hasOwnProperty('type')) {
  682. type = value['type']['value'];
  683. object += '<div class="col-auto">' + type + '</div>';
  684. }
  685. if (value.hasOwnProperty('note')) {
  686. note = value['note']['value'];
  687. object += '<div class="col-auto">' + note + '</div>';
  688. }
  689. if (value.hasOwnProperty('ref')) {
  690. ref = value['ref']['value'];
  691. object += '<div class="col-auto">' + ref + '</div>';
  692. }
  693. if (value.hasOwnProperty('givenName')) {
  694. givenName = value['givenName']['value'];
  695. object += '<div class="col-auto">' + givenName + '</div>';
  696. }
  697. if (value.hasOwnProperty('familyName')) {
  698. familyName = value['familyName']['value'];
  699. object += '<div class="col-auto">' + familyName + '</div>';
  700. }
  701. if (value.hasOwnProperty('patronymic')) {
  702. patronymic = value['patronymic']['value'];
  703. object += '<div class="col-auto">' + patronymic + '</div>';
  704. }
  705. if (value.hasOwnProperty('birthPlace')) {
  706. birthPlace = value['birthPlace']['value'];
  707. object += '<div class="col-auto">' + birthPlace + '</div>';
  708. }
  709. if (value.hasOwnProperty('deathPlace')) {
  710. deathPlace = value['deathPlace']['value'];
  711. object += '<div class="col-auto">' + deathPlace + '</div>';
  712. }
  713. if (value.hasOwnProperty('genere')) {
  714. genere = value['genere']['value'];
  715. object += '<div class="col-auto">' + genere + '</div>';
  716. }
  717. if (value.hasOwnProperty('Birth_TS')) {
  718. Birth_TS = value['Birth_TS']['value'];
  719. object += '<div class="col-auto">' + Birth_TS + '</div>';
  720. }
  721. if (value.hasOwnProperty('Death_TS')) {
  722. Death_TS = value['Death_TS']['value'];
  723. object += '<div class="col-auto">' + Death_TS + '</div>';
  724. }
  725. if (value.hasOwnProperty('qualification')) {
  726. qualification = value['qualification']['value'];
  727. object += '<div class="col-auto">' + qualification + '</div>';
  728. }
  729. if (value.hasOwnProperty('occupation')) {
  730. occupation = value['occupation']['value'];
  731. object += '<div class="col-auto">' + occupation + '</div>';
  732. }
  733. if (value.hasOwnProperty('group')) {
  734. group = value['group']['value'];
  735. object += '<div class="col-auto">' + group + '</div>';
  736. }
  737. if (value.hasOwnProperty('mittente')) {
  738. mittente = value['mittente']['value'];
  739. object += '<div class="col-auto">' + mittente + '</div>';
  740. }
  741. if (value.hasOwnProperty('destinatario')) {
  742. destinatario = value['destinatario']['value'];
  743. object += '<div class="col-auto">' + destinatario + '</div>';
  744. }
  745. if (value.hasOwnProperty('luogo_partenza')) {
  746. luogo_partenza = value['luogo_partenza']['value'];
  747. object += '<div class="col-auto">' + luogo_partenza + '</div>';
  748. }
  749. if (value.hasOwnProperty('luogo_arrivo')) {
  750. luogo_arrivo = value['luogo_arrivo']['value'];
  751. object += '<div class="col-auto">' + luogo_arrivo + '</div>';
  752. }
  753. if (value.hasOwnProperty('timeSpanSend')) {
  754. timeSpanSend = value['timeSpanSend']['value'];
  755. object += '<div class="col-auto">' + timeSpanSend + '</div>';
  756. }
  757. if (value.hasOwnProperty('timeSpanReceive')) {
  758. timeSpanReceive = value['timeSpanReceive']['value'];
  759. object += '<div class="col-auto">' + timeSpanReceive + '</div>';
  760. }
  761. if (value.hasOwnProperty('lingua')) {
  762. lingua = value['lingua']['value'];
  763. object += '<div class="col-auto">' + lingua + '</div>';
  764. }
  765. if (value.hasOwnProperty('area_linguistica')) {
  766. area_linguistica = value['area_linguistica']['value'];
  767. object += '<div class="col-auto">' + area_linguistica + '</div>';
  768. }
  769. if (value.hasOwnProperty('edizione')) {
  770. edizione = value['edizione']['value'];
  771. object += '<div class="col-auto">' + edizione + '</div>';
  772. }
  773. if (value.hasOwnProperty('toponimo')) {
  774. toponimo = value['toponimo']['value'];
  775. object += '<div class="col-auto">' + toponimo + '</div>';
  776. }
  777. if (value.hasOwnProperty('antroponimo')) {
  778. antroponimo = value['antroponimo']['value'];
  779. object += '<div class="col-auto">' + antroponimo + '</div>';
  780. }
  781. if (value.hasOwnProperty('date')) {
  782. date = value['date']['value'];
  783. object += '<div class="col-auto">' + date + '</div>';
  784. }
  785. object += '</div>';
  786. i++;
  787. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  788. $('#query_results').append(object);
  789. });
  790. if (i==0) {
  791. var message = '<p>Nessun risultato trovato</p>';
  792. $('#query_results').append(message);
  793. }
  794. document.getElementById("n_res").innerHTML = i;
  795. }
  796. function renameCol(param) {
  797. if (param == "label") {
  798. return ("Denominazione");
  799. }
  800. else if (param == "identifier") {
  801. return ("Identificatore");
  802. }
  803. else if (param == "dimension") {
  804. return ("Dimensioni");
  805. }
  806. else if (param == "material") {
  807. return ("Materiale");
  808. }
  809. else if (param == "location") {
  810. return ("Istituto di conservazione");
  811. }
  812. else if (param == "technique") {
  813. return ("Tecnica");
  814. }
  815. else if (param == "artist") {
  816. return ("Artista");
  817. }
  818. else if (param == "depiction") {
  819. return ("Soggetto");
  820. }
  821. else if (param == "title") {
  822. return ("Titolo");
  823. }
  824. else if (param == "type") {
  825. return ("Tipologia");
  826. }
  827. else if (param == "note") {
  828. return ("Note");
  829. }
  830. else if (param == "ref") {
  831. return ("Riferimenti");
  832. }
  833. else if (param == "givenName") {
  834. return ("Nome proprio");
  835. }
  836. else if (param == "familyName") {
  837. return ("Cognome");
  838. }
  839. else if (param == "birthPlace") {
  840. return ("Luogo di Nascita");
  841. }
  842. else if (param == "deathPlace") {
  843. return ("Luogo di morte");
  844. }
  845. else if (param == "genere") {
  846. return ("Genere");
  847. }
  848. else if (param == "Birth_TS") {
  849. return ("Data di nascita");
  850. }
  851. else if (param == "Death_TS") {
  852. return ("Data di morte");
  853. }
  854. else if (param == "qualification") {
  855. return ("Qualifica");
  856. }
  857. else if (param == "occupation") {
  858. return ("Occupazione");
  859. }
  860. else if (param == "mittente") {
  861. return ("Mittente");
  862. }
  863. else if (param == "destinatario") {
  864. return ("Destinatario");
  865. }
  866. else if (param == "luogo_partenza") {
  867. return ("Luogo di partenza");
  868. }
  869. else if (param == "luogo_arrivo") {
  870. return ("Luogo di arrivo");
  871. }
  872. else if (param == "timeSpanSend") {
  873. return ("Data partenza");
  874. }
  875. else if (param == "timeSpanReceive") {
  876. return ("Data arrivo");
  877. }
  878. else if (param == "area_linguistica") {
  879. return ("Area linguistica");
  880. }
  881. else if (param == "edizione") {
  882. return ("Edizione");
  883. }
  884. else if (param == "lemma") {
  885. return ("Lemma");
  886. }
  887. else if (param == "date") {
  888. return ("Data");
  889. }
  890. else {
  891. return (param);
  892. }
  893. }