From a2796b54fae1c1f6faf82bcb31423490f137cfe8 Mon Sep 17 00:00:00 2001 From: cesare Date: Thu, 20 Feb 2025 14:02:54 +0100 Subject: [PATCH] implementazione query --- js/browseMgr_5.1.js | 2 +- js/sparqltemplates.js | 6 +++--- js/utilsMgr_5.1.js | 34 +++++++++++++++++++--------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/js/browseMgr_5.1.js b/js/browseMgr_5.1.js index 34f8d38..88ead2e 100644 --- a/js/browseMgr_5.1.js +++ b/js/browseMgr_5.1.js @@ -1980,7 +1980,7 @@ $(document).ready(function() { } //cambiare! - for (var ip=1; ip<10; ip++){ + for (var ip=1; ip<30; ip++){ if (binding.has('pos'+ip)){ var tp=binding.get('pos'+ip).value; if (!result.has(tp)) diff --git a/js/sparqltemplates.js b/js/sparqltemplates.js index 16b858b..bafe9b8 100644 --- a/js/sparqltemplates.js +++ b/js/sparqltemplates.js @@ -411,12 +411,12 @@ const sentencetarget_morphgroup_short = `{"type": "group", {"subject": {"termType": "Variable","value": "fa"}, "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/OccursInRegion"}, "object": {"termType": "Variable", "value": "reg"}}, + {"subject": {"termType": "Variable","value": "cloccte"}, + "predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"}, + "object": {"termType": "Variable","value": "fa"}}, {"subject": {"termType": "Variable","value": "cloccte"}, "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, "object": {"termType": "Variable","value": "clg"}}, - {"subject": {"termType": "Variable","value": "cloccte"}, - "predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"}, - "object": {"termType": "Variable","value": "fa"}}, {"subject": {"termType": "Variable","value": "reg"}, "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom"}, "object": {"termType": "Variable","value": "pos"}}, diff --git a/js/utilsMgr_5.1.js b/js/utilsMgr_5.1.js index cf7a3db..8b03a5b 100644 --- a/js/utilsMgr_5.1.js +++ b/js/utilsMgr_5.1.js @@ -378,7 +378,8 @@ var unionop = `{"union": {"type": "union", "patterns":[]}, "bgp": {"type": "bgp" var idtoken = 0; - +var idtokenor = 0; +var orfilters=[] function parseJsonClause(op, tokens, nowhere) { //alert(op) var idp = -1 @@ -390,6 +391,14 @@ function parseJsonClause(op, tokens, nowhere) { if (op.trim() == 'OR') { nowhere.splice(0, 0, JSON.parse(unionop)['union']) + idtokenor=idtoken+20 + var tmpcoal=clausetarget_coalesce.replaceAll("pos","pos"+idtokenor) + clausePosCoalesceStatement = JSON.parse(tmpcoal); + tmpcoal =`{ + "termType": "Variable", + "value": "pos`+ idtokenor + `" + }` + multipleCondSpQuery['variables'].push(JSON.parse(tmpcoal)) nowhere.splice(1, 0, clausePosCoalesceStatement) idp = 0 } @@ -425,11 +434,10 @@ function buildSPQuery(guiquery) { bindConcatStatement = JSON.parse(sentencetarget_functionbind); occBindConcatStatement = JSON.parse(sentencetarget_occbind); posBindConcatStatement = JSON.parse(sentencetarget_posbind); - clausePosCoalesceStatement = JSON.parse(clausetarget_coalesce); + //clausePosCoalesceStatement = JSON.parse(clausetarget_coalesce); if (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso') { multipleCondSpQuery = spqparser.parse(clausetargetquery); - //clausePosCoalesceStatement = JSON.parse(clausetarget_coalesce); } if (theguiQ['unitaRicerca'] == 'periodo') {//Multiple Conditions @@ -449,20 +457,13 @@ function buildSPQuery(guiquery) { //here get clauses var jsonclauses = JSON.parse(clauses) idtoken = 0 + idtokenor=0 + orfilters=[] for (const ck of Object.keys(jsonclauses)) { parseJsonClause(ck, jsonclauses[ck], multipleCondSpQuery.where) - /*if (ck.trim()=='OR' && (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso')) { - multipleCondSpQuery.where.push(clausePosCoalesceStatement) - }*/ - } - /*if (theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso') { - - multipleCondSpQuery.where.push(clausePosCoalesceStatement) - - - }*/ + if (theguiQ['unitaRicerca'] == 'periodo') { multipleCondSpQuery.where.push(bindConcatStatement) multipleCondSpQuery.where.push(occBindConcatStatement) @@ -787,9 +788,12 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token, op }` if (op == 'OR') { clausePosCoalesceStatement['expression']['args'].push(JSON.parse(tmppos)) - var orfilter=clausepos_filter.replaceAll("pos_", "pos") - if (!parsedquery['where'].includes(JSON.parse(orfilter))) + var orfilter=clausepos_filter.replaceAll("pos_", "pos"+idtokenor) + if (orfilters.length==0 || !orfilters.includes(orfilter)){ parsedquery['where'].push(JSON.parse(orfilter)) + orfilters.push(orfilter) + } + } else{ parsedquery['variables'].push(JSON.parse(tmppos))