diff --git a/js/utils.js b/js/utils.js index 2094fbb..75deebc 100644 --- a/js/utils.js +++ b/js/utils.js @@ -50,6 +50,28 @@ Clausola = cla:("Clausola"Integer)(_)? {return '"'+cla[0]+cla[1]+'"';} +Integer "integer" + = _ [0-9]+ { return parseInt(text(), 10); } + +_ "whitespace"= " "* + +` +var hdnquerygrammartest=` +Expression + = head:((_)?"("(_)?("AND "/"OR ") Filtro+ (_)?(")")?){return '{"'+head[3]+'": ['+head[4]+"]}"}//{ return head}.join("").replaceAll(", ,","").replaceAll("(,","(").replaceAll(",("," (")} + / resu:Filtro {return resu[1].split().join()+' ';} +Filtro + = (_)"("?head:(("AND "/"OR "))? tail:Clausola+ (_)? closecl:(")")? + + {if (head != null) return ' {"'+head+'":['+tail+"]}"; + else if (tail!=null & tail.length <2) return ' '+tail+'' + else return ""+tail+"";} + / cl:Clausola + +Clausola + = cla:("Clausola"Integer)(_)? {return ' {"TERM": "'+cla[0]+cla[1]+'"}';} + + Integer "integer" = _ [0-9]+ { return parseInt(text(), 10); } @@ -182,8 +204,27 @@ function parseClause(op, tokens){ } } - - +} + +function parseJsonClause(op, tokens, nowhere){ + alert (op) + if (op.trim()=='OR'){ + //multipleCondSpQuery.where.push(JSON.parse(unionop)['union']); + nowhere.push(JSON.parse(unionop)['union']); + } + if (op.trim()=='AND'){ + nowhere.push(JSON.parse(unionop)['group']); + } + for (var mtoken in tokens){ + te_op=tokens[mtoken] + if ('TERM' in te_op){ + cond=theguiQ[te_op['TERM']] + multipleCondSpQuery=buildClause(cond, multipleCondSpQuery, -1) + } + if('OR ' in te_op){ + parseJsonClause('OR', te_op['OR '], nowhere) + } + } } @@ -194,7 +235,7 @@ function buildSPQuery(guiquery){ var spqparser = new SparqlParser(); multipleCondSpQuery=spqparser.parse(ontoSparqlQuery); mytestq=spqparser.parse(tq); - var parser = peg.generate(hdnquerygrammar); + var parser = peg.generate(hdnquerygrammartest); test=guiquery['EsprLogica'].join(" "); test=test.replaceAll("( ","(") test=test.replaceAll(" )",")") @@ -202,7 +243,7 @@ function buildSPQuery(guiquery){ jsonclauses=JSON.parse(clauses) for (const ck of Object.keys(jsonclauses)){ - parseClause(ck, jsonclauses[ck]) + parseJsonClause(ck, jsonclauses[ck], multipleCondSpQuery.where) }