|
@@ -1,5 +1,5 @@
|
|
|
|
|
|
-// Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
|
|
|
+// Recupero i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
|
|
|
thisUrlParams = {};
|
|
|
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
|
|
|
thisUrlParams[key] = value;
|
|
@@ -8,42 +8,45 @@ console.log('URL get params: ', thisUrlParams);
|
|
|
|
|
|
|
|
|
// Funzioni per eseguire le queries
|
|
|
+
|
|
|
function prepareQueryURL(query){
|
|
|
sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
|
|
|
sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
|
|
|
return sparqlEndpoint + sparqlUrlParams;
|
|
|
}
|
|
|
-function doJsonQuery(query){
|
|
|
+
|
|
|
+// Esegue una query sull'endpoint SPARQL il cui testo completo deve essere fornito nel parametro-stringa 'query'
|
|
|
+// Restituisce una lista di oggetti json nel formato di Virtuoso
|
|
|
+// Il parametro opzionale 'isUnique', se messo a 'true' controlla che ci sia un unico risultato (un array di
|
|
|
+// lunghezza 1) e se non è così restituisce un errore.
|
|
|
+async function doJsonQuery(query, isUnique = false){
|
|
|
|
|
|
queryURL = prepareQueryURL(query);
|
|
|
|
|
|
- response = $.ajax({//OGGETTO
|
|
|
+ response = await $.ajax({//OGGETTO
|
|
|
|
|
|
url: queryURL,
|
|
|
dataType: "json",
|
|
|
success: function (data){},
|
|
|
- error: function (e) {}
|
|
|
+ error: function (e) {
|
|
|
+ console.log("Exception in query:", e);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
- return response;
|
|
|
+ let out = response['results']['bindings'];
|
|
|
+ if(!isUnique) return out;
|
|
|
+ if(!out.length) throw "ERROR: Letter not found";
|
|
|
+ if(out.length>1) throw "ERROR: ambiguity in search -- multiple letters matching search parameters";
|
|
|
+ return out[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
+// Nuova funzione per l'NLP
|
|
|
function loadPageNLP()
|
|
|
{
|
|
|
window.location="nlp.html?link=" + thisUrlParams.link;
|
|
|
}
|
|
|
|
|
|
-// Funzioni per raccattare + stringhificare l'output
|
|
|
-queryStringOutput = "";
|
|
|
-function stringifyResponse(val){
|
|
|
- resultArray = val['results']['bindings'];
|
|
|
- out = "";
|
|
|
- for(i = 0; i < resultArray.length; i++){
|
|
|
- out = out + JSON.stringify(resultArray[i])
|
|
|
- }
|
|
|
- queryStringOutput = (queryStringOutput + out).replace("}{",",");
|
|
|
-}
|
|
|
|
|
|
////////////////////
|
|
|
// TESTI DELLE QUERY
|
|
@@ -139,3 +142,14 @@ crm:P2_has_type ?racc_type ; \
|
|
|
rdfs:label ?raccolta . \
|
|
|
?racc_type rdfs:label 'Raccolta'. \
|
|
|
}"
|
|
|
+
|
|
|
+queryToponimi = prefixes + "SELECT DISTINCT ?link_toponimo ?toponimo \
|
|
|
+WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_toponimo . \
|
|
|
+?link_toponimo rdfs:label ?toponimo ; \
|
|
|
+crm:P2_has_type 'Toponimo' . \
|
|
|
+}"
|
|
|
+
|
|
|
+queryAntroponimi = prefixes + "SELECT DISTINCT * \
|
|
|
+WHERE {<" + thisUrlParams.link + "> crm:P67_refers_to ?link_antroponimo . \
|
|
|
+?link_antroponimo rdfs:label ?antroponimo; \
|
|
|
+crm:P2_has_type 'Antroponimo'}"
|