diff --git a/js/utils.js b/js/utils.js index cf5220f..8c39494 100644 --- a/js/utils.js +++ b/js/utils.js @@ -58,15 +58,6 @@ WHERE { ?reg olires:fragmentRegionFrom ?pos . } ###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 { ?clocc orl:occurrenceOf ?cl ; @@ -84,6 +75,15 @@ WHERE { ?frag olires:fragmentRegionFrom ?clfr ; 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 }` @@ -411,7 +411,7 @@ function buildSQ(stquery) { if (stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) { clause = stquery['EsprLogica'] - //filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola1']['contesto'])); + filtroContesto=getFiltroContestoJson(JSON.parse(stquery[clause[0]]['contesto'])) if (stquery[clause]['TipoClausola'] == 'Sintattico') { parsedquery = parser.parse(ontoSparqlQuerySynt); @@ -419,7 +419,7 @@ function buildSQ(stquery) { if (filtroContesto.length>0){ for (tmpc of filtroContesto){ - tempsyntquery.where.splice(1, 0, tmpc) + tempsyntquery.where.splice(0, 0, tmpc) } } return tempsyntquery @@ -432,9 +432,9 @@ function buildSQ(stquery) { 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 + //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) @@ -460,7 +460,7 @@ function buildSQ(stquery) { strval = "^" + searchtext.trim(); } - //filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto'])); + filtroContestoJson=getFiltroContestoJson(JSON.parse(stquery['Clausola0']['contesto'])) if (filtroContestoJson.length>0){ for (tmpc of filtroContestoJson){ @@ -487,30 +487,6 @@ function buildSQ(stquery) { //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) { 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'] for (var ky in contextcantiche){ @@ -848,106 +817,25 @@ function buildFilterContextJson( contextcantiche) { } var uniontmp=`{"type": "union", "patterns":[]}` + var tmpres=[] jsunion=JSON.parse(uniontmp) if (resfilters.length>1){ - var tmpres=[] + for (filter in resfilters){ jsunion.patterns.push(resfilters[filter]) } tmpres.push(jsunion) return (tmpres) } - - return resfilters + if (resfilters.length>0){ + + 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) {