lettera_query.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. OPTIONAL {?send crm:P4_has_time-span ?time_spanA . \
  63. ?time_spanA rdfs:label ?data_partenza . } \
  64. OPTIONAL {?send crm:P27_moved_from ?uriLuogoPartenza . \
  65. ?uriLuogoPartenza rdfs:label ?luogo_partenza . } \
  66. OPTIONAL {?send crm:P01_has_domain ?uriMittente . \
  67. ?uriMittente crm:P02_has_range ?mittente . } \
  68. \
  69. ?receive rdfs:subClassOf ?mov_ev; \
  70. rdf:type crm:EL3_Receive_Letter . \
  71. OPTIONAL {?receive crm:P4_has_time-span ?time_spanB . \
  72. ?time_spanB rdfs:label ?data_arrivo . } \
  73. OPTIONAL {?receive crm:P26_moved_to ?uriLuogoArrivo . \
  74. ?uriLuogoArrivo rdfs:label ?luogo_arrivo . } \
  75. OPTIONAL {?receive crm:P01_has_domain ?receiver . \
  76. ?receiver crm:P02_has_range ?destinatario . } \
  77. } LIMIT 1"
  78. query2 = prefixes + " SELECT DISTINCT ?uriSender ?mittente ?uriReceiver ?destinatario ?timeSpanSend ?timeSpanReceive ?placeSend ?placeReceive ?identifier ?material ?dimension ?currentLocation \
  79. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> . \
  80. GRAPH <http://dev.restore.ovi.cnr.it:8890/aspo/datini/item> {?subject crm:P25i_moved_by ?mov_ev .} \
  81. ?send rdfs:subClassOf ?mov_ev ; \
  82. rdf:type crm:EL2_Send_Letter . \
  83. ?receive rdfs:subClassOf ?mov_ev ; \
  84. rdf:type crm:EL3_Receive_Letter . \
  85. \
  86. OPTIONAL {?subject crm:P54_has_current_permanent_location ?uriCurrentLocation . \
  87. ?uriCurrentLocation rdfs:label ?currentLocation . } \
  88. OPTIONAL {?subject crm:P45_consist_of ?uriMaterial . \
  89. ?uriMaterial rdfs:label ?material . } \
  90. OPTIONAL {?subject crm:P43_has_dimension ?uriDimension . \
  91. ?uriDimension rdfs:label ?dimension . } \
  92. OPTIONAL {?subject crm:P1_is_identified_by ?uriIdentifier . \
  93. ?uriIdentifier rdfs:label ?identifier . \
  94. ?identifier bif:contains 'Segnatura'} \
  95. \
  96. OPTIONAL {?send crm:P4_has_time-span ?time_spanS . \
  97. ?time_spanS rdfs:label ?timeSpanSend } \
  98. OPTIONAL {?receive crm:P4_has_time-span ?time_spanR . \
  99. ?time_spanR rdfs:label ?timeSpanReceive } \
  100. \
  101. OPTIONAL {?send crm:P27_moved_from ?placeS . \
  102. ?placeS rdfs:label ?placeSend } \
  103. OPTIONAL {?receive crm:P26_moved_to ?placeR . \
  104. ?placeR rdfs:label ?placeReceive } \
  105. \
  106. OPTIONAL {?send crm:P01_has_domain ?pcS . \
  107. ?pcS crm:P02_has_range ?uriSender . \
  108. ?uriSender rdfs:label ?mittente } \
  109. \
  110. OPTIONAL {?receive crm:P01_has_domain ?pcR . \
  111. ?pcR crm:P02_has_range ?uriReceiver . \
  112. ?uriReceiver rdfs:label ?destinatario } \
  113. } LIMIT 1"
  114. querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
  115. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
  116. crm:P1_is_identified_by ?segnatura_ASPO . \
  117. ?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
  118. ?segnatura crm:P2_has_type ?tipo_segnatura ; \
  119. rdfs:label ?segnatura_OVI . \
  120. ?tipo_segnatura rdfs:label \"Segnatura OVI\"} LIMIT 1"
  121. queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
  122. WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
  123. ?language crm:P3_has_note ?area ; \
  124. rdfs:label ?lingua . \
  125. ?area rdfs:label ?area_linguistica \
  126. } LIMIT 1"
  127. queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
  128. WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
  129. ?description rdfs:label ?descrizione \
  130. } LIMIT 1"
  131. queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
  132. WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
  133. ?type rdf:type crm:E55_Type; \
  134. rdfs:label ?tipologia . \
  135. } LIMIT 1"
  136. querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
  137. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
  138. ?id rdf:type crm:E42_Identifier; \
  139. crm:P2_has_type ?type ; \
  140. rdfs:label ?sigla_OVI . \
  141. ?type rdfs:label 'Sigla OVI'. \
  142. } LIMIT 1"
  143. queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
  144. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
  145. ?title rdf:type crm:E35_Title; \
  146. rdfs:label ?titolo . \
  147. } LIMIT 1"
  148. queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
  149. WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
  150. } LIMIT 1"
  151. queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
  152. WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
  153. crm:P1_is_identified_by ?edition_id . \
  154. ?edition_id rdfs:label ?edizione; \
  155. crm:P139_has_alternative_form ?ed_abbr . \
  156. ?ed_abbr rdfs:label ?edizione_abbreviata \
  157. } LIMIT 1"
  158. queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
  159. WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
  160. crm:P2_has_type ?racc_type ; \
  161. rdfs:label ?raccolta . \
  162. ?racc_type rdfs:label 'Raccolta'. \
  163. } LIMIT 1"
  164. queryToponimi = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
  165. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
  166. ?link_toponimo rdfs:label ?toponimo ; \
  167. crm:P2_has_type 'Toponimo' . \
  168. }"
  169. queryAntroponimi = prefixes + "SELECT DISTINCT * \
  170. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
  171. ?link_antroponimo rdfs:label ?antroponimo; \
  172. crm:P2_has_type 'Antroponimo'}"