implementazione filtri contesto, in progress
This commit is contained in:
parent
2ceb8f477e
commit
17db3ba3fd
113
js/utils.js
113
js/utils.js
|
@ -136,9 +136,13 @@ WHERE {
|
|||
}
|
||||
###end
|
||||
### 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;
|
||||
olires:hasStructuralComponent ?canto.
|
||||
# FILTER (?t_cantica in ("Inferno", "Purgatorio"))
|
||||
# FILTER (?num IN ("12"^^xsd:short, "4"^^xsd:short ) )
|
||||
### end
|
||||
###condizioni sintattiche
|
||||
{
|
||||
|
@ -517,6 +521,13 @@ function buildSQ(stquery) {
|
|||
|
||||
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;
|
||||
if (stquery['Clausola0']['lemma_forma'] == 'lemma')
|
||||
|
@ -536,14 +547,22 @@ function buildSQ(stquery) {
|
|||
|
||||
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)
|
||||
if (element == 1){
|
||||
canticheids.add(cantica)
|
||||
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)
|
||||
}
|
||||
//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) {
|
||||
|
||||
var filtertemplate = `{
|
||||
|
|
Loading…
Reference in New Issue