bug fixed

This commit is contained in:
cesare 2023-12-14 13:15:25 +01:00
parent 4545f129a5
commit 5958bdbf16
1 changed files with 24 additions and 136 deletions

View File

@ -58,15 +58,6 @@ WHERE {
?reg olires:fragmentRegionFrom ?pos . ?reg olires:fragmentRegionFrom ?pos .
} }
###end ###end
### condizioni comuni
?canto ecrm:P102_has_title ?t_canto;
olires:hasNumber ?num .
?cantica ecrm:P102_has_title ?t_cantica;
olires:hasStructuralComponent ?canto.
# FILTER (?t_cantica in ("Inferno", "Purgatorio"))
# FILTER (?num IN ("12"^^xsd:short, "4"^^xsd:short ) )
### end
###condizioni sintattiche ###condizioni sintattiche
{ {
?clocc orl:occurrenceOf ?cl ; ?clocc orl:occurrenceOf ?cl ;
@ -84,6 +75,15 @@ WHERE {
?frag olires:fragmentRegionFrom ?clfr ; ?frag olires:fragmentRegionFrom ?clfr ;
olires:fragmentRegionTo ?clto . olires:fragmentRegionTo ?clto .
} }
### end
### condizioni comuni
?canto ecrm:P102_has_title ?t_canto;
olires:hasNumber ?num .
?cantica ecrm:P102_has_title ?t_cantica;
olires:hasStructuralComponent ?canto.
# FILTER (?t_cantica in ("Inferno", "Purgatorio"))
# FILTER (?num IN ("12"^^xsd:short, "4"^^xsd:short ) )
### end ### end
}` }`
@ -411,7 +411,7 @@ function buildSQ(stquery) {
if (stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) { if (stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) {
clause = stquery['EsprLogica'] clause = stquery['EsprLogica']
//filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola1']['contesto']));
filtroContesto=getFiltroContestoJson(JSON.parse(stquery[clause[0]]['contesto'])) filtroContesto=getFiltroContestoJson(JSON.parse(stquery[clause[0]]['contesto']))
if (stquery[clause]['TipoClausola'] == 'Sintattico') { if (stquery[clause]['TipoClausola'] == 'Sintattico') {
parsedquery = parser.parse(ontoSparqlQuerySynt); parsedquery = parser.parse(ontoSparqlQuerySynt);
@ -419,7 +419,7 @@ function buildSQ(stquery) {
if (filtroContesto.length>0){ if (filtroContesto.length>0){
for (tmpc of filtroContesto){ for (tmpc of filtroContesto){
tempsyntquery.where.splice(1, 0, tmpc) tempsyntquery.where.splice(0, 0, tmpc)
} }
} }
return tempsyntquery return tempsyntquery
@ -432,9 +432,9 @@ function buildSQ(stquery) {
myquery.where.splice(1, 0, tmpc) myquery.where.splice(1, 0, tmpc)
} }
//myArray[0] = myArray.splice(1, 1, myArray[0])[0]; //myArray[0] = myArray.splice(1, 1, myArray[0])[0];
let tw=myquery.where[4] //let tw=myquery.where[4]
myquery.where[4]=myquery.where[3] //myquery.where[4]=myquery.where[3]
myquery.where[3]=tw //myquery.where[3]=tw
if (stquery[clause]['queryText'].trim() == "") { if (stquery[clause]['queryText'].trim() == "") {
if (myquery.where[0].type == 'filter') if (myquery.where[0].type == 'filter')
myquery.where.splice(0, 1) myquery.where.splice(0, 1)
@ -460,7 +460,7 @@ function buildSQ(stquery) {
strval = "^" + searchtext.trim(); strval = "^" + searchtext.trim();
} }
//filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto']));
filtroContestoJson=getFiltroContestoJson(JSON.parse(stquery['Clausola0']['contesto'])) filtroContestoJson=getFiltroContestoJson(JSON.parse(stquery['Clausola0']['contesto']))
if (filtroContestoJson.length>0){ if (filtroContestoJson.length>0){
for (tmpc of filtroContestoJson){ for (tmpc of filtroContestoJson){
@ -487,30 +487,6 @@ function buildSQ(stquery) {
//Filtro Contesto //Filtro Contesto
function getFiltroContesto(datiContesto) {
var cantica = 0;
var canticheids= new Set ()
var contextids=[]
for (contestoCantica of datiContesto) {
cantica++;
for (const [index, element] of contestoCantica.entries()) {
if (element == 1){
canticheids.add(cantica)
console.log('Cantica ' + cantica + ', Canto ' + (parseInt(index) + 1));
contextids.push (parseInt(index) + 1)
}
}
}
if(contextids.length>0){
var test=buildFilterContext(contextids, canticheids)
console.log(test)
return (buildFilterContext(contextids, canticheids))
}
return []
}
function getFiltroContestoJson(datiContesto) { function getFiltroContestoJson(datiContesto) {
var cantica = 0; var cantica = 0;
@ -805,14 +781,7 @@ function buildFilterContextJson( contextcantiche) {
} }
}` }`
//var contextfilter=[]
//var cantichecontextfilter=[]
//var cgroup=JSON.parse(contextgroup)
//filters=JSON.parse(filtercontexttemplate)
//cantichefilters=JSON.parse(filtercontextcantichetemplate)
var canticheliteral=['Inferno', 'Purgatorio', 'Paradiso'] var canticheliteral=['Inferno', 'Purgatorio', 'Paradiso']
for (var ky in contextcantiche){ for (var ky in contextcantiche){
@ -848,106 +817,25 @@ function buildFilterContextJson( contextcantiche) {
} }
var uniontmp=`{"type": "union", "patterns":[]}` var uniontmp=`{"type": "union", "patterns":[]}`
var tmpres=[]
jsunion=JSON.parse(uniontmp) jsunion=JSON.parse(uniontmp)
if (resfilters.length>1){ if (resfilters.length>1){
var tmpres=[]
for (filter in resfilters){ for (filter in resfilters){
jsunion.patterns.push(resfilters[filter]) jsunion.patterns.push(resfilters[filter])
} }
tmpres.push(jsunion) tmpres.push(jsunion)
return (tmpres) return (tmpres)
} }
if (resfilters.length>0){
return resfilters
tmpres.push(resfilters[0].patterns[1])
tmpres.push(resfilters[0].patterns[0])
}
return (tmpres)
} }
function buildFilterContext(contextids, contextcantiche) {
resfilters=[]
var filtercontexttemplate = `{
"type": "filter",
"expression": {
"type": "operation",
"operator": "in",
"args": [
{
"termType": "Variable",
"value": "num"
}
]
}
}`
var filtercontextcantichetemplate = `{
"type": "filter",
"expression": {
"type": "operation",
"operator": "in",
"args": [
{
"termType": "Variable",
"value": "t_cantica"
}
]
}
}`
var itemcontexttemplate = `
{
"termType": "Literal",
"value": "na",
"language": "",
"datatype": {
"termType": "NamedNode",
"value": "http://www.w3.org/2001/XMLSchema#short"
}
}`
var canticacontexttemplate= `
{
"termType": "Literal",
"value": "na",
"language": "",
"datatype": {
"termType": "NamedNode",
"value": "http://www.w3.org/2001/XMLSchema#string"
}
}`
var contextfilter=[]
filters=JSON.parse(filtercontexttemplate)
cantichefilters=JSON.parse(filtercontextcantichetemplate)
//forEach(() => { /* ... */ } )
for (var ids of contextids){
var myfilter= JSON.parse(itemcontexttemplate);
myfilter['value']=ids.toString()
contextfilter.push(myfilter)
}
if (contextfilter.length>0){
filters['expression']['args'].push(contextfilter)
resfilters.push(filters)
}
var canticheliteral=['Inferno', 'Purgatorio', 'Paradiso']
contextfilter=[]
if(contextcantiche.size < 3){
contextcantiche.forEach((value) => {
var cfilter=JSON.parse(canticacontexttemplate);
cfilter['value']=canticheliteral[value-1]
contextfilter.push(cfilter)
})
cantichefilters['expression']['args'].push(contextfilter)
resfilters.push(cantichefilters)
}
return resfilters
}
function buildFilterStatement(target, filter, opzione) { function buildFilterStatement(target, filter, opzione) {