lettera_query.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Recupero i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  2. thisUrlParams = {};
  3. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. thisUrlParams[key] = value;
  5. });
  6. console.log('URL get params: ', thisUrlParams);
  7. // Funzioni per eseguire le queries
  8. queryOutput2 = {};
  9. function addResponseToOutput(key, val){
  10. resultArray = val['results']['bindings'];
  11. queryOutput2[key] = resultArray;
  12. }
  13. function prepareQueryURL(query){
  14. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  15. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  16. return sparqlEndpoint + sparqlUrlParams;
  17. }
  18. async function doJsonQuery(query, isUnique = false){
  19. queryURL = prepareQueryURL(query);
  20. response = await $.ajax({//OGGETTO
  21. url: queryURL,
  22. dataType: "json",
  23. success: function (data){},
  24. error: function (e) {
  25. console.log("Exception in query:", e);
  26. }
  27. });
  28. let out = response['results']['bindings'];
  29. if(!isUnique) return out;
  30. if(!out.length) throw "Letter not found";
  31. if(out.length>1) throw "Ambiguity -- multiple letters matching URI";
  32. return out;
  33. }
  34. // Funzioni per raccattare + stringhificare l'output
  35. queryStringOutput = "";
  36. function stringifyResponse(val){
  37. resultArray = val['results']['bindings'];
  38. out = "";
  39. for(i = 0; i < resultArray.length; i++){
  40. out = out + JSON.stringify(resultArray[i])
  41. }
  42. queryStringOutput = (queryStringOutput + out).replaceAll("}{",",");
  43. }
  44. ////////////////////
  45. // TESTI DELLE QUERY
  46. ////////////////////
  47. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  48. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  49. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  50. PREFIX dat: <http://datini.archiviodistato.prato.it/la-ricerca/scheda/> \
  51. PREFIX mpp: <http://palazzopretorio.comune.prato.it/it/le-opere/alcuni-capolavori/> \
  52. PREFIX aut: <http://palazzopretorio.comune.prato.it/it/opere/autori/>"
  53. query1 = prefixes + " SELECT DISTINCT ?mittente ?destinatario ?data_partenza ?data_arrivo ?luogo_partenza ?luogo_arrivo \
  54. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> \
  55. GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini/ex> {?subject crm:P25i_moved_by ?mov_ev .} \
  56. ?send rdfs:subClassOf ?mov_ev ; \
  57. rdf:type crm:EL2_Send_Letter ; \
  58. crm:P4_has_time-span ?time_spanA; \
  59. crm:P27_moved_from ?placeA; \
  60. crm:P01_has_domain ?sender . \
  61. \
  62. ?time_spanA rdfs:label ?data_partenza . \
  63. ?placeA rdfs:label ?luogo_partenza . \
  64. ?sender crm:P02_has_range ?mittente . \
  65. \
  66. ?receive rdfs:subClassOf ?mov_ev; \
  67. rdf:type crm:EL3_Receive_Letter ; \
  68. crm:P4_has_time-span ?time_spanB; \
  69. crm:P26_moved_to ?placeB; \
  70. crm:P01_has_domain ?receiver . \
  71. \
  72. ?time_spanB rdfs:label ?data_arrivo . \
  73. ?placeB rdfs:label ?luogo_arrivo . \
  74. ?receiver crm:P02_has_range ?destinatario . \
  75. }"
  76. querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
  77. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
  78. crm:P1_is_identified_by ?segnatura_ASPO . \
  79. ?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
  80. ?segnatura crm:P2_has_type ?tipo_segnatura; \
  81. rdfs:label ?segnatura_OVI . \
  82. ?tipo_segnatura rdfs:label \"Segnatura OVI\"}"
  83. queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
  84. WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
  85. ?language crm:P3_has_note ?area ; \
  86. rdfs:label ?lingua . \
  87. ?area rdfs:label ?area_linguistica \
  88. }"
  89. queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
  90. WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
  91. ?description rdfs:label ?descrizione \
  92. }"
  93. queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
  94. WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
  95. ?type rdf:type crm:E55_Type; \
  96. rdfs:label ?tipologia . \
  97. }"
  98. querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
  99. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
  100. ?id rdf:type crm:E42_Identifier; \
  101. crm:P2_has_type ?type ; \
  102. rdfs:label ?sigla_OVI . \
  103. ?type rdfs:label 'Sigla OVI'. \
  104. }"
  105. queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
  106. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
  107. ?title rdf:type crm:E35_Title; \
  108. rdfs:label ?titolo . \
  109. }"
  110. queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
  111. WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
  112. }"
  113. queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
  114. WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
  115. crm:P1_is_identified_by ?edition_id . \
  116. ?edition_id rdfs:label ?edizione; \
  117. crm:P139_has_alternative_form ?ed_abbr . \
  118. ?ed_abbr rdfs:label ?edizione_abbreviata \
  119. }"
  120. queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
  121. WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
  122. crm:P2_has_type ?racc_type ; \
  123. rdfs:label ?raccolta . \
  124. ?racc_type rdfs:label 'Raccolta'. \
  125. }"
  126. queryToponimo = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
  127. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
  128. ?link_toponimo rdfs:label ?toponimo ; \
  129. crm:P2_has_type 'Toponimo' . \
  130. }"
  131. queryAntroponimo = prefixes + "SELECT DISTINCT * \
  132. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
  133. ?link_antroponimo rdfs:label ?antroponimo; \
  134. crm:P2_has_type 'Antroponimo'}"