definizione dei filtri sul contesto, in progress

This commit is contained in:
cesare 2023-12-13 16:23:51 +01:00
parent 7bfeb4da0d
commit 8105f89863
1 changed files with 212 additions and 13 deletions

View File

@ -104,7 +104,8 @@ WHERE {
FILTER(LANGMATCHES(LANG(?Rappresentazione), "it"))
### condizioni
?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.
###condizioni end
@ -151,11 +152,12 @@ WHERE {
?frag olires:fragmentRegionFrom ?clfr;
olires:fragmentRegionTo ?clto.
?sentence <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> syntit:Sentence;
ecrm:P148i_is_component_of ?cantoIRI;
ecrm:P148i_is_component_of ?canto;
syntit:hasSyntacticalComponent ?cl.
?cantica ecrm:P102_has_title ?t_cantica ;
olires:hasStructuralComponent ?cantoIRI .
?cantoIRI ecrm:P102_has_title ?t_canto .
olires:hasStructuralComponent ?canto .
?canto ecrm:P102_has_title ?t_canto ;
olires:hasNumber ?num .
} LIMIT 10000
@ -409,10 +411,18 @@ function buildSQ(stquery) {
if (stquery['EsprLogica'] != null && stquery['EsprLogica'] != '' && stquery['EsprLogica'].length == 1) {
clause = stquery['EsprLogica']
filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola1']['contesto']));
//filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola1']['contesto']));
filtroContesto=getFiltroContestoJson(JSON.parse(stquery[clause[0]]['contesto']))
if (stquery[clause]['TipoClausola'] == 'Sintattico') {
parsedquery = parser.parse(ontoSparqlQuerySynt);
return buildSintacticClause(stquery[clause], parsedquery, 2)
var tempsyntquery=buildSintacticClause(stquery[clause], parsedquery, 2)
if (filtroContesto.length>0){
for (tmpc of filtroContesto){
tempsyntquery.where.splice(1, 0, tmpc)
}
}
return tempsyntquery
}
myquery = buildClause(stquery[clause], parsedquery, 2)
@ -450,14 +460,15 @@ function buildSQ(stquery) {
strval = "^" + searchtext.trim();
}
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)
//filtroContesto = getFiltroContesto(JSON.parse(stquery['Clausola0']['contesto']));
filtroContestoJson=getFiltroContestoJson(JSON.parse(stquery['Clausola0']['contesto']))
if (filtroContestoJson.length>0){
for (tmpc of filtroContestoJson){
//console.log(filtroContesto[0])
parsedquery.where.splice(1, 0, tmpc)
}
}
parsedquery.where[0].expression.args[1].value = strval;
@ -491,13 +502,44 @@ function getFiltroContesto(datiContesto) {
}
}
if(contextids.length>0)
if(contextids.length>0){
var test=buildFilterContext(contextids, canticheids)
console.log(test)
return (buildFilterContext(contextids, canticheids))
}
return []
}
function getFiltroContestoJson(datiContesto) {
var cantica = 0;
var canticheids= new Set ()
for (contestoCantica of datiContesto) {
var contextids=[]
cantica++;
for (const [index, element] of contestoCantica.entries()) {
if (element == 1){
console.log('Cantica ' + cantica + ', Canto ' + (parseInt(index) + 1));
contextids.push (parseInt(index) + 1)
}
}
if (contextids.length>0){
canticheids[cantica]=contextids
}
}
if (Object.keys(canticheids).length > 0){
console.log(JSON.stringify(canticheids))
var test=buildFilterContextJson (canticheids)
console.log(test)
return (test)
}
else
return []
}
function buildStatementClause(clause, parsedquery, whereind, theplace) {
//var tmpgroup=JSON.parse(unionop)['group']
if (clause['TipoClausola'] == "Sintattico") {
@ -688,6 +730,163 @@ function getStringFilter(filter, opzione) {
//costruzione filtri per query
//filtri contesto
function buildFilterContextJson( contextcantiche) {
var resfilters=[]
var tcontextgroup = ` {
"type": "group",
"patterns": [
{
"type": "bgp",
"triples": [
{"subject": {"termType": "Variable","value": "clocc"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/orl/current/occurrenceOf"},
"object": {"termType": "Variable","value": "cl"}},
{"subject": {"termType": "Variable","value": "clocc"},
"predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"},
"object": {"termType": "Variable","value": "fa"}},
{"subject": {"termType": "Variable","value": "clocc"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occursInRegion"},
"object": {"termType": "Variable","value": "frag"}},
{"subject": {"termType": "Variable","value": "sentence"},
"predicate": {"termType": "NamedNode","value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"},
"object": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/Sentence"}},
{"subject": {"termType": "Variable","value": "sentence"},
"predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148i_is_component_of"},
"object": {"termType": "Variable","value": "canto"}},
{"subject": {"termType": "Variable","value": "sentence"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasSyntacticalComponent"},
"object": {"termType": "Variable","value": "cl"}},
{"subject": {"termType": "Variable","value": "cl"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasClauseType"},
"object": {"termType": "Variable","value": "clatype"}},
{"subject": {"termType": "Variable","value": "cl"},
"predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P190_has_symbolic_content"},
"object": {"termType": "Variable","value": "cltext"}},
{"subject": {"termType": "Variable","value": "cl"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasClauseFunction"},
"object": {"termType": "Variable","value": "clafunction"}},
{"subject": {"termType": "Variable","value": "frag"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom"},
"object": {"termType": "Variable","value": "clfr"}},
{"subject": {"termType": "Variable","value": "frag"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionTo"},
"object": {"termType": "Variable","value": "clto"}}
]
}
]
}
`
var contextgroup = ` {
"type": "group",
"patterns": [
{
"type": "bgp",
"triples": [
{"subject": {"termType": "Variable","value": "cantica"},
"predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P102_has_title"},
"object": {"termType": "Variable","value": "t_cantica"}},
{"subject": {"termType": "Variable","value": "cantica"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/hasStructuralComponent"},
"object": {"termType": "Variable","value": "canto"}},
{"subject": {"termType": "Variable","value": "canto"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/hasNumber"},
"object": {"termType": "Variable","value": "num"}}
]
}
]
}
`
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=[]
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){
if(contextcantiche.hasOwnProperty(ky)){
console.log(`test ${ky} : ${contextcantiche[ky]}`)
var cfilter=JSON.parse(canticacontexttemplate);
cfilter['value']=canticheliteral[ky-1]
cantichecontextfilter.push(cfilter)
for (var kval in contextcantiche[ky]){
//console.log(contextcantiche[ky][kval])
var myfilter= JSON.parse(itemcontexttemplate);
myfilter['value']=contextcantiche[ky][kval].toString()
contextfilter.push(myfilter)
}
}
if (contextfilter.length>0){
filters['expression']['args'].push(contextfilter)
//resfilters.push(filters)
cgroup.patterns.splice(0,0,filters)
}
}
cantichefilters['expression']['args'].push(cantichecontextfilter)
//resfilters.push(cantichefilters)
cgroup.patterns.splice(0,0, cantichefilters)
resfilters.push(cgroup)
return resfilters
}
function buildFilterContext(contextids, contextcantiche) {
resfilters=[]
var filtercontexttemplate = `{