selezione contesto in query avanzate, in progress

This commit is contained in:
cesare 2023-12-12 11:11:23 +01:00
parent 0c4fa38a68
commit a09fdd8ece
1 changed files with 23 additions and 97 deletions

View File

@ -1,81 +1,4 @@
tqvpvs = `
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX olires: <https://dantenetwork.it/ontology/olires/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIx comm: <https://dantenetwork.it/data/commedia/>
SELECT (?form AS ?IRIForma) (?Rappresentazione AS ?Forma) (?lm AS ?Lemma) (?textver AS ?Verso) (?NumVerso AS ?NumeroVerso) (?t_canto AS ?Canto) (?t_cantica AS ?Cantica)
(?textver1 AS ?VersoPrec) (?textver2 AS ?VersoSucc)
WHERE {
?fa orl:occurrenceOf ?form.
?ver ecrm:P190_Has_Symbolic_Content ?textver;
olires:hasNumber ?NumVerso;
olires:hasStructuralComponent ?fa.
?canto ecrm:P102_has_title ?t_canto;
olires:hasStructuralComponent ?ver.
?cantica ecrm:P102_has_title ?t_cantica;
olires:hasStructuralComponent ?canto.
?form ontolex:writtenRep ?Rappresentazione.
?lent ontolex:lexicalForm ?form;
ontolex:canonicalForm ?cf.
?cf ontolex:writtenRep ?lm.
FILTER(REGEX(?Rappresentazione, "^stelle$", "i")) .
FILTER(LANGMATCHES(LANG(?Rappresentazione), "it")) .
#BIND(IF((?NumVerso-1) >0,(xsd:short(?NumVerso-1)), (xsd:short(1))) as ?NumVerso1)
BIND(xsd:short(?NumVerso-1) as ?NumVerso1)
BIND(xsd:short(?NumVerso+1) as ?NumVerso2)
Optional{
?ver1 ecrm:P190_Has_Symbolic_Content ?textver1;
olires:hasNumber ?NumVerso1.
?canto olires:hasStructuralComponent ?ver1 .
}
OPTIONAL {
?ver2 ecrm:P190_Has_Symbolic_Content ?textver2;
olires:hasNumber ?NumVerso2.
?canto olires:hasStructuralComponent ?ver2 .
}
} ORDER BY (?canto) (?cantica)
LIMIT 20
`
// Per restituire i versi di una cantica
var qVersiCantica = `
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX olires: <https://dantenetwork.it/ontology/olires/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX text: <http://jena.apache.org/text#>
PREFIx hdn: <https://dantenetwork.it/data/commedia/>
SELECT (?textver AS ?Verso) (?NumVerso AS ?NumeroVerso) (?t_canto AS ?Canto) (?t_cantica AS ?Cantica)
?textform ?pos
WHERE {
?cantica ecrm:P102_has_title ?t_cantica ;
olires:hasStructuralComponent ?canto.
?canto ecrm:P102_has_title ?t_canto;
olires:hasStructuralComponent ?ver.
?ver ecrm:P190_Has_Symbolic_Content ?textver;
olires:hasNumber ?NumVerso;
olires:hasStructuralComponent ?fa.
# olires:OccursInRegion ?reg .
?fa orl:occurrenceOf ?form.
?fa olires:OccursInRegion ?regfo .
?regfo olires:fragmentRegionFrom ?pos .
?form ontolex:writtenRep ?textform.
# ?reg olires:fragmentRegionFrom ?from;
# olires:fragmentRegionTo ?to .
FILTER regex(?t_cantica,"Inferno","i") .
}`
var hdnquerygrammar = `
Expression
= head:((_)?"("(_)?("AND "/"OR ") Filtro+ (_)?(")")?){return '{"'+head[3]+'": ['+head[4]+"]}"}//{ return head}.join("").replaceAll(", ,","").replaceAll("(,","(").replaceAll(",("," (")}
@ -238,7 +161,7 @@ WHERE {
`
//colori
//colori per frasi sintattiche
@ -353,24 +276,12 @@ function getFormaContext(formaid, numversi = 3) {
}
//restituisce la query per ottenere tutti i versi di una cantica: NON USATA: RIMUOVERE
/*
function versiCantica(cantica) {
var SparqlParser = sparqljs.Parser;
var parser = new SparqlParser();
parsedqVersiCantica = parser.parse(qVersiCantica);
parsedqVersiCantica.where[1].expression.args[1].value = cantica;
return (parsedqVersiCantica)
}
*/
// the basic initial query is parsed RIMUOVERE
// the basic initial query is parsed
function gimmespq() {
var SparqlParser = sparqljs.Parser;
var parser = new SparqlParser();
return parser.parse(ontoSparqlQuery);
//return parser.parse(tqvpvs);
}
@ -477,18 +388,16 @@ function buildSPQuery(guiquery) {
}
//BUILD THE QUERY!
function buildSQ(stquery) {
var filtroContesto;
stringInSparql = false;
var SparqlParser = sparqljs.Parser;
var parser = new SparqlParser();
//Prendo la query SPARQL template
var parsedquery = parser.parse(ontoSparqlQuery);
//const parsedquery = parser.parse(tqvpvs);
console.log(stquery)
@ -500,14 +409,31 @@ function buildSQ(stquery) {
if (stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) {
clause = stquery['EsprLogica']
filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola1']['contesto']));
if (stquery[clause]['TipoClausola'] == 'Sintattico') {
parsedquery = parser.parse(ontoSparqlQuerySynt);
return buildSintacticClause(stquery[clause], parsedquery, 2)
}
myquery = buildClause(stquery[clause], parsedquery, 2)
return (myquery)
if (filtroContesto.length>0){
for (tmpc of filtroContesto){
console.log(filtroContesto[0])
myquery.where.splice(1, 0, tmpc)
}
//myArray[0] = myArray.splice(1, 1, myArray[0])[0];
let tw=myquery.where[4]
myquery.where[4]=myquery.where[3]
myquery.where[3]=tw
if (stquery[clause]['queryText'].trim() == "") {
if (myquery.where[0].type == 'filter')
myquery.where.splice(0, 1)
}
}
return (myquery)
}
//Simple query
if (stquery['Clausola0']['queryText'] != "") {
searchtext = stquery['Clausola0']['queryText']
strval = searchtext
@ -524,7 +450,7 @@ function buildSQ(stquery) {
strval = "^" + searchtext.trim();
}
var filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto']));
filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto']));
if (filtroContesto.length>0){
for (tmpc of filtroContesto){