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
### 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
{
@ -243,12 +247,12 @@ var colorssp = d3.scaleQuantize()
.range(["#1f78b4", "#a6cee3", "#b2df8a", "#33a02c", "#fb9a99", "#e31a1c", "#fdbf6f", "#ff7f00",
"#cab2d6", "#6a3d9a", "#ffff99", "#b15928", "#F46D43",
"#D53E4F", "#9E0142", "#e377c2", "#7f7f7f", "#bcbd22"]);
/*.range(["#3288bd", "#66c2a5", "#e41a1c", "#4daf4a", "#984ea3", "#d53e4f", "#f46d43", "#ABDDA4",
"#E6F598", "#FFFFBF", "#FEE08B", "#FDAE61", "#F46D43",
"#D53E4F", "#9E0142", "#e377c2", "#7f7f7f", "#bcbd22"]);*/
/*.range(["#3288bd", "#66c2a5", "#e41a1c", "#4daf4a", "#984ea3", "#d53e4f", "#f46d43", "#ABDDA4",
"#E6F598", "#FFFFBF", "#FEE08B", "#FDAE61", "#F46D43",
"#D53E4F", "#9E0142", "#e377c2", "#7f7f7f", "#bcbd22"]);*/
const mapsynttypestopalette = {
"Ma": 0, "SubI": 1, "SubII": 3, "SubIII": 4, "Co": 5, "Co0":2,
"Ma": 0, "SubI": 1, "SubII": 3, "SubIII": 4, "Co": 5, "Co0": 2,
"CoI": 9, "CoII": 10, "SubIV": 5, "SubV": 6, "ParentethicalClause": 17,
"CoIII": 11, "ParentheticalCo": 14, "PseudoCo": 16, "SubVI": 7, "CoIV": 12,
"CoV": 13, "ParentheticalCoI": 15, "SubVII": 8
@ -270,64 +274,64 @@ syntitprefix = 'https://dantenetwork.it/ontology/syntit/current/'
function getFormaContext(formaid, numversi=3) {
function getFormaContext(formaid, numversi = 3) {
var context = []
var cantica = 1;
var listaforme = formeprima;
var minpos = 0;
var limitv = Math.max((numversi),3)
var limitv = Math.max((numversi), 3)
var maxpos = 0;
var offset=0;
if (parseInt(formaid) < 33373) {
offset=parseInt(formaid)
var offset = 0;
if (parseInt(formaid) < 33373) {
offset = parseInt(formaid)
}
if (parseInt(formaid) > 33373 && parseInt(formaid) < 66588) {
listaforme = formeseconda;
cantica = 2;
offset=parseInt(formaid)-33374
offset = parseInt(formaid) - 33374
}
if (parseInt(formaid) > 66587 && parseInt(formaid) < 99314) {
listaforme = formeterza;
cantica = 3;
offset=parseInt(formaid)-66588
offset = parseInt(formaid) - 66588
}
if (parseInt(formaid) > 99314 || parseInt(formaid) < 0){
if (parseInt(formaid) > 99314 || parseInt(formaid) < 0) {
return [];
}
maxpos = listaforme.length - 1
var pos = 0
var startindex=Math.max(0, (offset-25))
var startindex = Math.max(0, (offset - 25))
//console.log('Forma id: '+formaid+' startindex '+ startindex+' offset '+offset+' ('+cantica+')')
for (i=startindex; i<listaforme.length; i++){
var tmpos=listaforme[i].split('_')[2]
if (tmpos==formaid){
pos=i;
for (i = startindex; i < listaforme.length; i++) {
var tmpos = listaforme[i].split('_')[2]
if (tmpos == formaid) {
pos = i;
//console.log(' in pos: '+pos)
break;
}
}
/*for (const [index, element] of listaforme.entries()) {
if(element.split('_')[2]==formaid){
pos=index;
break;
}
}
*/
}
*/
var item = listaforme[pos].split('_');
var numverso = item[3]
var spannum=(11*limitv)
var spannum = (11 * limitv)
var contextinf = Math.max(minpos, parseInt(pos) - spannum)
var contextsup = Math.min(maxpos, parseInt(pos) + spannum)
for (j = contextinf; j < contextsup + 1; j++) {
@ -514,10 +518,17 @@ function buildSQ(stquery) {
if (stquery['Clausola0']['opzioni_testo'] == 'prefisso') {
strval = "^" + searchtext.trim();
}
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;
if (stquery['Clausola0']['lemma_forma'] == 'lemma')
parsedquery.where[0].expression.args[0].value = "lm";
@ -534,18 +545,26 @@ function buildSQ(stquery) {
//Filtro Contesto
function getFiltroContesto(datiContesto){
var cantica=0;
for (contestoCantica of datiContesto){
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)
console.log('Cantica '+cantica+', Canto '+(parseInt(index)+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 []
}
function buildStatementClause(clause, parsedquery, whereind, theplace) {
@ -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 = `{