implementazione filtri contesto, in progress

This commit is contained in:
cesare 2023-03-14 11:49:06 +01:00
parent 2ceb8f477e
commit 17db3ba3fd
1 changed files with 150 additions and 41 deletions

View File

@ -136,9 +136,13 @@ WHERE {
} }
###end ###end
### condizioni comuni ### condizioni comuni
?canto ecrm:P102_has_title ?t_canto.
?canto ecrm:P102_has_title ?t_canto;
olires:hasNumber ?num .
?cantica ecrm:P102_has_title ?t_cantica; ?cantica ecrm:P102_has_title ?t_cantica;
olires:hasStructuralComponent ?canto. olires:hasStructuralComponent ?canto.
# FILTER (?t_cantica in ("Inferno", "Purgatorio"))
# FILTER (?num IN ("12"^^xsd:short, "4"^^xsd:short ) )
### end ### end
###condizioni sintattiche ###condizioni sintattiche
{ {
@ -517,6 +521,13 @@ function buildSQ(stquery) {
var filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto'])); var filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto']));
if (filtroContesto.length>0){
for (tmpc of filtroContesto){
console.log(filtroContesto[0])
parsedquery.where.splice(4, 0, tmpc)
}
}
parsedquery.where[0].expression.args[1].value = strval; parsedquery.where[0].expression.args[1].value = strval;
if (stquery['Clausola0']['lemma_forma'] == 'lemma') if (stquery['Clausola0']['lemma_forma'] == 'lemma')
@ -536,14 +547,22 @@ function buildSQ(stquery) {
function getFiltroContesto(datiContesto) { function getFiltroContesto(datiContesto) {
var cantica = 0; var cantica = 0;
var canticheids= new Set ()
var contextids=[]
for (contestoCantica of datiContesto) { for (contestoCantica of datiContesto) {
cantica++; cantica++;
for (const [index, element] of contestoCantica.entries()) { for (const [index, element] of contestoCantica.entries()) {
if(element==1) if (element == 1){
canticheids.add(cantica)
console.log('Cantica ' + cantica + ', Canto ' + (parseInt(index) + 1)); console.log('Cantica ' + cantica + ', Canto ' + (parseInt(index) + 1));
contextids.push (parseInt(index) + 1)
}
} }
} }
if(contextids.length>0)
return (buildFilterContext(contextids, canticheids))
return []
} }
@ -735,6 +754,96 @@ function getStringFilter(filter, opzione) {
}; };
return (strval) return (strval)
} }
//costruzione filtri per query
//filtri contesto
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) {
var filtertemplate = `{ var filtertemplate = `{