lettera_query.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 ?mittente ?destinatario ?data_partenza ?data_arrivo ?luogo_partenza ?luogo_arrivo \
  53. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + "> \
  54. GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini/ex> {?subject crm:P25i_moved_by ?mov_ev .} \
  55. ?send rdfs:subClassOf ?mov_ev ; \
  56. rdf:type crm:EL2_Send_Letter ; \
  57. crm:P4_has_time-span ?time_spanA; \
  58. crm:P27_moved_from ?placeA; \
  59. crm:P01_has_domain ?sender . \
  60. \
  61. ?time_spanA rdfs:label ?data_partenza . \
  62. ?placeA rdfs:label ?luogo_partenza . \
  63. ?sender crm:P02_has_range ?mittente . \
  64. \
  65. ?receive rdfs:subClassOf ?mov_ev; \
  66. rdf:type crm:EL3_Receive_Letter ; \
  67. crm:P4_has_time-span ?time_spanB; \
  68. crm:P26_moved_to ?placeB; \
  69. crm:P01_has_domain ?receiver . \
  70. \
  71. ?time_spanB rdfs:label ?data_arrivo . \
  72. ?placeB rdfs:label ?luogo_arrivo . \
  73. ?receiver crm:P02_has_range ?destinatario . \
  74. }"
  75. querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
  76. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
  77. crm:P1_is_identified_by ?segnatura_ASPO . \
  78. ?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
  79. ?segnatura crm:P2_has_type ?tipo_segnatura; \
  80. rdfs:label ?segnatura_OVI . \
  81. ?tipo_segnatura rdfs:label \"Segnatura OVI\"}"
  82. queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
  83. WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
  84. ?language crm:P3_has_note ?area ; \
  85. rdfs:label ?lingua . \
  86. ?area rdfs:label ?area_linguistica \
  87. }"
  88. queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
  89. WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
  90. ?description rdfs:label ?descrizione \
  91. }"
  92. queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
  93. WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
  94. ?type rdf:type crm:E55_Type; \
  95. rdfs:label ?tipologia . \
  96. }"
  97. querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
  98. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
  99. ?id rdf:type crm:E42_Identifier; \
  100. crm:P2_has_type ?type ; \
  101. rdfs:label ?sigla_OVI . \
  102. ?type rdfs:label 'Sigla OVI'. \
  103. }"
  104. queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
  105. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
  106. ?title rdf:type crm:E35_Title; \
  107. rdfs:label ?titolo . \
  108. }"
  109. queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
  110. WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
  111. }"
  112. queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
  113. WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
  114. crm:P1_is_identified_by ?edition_id . \
  115. ?edition_id rdfs:label ?edizione; \
  116. crm:P139_has_alternative_form ?ed_abbr . \
  117. ?ed_abbr rdfs:label ?edizione_abbreviata \
  118. }"
  119. queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
  120. WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
  121. crm:P2_has_type ?racc_type ; \
  122. rdfs:label ?raccolta . \
  123. ?racc_type rdfs:label 'Raccolta'. \
  124. }"
  125. queryToponimi = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
  126. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
  127. ?link_toponimo rdfs:label ?toponimo ; \
  128. crm:P2_has_type 'Toponimo' . \
  129. }"
  130. queryAntroponimi = prefixes + "SELECT DISTINCT * \
  131. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
  132. ?link_antroponimo rdfs:label ?antroponimo; \
  133. crm:P2_has_type 'Antroponimo'}"