lettera_query.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://iperion.vm.fedcloud.eu:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. // Esegue una query sull'endpoint SPARQL il cui testo completo deve essere fornito nel parametro-stringa 'query'
  14. // Restituisce una lista di oggetti json nel formato di Virtuoso
  15. // Il parametro opzionale 'isUnique', se messo a 'true' controlla che ci sia un unico risultato (un array di
  16. // lunghezza 1) e se non è così restituisce un errore.
  17. async function doJsonQuery(query, isUnique = false){
  18. queryURL = prepareQueryURL(query);
  19. response = await $.ajax({//OGGETTO
  20. url: queryURL,
  21. dataType: "json",
  22. success: function (data){},
  23. error: function (e) {
  24. console.log("Exception in query:", e);
  25. }
  26. });
  27. let out = response['results']['bindings'];
  28. if(!isUnique) return out;
  29. if(!out.length) throw "ERROR: Letter not found";
  30. if(out.length>1) throw "ERROR: ambiguity in search -- multiple letters matching search parameters";
  31. return out[0];
  32. }
  33. // Nuova funzione per l'NLP
  34. function loadPageNLP()
  35. {
  36. window.location="nlp.html?link=" + thisUrlParams.link;
  37. }
  38. // Nuova funzione per Button LOD
  39. function loadPageLOD()
  40. {
  41. window.location="http://iperion.vm.fedcloud.eu/lodlive/?" + thisUrlParams.link;
  42. }
  43. ////////////////////
  44. // TESTI DELLE QUERY
  45. ////////////////////
  46. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  47. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  48. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  49. PREFIX dat: <http://datini.archiviodistato.prato.it/la-ricerca/scheda/> \
  50. PREFIX mpp: <http://palazzopretorio.comune.prato.it/it/le-opere/alcuni-capolavori/> \
  51. PREFIX aut: <http://palazzopretorio.comune.prato.it/it/opere/autori/>"
  52. query1 = prefixes + " SELECT DISTINCT ?subject ?mittente ?destinatario ?data_partenza ?data_arrivo ?uriLuogoPartenza ?luogo_partenza ?uriLuogoArrivo ?luogo_arrivo \
  53. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> \
  54. GRAPH <http://147.213.76.182:8890/ovi/datini> {?subject crm:P25i_moved_by ?mov_ev .} \
  55. ?send rdfs:subClassOf ?mov_ev ; \
  56. rdf:type crm:EL2_Send_Letter . \
  57. OPTIONAL {?send crm:P4_has_time-span ?time_spanA . \
  58. ?time_spanA rdfs:label ?data_partenza . } \
  59. OPTIONAL {?send crm:P27_moved_from ?uriPlaceSend . \
  60. ?uriPlaceSend rdfs:label ?luogo_partenza . \
  61. OPTIONAL {?uriPlaceSend owl:sameAs ?uriLuogoPartenza .}} \
  62. OPTIONAL {?send crm:P01_has_domain ?uriMittente . \
  63. ?uriMittente crm:P02_has_range ?mittente . } \
  64. \
  65. ?receive rdfs:subClassOf ?mov_ev; \
  66. rdf:type crm:EL3_Receive_Letter . \
  67. OPTIONAL {?receive crm:P4_has_time-span ?time_spanB . \
  68. ?time_spanB rdfs:label ?data_arrivo . } \
  69. OPTIONAL {?receive crm:P26_moved_to ?uriPlaceReceive . \
  70. ?uriPlaceReceive rdfs:label ?luogo_arrivo . \
  71. OPTIONAL {?uriPlaceReceive owl:sameAs ?uriLuogoArrivo .} } \
  72. OPTIONAL {?receive crm:P01_has_domain ?receiver . \
  73. ?receiver crm:P02_has_range ?destinatario . } \
  74. } LIMIT 1"
  75. query2 = prefixes + " SELECT DISTINCT ?uriSender ?mittente ?uriReceiver ?destinatario ?timeSpanSend ?timeSpanReceive ?placeSend ?placeReceive ?identifier ?material ?dimension ?currentLocation \
  76. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> . \
  77. GRAPH <http://147.213.76.182:8890/aspo/datini> {?subject crm:P25i_moved_by ?mov_ev .} \
  78. ?send rdfs:subClassOf ?mov_ev ; \
  79. rdf:type crm:EL2_Send_Letter . \
  80. ?receive rdfs:subClassOf ?mov_ev ; \
  81. rdf:type crm:EL3_Receive_Letter . \
  82. \
  83. OPTIONAL {?subject crm:P54_has_current_permanent_location ?currentLocation . } \
  84. OPTIONAL {?subject crm:P45_consist_of ?uriMaterial . \
  85. ?uriMaterial rdfs:label ?material . } \
  86. OPTIONAL {?subject crm:P43_has_dimension ?uriDimension . \
  87. ?uriDimension rdfs:label ?dimension . } \
  88. OPTIONAL {?subject crm:P1_is_identified_by ?uriIdentifier . \
  89. ?uriIdentifier rdfs:label ?identifier ; \
  90. crm:P2_has_type 'Segnatura'} \
  91. \
  92. OPTIONAL {?send crm:P4_has_time-span ?time_spanS . \
  93. ?time_spanS rdfs:label ?timeSpanSend } \
  94. OPTIONAL {?receive crm:P4_has_time-span ?time_spanR . \
  95. ?time_spanR rdfs:label ?timeSpanReceive } \
  96. \
  97. OPTIONAL {?send crm:P27_moved_from ?placeS . \
  98. ?placeS rdfs:label ?placeSend } \
  99. OPTIONAL {?receive crm:P26_moved_to ?placeR . \
  100. ?placeR rdfs:label ?placeReceive } \
  101. \
  102. OPTIONAL {?send crm:P01_has_domain ?pcS . \
  103. ?pcS crm:P02_has_range ?uriSender . \
  104. ?uriSender rdfs:label ?mittente } \
  105. \
  106. OPTIONAL {?receive crm:P01_has_domain ?pcR . \
  107. ?pcR crm:P02_has_range ?uriReceiver . \
  108. ?uriReceiver rdfs:label ?destinatario } \
  109. } LIMIT 1"
  110. querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
  111. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
  112. crm:P1_is_identified_by ?segnatura_ASPO . \
  113. ?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
  114. ?segnatura crm:P2_has_type ?tipo_segnatura ; \
  115. rdfs:label ?segnatura_OVI . \
  116. ?tipo_segnatura rdfs:label \"Segnatura OVI\"} LIMIT 1"
  117. queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
  118. WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
  119. ?language crm:P3_has_note ?area ; \
  120. rdfs:label ?lingua . \
  121. ?area rdfs:label ?area_linguistica \
  122. } LIMIT 1"
  123. queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
  124. WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
  125. ?description rdfs:label ?descrizione \
  126. } LIMIT 1"
  127. queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
  128. WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
  129. ?type rdf:type crm:E55_Type; \
  130. rdfs:label ?tipologia . \
  131. } LIMIT 1"
  132. querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
  133. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
  134. ?id rdf:type crm:E42_Identifier; \
  135. crm:P2_has_type ?type ; \
  136. rdfs:label ?sigla_OVI . \
  137. ?type rdfs:label 'Sigla OVI'. \
  138. } LIMIT 1"
  139. queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
  140. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri_title . \
  141. ?uri_title rdf:type crm:E35_Title ; \
  142. rdfs:label ?titolo . \
  143. } LIMIT 1"
  144. queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
  145. WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
  146. } LIMIT 1"
  147. queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
  148. WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
  149. crm:P1_is_identified_by ?edition_id . \
  150. ?edition_id rdfs:label ?edizione; \
  151. crm:P139_has_alternative_form ?ed_abbr . \
  152. ?ed_abbr rdfs:label ?edizione_abbreviata \
  153. } LIMIT 1"
  154. queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
  155. WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
  156. crm:P2_has_type ?racc_type ; \
  157. rdfs:label ?raccolta . \
  158. ?racc_type rdfs:label 'Raccolta'. \
  159. } LIMIT 1"
  160. queryToponimi = prefixes + "SELECT DISTINCT ?uri_lemma ?lemma ?uri_place \
  161. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?uri_lemma . \
  162. ?uri_lemma rdfs:label ?lemma ; \
  163. crm:P2_has_type 'Toponimo' . \
  164. OPTIONAL {?uri_place crm:P1_is_identified_by ?uri_lemma ; \
  165. crm:P168_place_is_defined_by ?coords . \
  166. } \
  167. }"
  168. queryAntroponimi = prefixes + "SELECT DISTINCT ?uri_lemma ?lemma \
  169. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?uri_lemma . \
  170. ?uri_lemma rdfs:label ?lemma; \
  171. crm:P2_has_type 'Antroponimo'}"
  172. /*queryLemmi = prefixes + " SELECT DISTINCT ?uri_lemma ?lemma ?tipo ?pos ?uri_iperlemma ?iperlemma \
  173. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?uri_thing . \
  174. ?uri_thing crm:P128_carries ?uri_lemma . \
  175. ?uri_lemma rdfs:label ?lemma ; \
  176. crm:P2_has_type ?uri_pos . \
  177. ?uri_pos rdfs:label ?pos . \
  178. OPTIONAL {?uri_thing crm:P2_has_type ?uri_type . \
  179. ?uri_type rdfs:label ?tipo .} \
  180. OPTIONAL {?uri_lemma rdfs:subClassOf ?uri_iperlemma . \
  181. ?uri_iperlemma rdfs:label ?iperlemma .} \
  182. }"*/
  183. queryLemmi = prefixes + "SELECT DISTINCT ?uri_lemma ?lemma ?tipo ?pos ?uri_iperlemma ?iperlemma \
  184. WHERE { \
  185. VALUES ?uri {<" + thisUrlParams.link + ">} \
  186. {?uri crm:P67_refers_to ?uri_lemma . } \
  187. UNION \
  188. {?uri crm:P67_refers_to ?uri_thing . \
  189. ?uri_thing crm:P128_carries ?uri_lemma . \
  190. OPTIONAL {?uri_thing crm:P2_has_type ?uri_type . \
  191. ?uri_type rdfs:label ?tipo .} } \
  192. ?uri_lemma rdfs:label ?lemma ; \
  193. crm:P2_has_type ?uri_pos . \
  194. ?uri_pos rdfs:label ?pos . \
  195. OPTIONAL {?uri_lemma rdfs:subClassOf ?uri_iperlemma . \
  196. ?uri_iperlemma rdfs:label ?iperlemma .} \
  197. }"