diff --git a/js/sparqltemplates.js b/js/sparqltemplates.js index bafe9b8..2fa5682 100644 --- a/js/sparqltemplates.js +++ b/js/sparqltemplates.js @@ -192,7 +192,7 @@ const clausetarget_coalesce = } }` -const clausepos_filter=` +const clausepos_gr_filter=` { "type": "filter", "expression": { @@ -201,7 +201,7 @@ const clausepos_filter=` "args": [ { "type": "operation", - "operator": ">", + "operator": ">=", "args": [ { "termType": "Variable", @@ -215,7 +215,7 @@ const clausepos_filter=` }, { "type": "operation", - "operator": "<", + "operator": "<=", "args": [ { "termType": "Variable", @@ -232,6 +232,46 @@ const clausepos_filter=` } ` +const clausepos_sy_filter=` +{ + "type": "filter", + "expression": { + "type": "operation", + "operator": "&&", + "args": [ + { + "type": "operation", + "operator": "=", + "args": [ + { + "termType": "Variable", + "value": "clto" + }, + { + "termType": "Variable", + "value": "clto_" + } + ] + }, + { + "type": "operation", + "operator": "=", + "args": [ + { + "termType": "Variable", + "value": "clfr" + }, + { + "termType": "Variable", + "value": "clfr_" + } + ] + } + ] + } +} +` + //Query per advanced search con obiettivo = 'Periodo' const sentencetargetquery = ` PREFIX ecrm: @@ -341,21 +381,34 @@ const sentencetarget_posbind = } ` + const sentencetarget_syntgroup = `{ "type": "group", "patterns": [ { "type": "bgp", "triples": [ - {"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": "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"}, + {"subject": {"termType": "Variable","value": "cl"}, "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasClauseFunction"}, - "object": {"termType": "Variable","value": "clafunction"}} + "object": {"termType": "Variable","value": "clafunction"}}, + {"subject": {"termType": "Variable","value": "claocc"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, + "object": {"termType": "Variable","value": "cl"}}, + {"subject": {"termType": "Variable","value": "claocc"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occursInRegion"}, + "object": {"termType": "Variable","value": "fragcl"}}, + {"subject": {"termType": "Variable","value": "fragcl"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom"}, + "object": {"termType": "Variable","value": "clfr"}}, + {"subject": {"termType": "Variable","value": "fragcl"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionTo"}, + "object": {"termType": "Variable","value": "clto"}} ] } ] @@ -363,6 +416,43 @@ const sentencetarget_syntgroup = `{ ` +const syntgroup_or_expr=`{ + "type": "operation", + "operator": "&&", + "args": [ + { + "type": "operation", + "operator": "=", + "args": [ + { + "termType": "Variable", + "value": "clto" + }, + { + "termType": "Variable", + "value": "clto_" + } + ] + }, + { + "type": "operation", + "operator": "=", + "args": [ + { + "termType": "Variable", + "value": "clfr" + }, + { + "termType": "Variable", + "value": "clfr_" + } + ] + } + ] + } +` + + const sentencetarget_morphgroup = `{"type": "group", "patterns": [{"type": "bgp", "triples": [ diff --git a/js/utilsMgr_5.1.js b/js/utilsMgr_5.1.js index 46753ad..15c5edf 100644 --- a/js/utilsMgr_5.1.js +++ b/js/utilsMgr_5.1.js @@ -379,7 +379,7 @@ var unionop = `{"union": {"type": "union", "patterns":[]}, "bgp": {"type": "bgp" var idtoken = 0; var idtokenor = 0; -var orfilters=[] +var orfilters = [] function parseJsonClause(op, tokens, nowhere) { //alert(op) var idp = -1 @@ -391,10 +391,10 @@ 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) + idtokenor = idtoken + 20 + var tmpcoal = clausetarget_coalesce.replaceAll("pos", "pos" + idtokenor) clausePosCoalesceStatement = JSON.parse(tmpcoal); - tmpcoal =`{ + tmpcoal = `{ "termType": "Variable", "value": "pos`+ idtokenor + `" }` @@ -457,13 +457,13 @@ function buildSPQuery(guiquery) { //here get clauses var jsonclauses = JSON.parse(clauses) idtoken = 0 - idtokenor=0 - orfilters=[] + idtokenor = 0 + orfilters = [] for (const ck of Object.keys(jsonclauses)) { parseJsonClause(ck, jsonclauses[ck], multipleCondSpQuery.where) } - + if (theguiQ['unitaRicerca'] == 'periodo') { multipleCondSpQuery.where.push(bindConcatStatement) multipleCondSpQuery.where.push(occBindConcatStatement) @@ -758,12 +758,12 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token, op tmpg = tmpg.replaceAll('"pos"', '"pos' + token + '"') tmpg = tmpg.replaceAll('"lm"', '"lm' + token + '"') tmpg = tmpg.replaceAll('"reg"', '"reg' + token + '"') - - if (op=='OR') + + if (op == 'OR') tmpg = tmpg.replaceAll('"clg"', '"clg' + token + '"') else tmpg = tmpg.replaceAll('"clg"', '"cl"') - + tmpg = tmpg.replaceAll('"cloccte"', '"cloccte' + token + '"') var tmppos = `{ "type": "operation", @@ -795,19 +795,30 @@ 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"+idtokenor) - if (orfilters.length==0 || !orfilters.includes(orfilter)){ - parsedquery['where'].push(JSON.parse(orfilter)) - orfilters.push(orfilter) + var orfilter = JSON.parse(clausepos_gr_filter.replaceAll("pos_", "pos" + idtokenor)) + + if (orfilters.length == 0 || !orfilters.includes(JSON.stringify(orfilter))) { + if (parsedquery['where'].at(-1).type == "filter") { + var texp = JSON.parse(JSON.stringify(parsedquery['where'].at(-1).expression)) + var targs = [] + targs.push(texp) + targs.push(JSON.parse(JSON.stringify(orfilter.expression))) + parsedquery['where'].at(-1).expression.operator = '||' + parsedquery['where'].at(-1).expression.args = targs + } + else { + parsedquery['where'].push(orfilter) + } + orfilters.push(JSON.stringify(orfilter)) } - + } - else{ + else { parsedquery['variables'].push(JSON.parse(tmppos)) - var andfilter=clausepos_filter.replaceAll("pos_", "pos"+ token) + var andfilter = clausepos_gr_filter.replaceAll("pos_", "pos" + token) parsedquery['where'].push(JSON.parse(andfilter)) } - + } @@ -837,7 +848,7 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token, op if (myf != '') tmpgroup.patterns.at(-1).triples.push(myf) } - + if (typeS != null && typeS != ".+" && typeS != "all") { var alltipi = Object.assign(macrotipi_sint, tipi_sint); let mymt = alltipi[typeS] @@ -862,14 +873,37 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token, op } if (theguiQ['unitaRicerca'] == 'periodo' || theguiQ['unitaRicerca'] == 'frase' || theguiQ['unitaRicerca'] == 'verso') { mytest = JSON.stringify(tmpgroup) - if (op=='OR') - mytest = tmpg.replaceAll(':"cl"', ':"cl' + token + '"') + mytest = mytest.replaceAll(':"clatype"', ':"clatype' + token + '"') mytest = mytest.replaceAll(':"clafunction"', ':"clafunction' + token + '"') mytest = mytest.replaceAll(':"cloccu"', ':"cloccu' + token + '"') + mytest = mytest.replaceAll(':"clocc"', ':"clocc' + token + '"') + mytest = mytest.replaceAll(':"fragcl"', ':"fragcl' + token + '"') + mytest = mytest.replaceAll(':"clfr"', ':"clfr' + token + '"') + mytest = mytest.replaceAll(':"clto"', ':"clto' + token + '"') mytest = mytest.replaceAll(':"fa"', ':"fa' + token + '"') mytest = mytest.replaceAll(':"form"', ':"form' + token + '"') mytest = mytest.replaceAll(':"Rappresentazione"', ':"Rappresentazione' + token + '"') + if (op == 'OR') { + mytest = mytest.replaceAll(':"cl"', ':"cl' + token + '"') + var syore = JSON.parse(clausepos_sy_filter.replaceAll(': "clfr_"', ': "clfr' + token + '"').replaceAll(': "clto_"', ': "clto' + token + '"')) + + if (orfilters.length == 0 || !orfilters.includes(JSON.stringify(syore))) { + if (parsedquery['where'].at(-1).type == "filter") { + var texp = JSON.parse(JSON.stringify(parsedquery['where'].at(-1).expression)) + var targs = [] + targs.push(texp) + targs.push(JSON.parse(JSON.stringify(syore.expression))) + parsedquery['where'].at(-1).expression.operator = '||' + parsedquery['where'].at(-1).expression.args = targs + } + else { + parsedquery['where'].push(syore) + } + orfilters.push(JSON.stringify(syore)) + } + } + var mystrb = `{ "type": "operation", "operator": "str", @@ -946,7 +980,7 @@ function buildSintacticClause(clause, parsedquery, whereind) { var functS = clause['functionSyntax']; var typeS = clause['typeSyntax0'] console.log(functS + ' ' + typeS) - if (functS != null && functS != ".+") { + if (functS != null && functS != "all") { //console.log('functS '+funzione_clausola['princ']) var myf = buildsyntClause(funzione_clausola[functS]) @@ -954,7 +988,7 @@ function buildSintacticClause(clause, parsedquery, whereind) { return parsedquery parsedquery.where.at(-1).triples.push(myf); } - if (typeS != null && typeS != ".+") { + if (typeS != null && typeS != "all") { var alltipi = Object.assign(macrotipi_sint, tipi_sint); let mymt = alltipi[typeS] if (listaMacroTipiConSubTipo.includes(mymt.split(':')[1])) {