lettera_query.js 7.3 KB

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