lettera_query.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 ?mittente ?destinatario ?data_partenza ?data_arrivo ?luogo_partenza ?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 ?placeA; \
  64. crm:P01_has_domain ?sender . \
  65. \
  66. ?time_spanA rdfs:label ?data_partenza . \
  67. ?placeA rdfs:label ?luogo_partenza . \
  68. ?sender 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 ?placeB; \
  74. crm:P01_has_domain ?receiver . \
  75. \
  76. ?time_spanB rdfs:label ?data_arrivo . \
  77. ?placeB rdfs:label ?luogo_arrivo . \
  78. ?receiver crm:P02_has_range ?destinatario . \
  79. }"
  80. querySegnatura = prefixes + "SELECT DISTINCT ?segnatura_OVI \
  81. WHERE {?subject crm:P128_carries <" + thisUrlParams.link + ">; \
  82. crm:P1_is_identified_by ?segnatura_ASPO . \
  83. ?segnatura_ASPO crm:P139_has_alternative_form ?segnatura . \
  84. ?segnatura crm:P2_has_type ?tipo_segnatura; \
  85. rdfs:label ?segnatura_OVI . \
  86. ?tipo_segnatura rdfs:label \"Segnatura OVI\"}"
  87. queryAreaLinguistica = prefixes + " SELECT DISTINCT ?lingua ?area_linguistica \
  88. WHERE {<" + thisUrlParams.link + "> crm:P72_has_language ?language . \
  89. ?language crm:P3_has_note ?area ; \
  90. rdfs:label ?lingua . \
  91. ?area rdfs:label ?area_linguistica \
  92. }"
  93. queryDescrizione = prefixes + " SELECT DISTINCT ?descrizione \
  94. WHERE {<" + thisUrlParams.link + "> crm:P3_has_note ?description . \
  95. ?description rdfs:label ?descrizione \
  96. }"
  97. queryTipo = prefixes + " SELECT DISTINCT ?tipologia \
  98. WHERE {<" + thisUrlParams.link + "> crm:P2_has_type ?type . \
  99. ?type rdf:type crm:E55_Type; \
  100. rdfs:label ?tipologia . \
  101. }"
  102. querySiglaOVI = prefixes + " SELECT DISTINCT ?sigla_OVI \
  103. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?id . \
  104. ?id rdf:type crm:E42_Identifier; \
  105. crm:P2_has_type ?type ; \
  106. rdfs:label ?sigla_OVI . \
  107. ?type rdfs:label 'Sigla OVI'. \
  108. }"
  109. queryTitolo = prefixes + " SELECT DISTINCT ?titolo \
  110. WHERE {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?title . \
  111. ?title rdf:type crm:E35_Title; \
  112. rdfs:label ?titolo . \
  113. }"
  114. queryTestoLemmatizzato = prefixes + " SELECT DISTINCT ?testo_lemmatizzato \
  115. WHERE {<" + thisUrlParams.link + "> crm:P190_has_symbolic_content ?testo_lemmatizzato . \
  116. }"
  117. queryEdizione = prefixes + " SELECT DISTINCT ?edizione ?edizione_abbreviata \
  118. WHERE {?edition crm:P70_documents <" + thisUrlParams.link + "> ; \
  119. crm:P1_is_identified_by ?edition_id . \
  120. ?edition_id rdfs:label ?edizione; \
  121. crm:P139_has_alternative_form ?ed_abbr . \
  122. ?ed_abbr rdfs:label ?edizione_abbreviata \
  123. }"
  124. queryRaccolta = prefixes + " SELECT DISTINCT ?raccolta \
  125. WHERE {?racc crm:P148_has_component <" + thisUrlParams.link + "> ; \
  126. crm:P2_has_type ?racc_type ; \
  127. rdfs:label ?raccolta . \
  128. ?racc_type rdfs:label 'Raccolta'. \
  129. }"
  130. queryToponimi = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
  131. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
  132. ?link_toponimo rdfs:label ?toponimo ; \
  133. crm:P2_has_type 'Toponimo' . \
  134. }"
  135. queryAntroponimi = prefixes + "SELECT DISTINCT * \
  136. WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
  137. ?link_antroponimo rdfs:label ?antroponimo; \
  138. crm:P2_has_type 'Antroponimo'}"