lettera_query.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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://dev.restore.ovi.cnr.it: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 EVT
  39. function loadPageEVT()
  40. {
  41. window.location="http://restore.ovi.cnr.it/mockup/evt/index.html";
  42. }
  43. // Nuova funzione per Button LOD
  44. function loadPageLOD()
  45. {
  46. window.location="http://dev.restore.ovi.cnr.it/lodlive/?" + thisUrlParams.link;
  47. }
  48. ////////////////////
  49. // TESTI DELLE QUERY
  50. ////////////////////
  51. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  52. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  53. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  54. PREFIX dat: <http://datini.archiviodistato.prato.it/la-ricerca/scheda/> \
  55. PREFIX mpp: <http://palazzopretorio.comune.prato.it/it/le-opere/alcuni-capolavori/> \
  56. PREFIX aut: <http://palazzopretorio.comune.prato.it/it/opere/autori/>"
  57. query1 = prefixes + " SELECT DISTINCT ?subject ?mittente ?destinatario ?data_partenza ?data_arrivo ?uriLuogoPartenza ?luogo_partenza ?uriLuogoArrivo ?luogo_arrivo \
  58. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> \
  59. GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?subject crm:P25i_moved_by ?mov_ev .} \
  60. ?send rdfs:subClassOf ?mov_ev ; \
  61. rdf:type crm:EL2_Send_Letter ; \
  62. crm:P4_has_time-span ?time_spanA; \
  63. crm:P27_moved_from ?uriLuogoPartenza; \
  64. crm:P01_has_domain ?uriMittente . \
  65. \
  66. ?time_spanA rdfs:label ?data_partenza . \
  67. ?uriLuogoPartenza rdfs:label ?luogo_partenza . \
  68. ?uriMittente crm:P02_has_range ?mittente . \
  69. \
  70. ?receive rdfs:subClassOf ?mov_ev; \
  71. rdf:type crm:EL3_Receive_Letter ; \
  72. crm:P4_has_time-span ?time_spanB; \
  73. crm:P26_moved_to ?uriLuogoArrivo; \
  74. crm:P01_has_domain ?receiver . \
  75. \
  76. ?time_spanB rdfs:label ?data_arrivo . \
  77. ?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
  78. ?receiver crm:P02_has_range ?destinatario . \
  79. }"
  80. query2 = prefixes + " SELECT DISTINCT ?uriSender ?mittente ?uriReceiver ?destinatario ?timeSpanSend ?timeSpanReceive ?placeSend ?placeReceive ?identifier ?material ?dimension ?currentLocation \
  81. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> . \
  82. GRAPH <http://dev.restore.ovi.cnr.it:8890/aspo/datini/item> {?subject crm:P25i_moved_by ?mov_ev .} \
  83. ?send rdfs:subClassOf ?mov_ev ; \
  84. rdf:type crm:EL2_Send_Letter . \
  85. ?receive rdfs:subClassOf ?mov_ev ; \
  86. rdf:type crm:EL3_Receive_Letter . \
  87. \
  88. OPTIONAL {?subject crm:P54_has_current_permanent_location ?uriCurrentLocation . \
  89. ?uriCurrentLocation rdfs:label ?currentLocation . } \
  90. OPTIONAL {?subject crm:P45_consist_of ?uriMaterial . \
  91. ?uriMaterial rdfs:label ?material . } \
  92. OPTIONAL {?subject crm:P43_has_dimension ?uriDimension . \
  93. ?uriDimension rdfs:label ?dimension . } \
  94. OPTIONAL {?subject crm:P1_is_identified_by ?uriIdentifier . \
  95. ?uriIdentifier rdfs:label ?identifier . \
  96. ?identifier bif:contains 'Segnatura'} \
  97. \
  98. OPTIONAL {?send crm:P4_has_time-span ?time_spanS . \
  99. ?time_spanS rdfs:label ?timeSpanSend } \
  100. OPTIONAL {?receive crm:P4_has_time-span ?time_spanR . \
  101. ?time_spanR rdfs:label ?timeSpanReceive } \
  102. \
  103. OPTIONAL {?send crm:P27_moved_from ?placeS . \
  104. ?placeS rdfs:label ?placeSend } \
  105. OPTIONAL {?receive crm:P26_moved_to ?placeR . \
  106. ?placeR rdfs:label ?placeReceive } \
  107. \
  108. OPTIONAL {?send crm:P01_has_domain ?pcS . \
  109. ?pcS crm:P02_has_range ?uriSender . \
  110. ?uriSender rdfs:label ?mittente } \
  111. \
  112. OPTIONAL {?receive crm:P01_has_domain ?pcR . \
  113. ?pcR crm:P02_has_range ?uriReceiver . \
  114. ?uriReceiver rdfs:label ?destinatario } \
  115. }"
  116. querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
  117. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
  118. crm:P1_is_identified_by ?segnatura_ASPO . \
  119. ?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
  120. ?segnatura crm:P2_has_type ?tipo_segnatura ; \
  121. rdfs:label ?segnatura_OVI . \
  122. ?tipo_segnatura rdfs:label \"Segnatura OVI\"}"
  123. queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
  124. WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
  125. ?language crm:P3_has_note ?area ; \
  126. rdfs:label ?lingua . \
  127. ?area rdfs:label ?area_linguistica \
  128. }"
  129. queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
  130. WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
  131. ?description rdfs:label ?descrizione \
  132. }"
  133. queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
  134. WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
  135. ?type rdf:type crm:E55_Type; \
  136. rdfs:label ?tipologia . \
  137. }"
  138. querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
  139. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
  140. ?id rdf:type crm:E42_Identifier; \
  141. crm:P2_has_type ?type ; \
  142. rdfs:label ?sigla_OVI . \
  143. ?type rdfs:label 'Sigla OVI'. \
  144. }"
  145. queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
  146. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
  147. ?title rdf:type crm:E35_Title; \
  148. rdfs:label ?titolo . \
  149. }"
  150. queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
  151. WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
  152. }"
  153. queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
  154. WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
  155. crm:P1_is_identified_by ?edition_id . \
  156. ?edition_id rdfs:label ?edizione; \
  157. crm:P139_has_alternative_form ?ed_abbr . \
  158. ?ed_abbr rdfs:label ?edizione_abbreviata \
  159. }"
  160. queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
  161. WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
  162. crm:P2_has_type ?racc_type ; \
  163. rdfs:label ?raccolta . \
  164. ?racc_type rdfs:label 'Raccolta'. \
  165. }"
  166. queryToponimi = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
  167. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
  168. ?link_toponimo rdfs:label ?toponimo ; \
  169. crm:P2_has_type 'Toponimo' . \
  170. }"
  171. queryAntroponimi = prefixes + "SELECT DISTINCT * \
  172. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
  173. ?link_antroponimo rdfs:label ?antroponimo; \
  174. crm:P2_has_type 'Antroponimo'}"