costruzione query, in progress

This commit is contained in:
cesare 2022-10-10 17:01:29 +02:00
parent 1945cb0648
commit cd42e5c0ba
1 changed files with 45 additions and 4 deletions

View File

@ -50,6 +50,28 @@ Clausola
= cla:("Clausola"Integer)(_)? {return '"'+cla[0]+cla[1]+'"';} = 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" Integer "integer"
= _ [0-9]+ { return parseInt(text(), 10); } = _ [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(); var spqparser = new SparqlParser();
multipleCondSpQuery=spqparser.parse(ontoSparqlQuery); multipleCondSpQuery=spqparser.parse(ontoSparqlQuery);
mytestq=spqparser.parse(tq); mytestq=spqparser.parse(tq);
var parser = peg.generate(hdnquerygrammar); var parser = peg.generate(hdnquerygrammartest);
test=guiquery['EsprLogica'].join(" "); test=guiquery['EsprLogica'].join(" ");
test=test.replaceAll("( ","(") test=test.replaceAll("( ","(")
test=test.replaceAll(" )",")") test=test.replaceAll(" )",")")
@ -202,7 +243,7 @@ function buildSPQuery(guiquery){
jsonclauses=JSON.parse(clauses) jsonclauses=JSON.parse(clauses)
for (const ck of Object.keys(jsonclauses)){ for (const ck of Object.keys(jsonclauses)){
parseClause(ck, jsonclauses[ck]) parseJsonClause(ck, jsonclauses[ck], multipleCondSpQuery.where)
} }