Search code examples
if-statementswitch-statementsparqlquerying

sparql query if statement with retrieval and variable


My main need is to use something like switch cases in other programming languages.

I have a ?x g1:state (true OR false OR UNDEF) The latest is a variable incoming from a REST API and I want to perform different things based on that value

What I want to achieve is: if ?x g1:state true, bring me all the true triples. If it is false, bring me all the false triples that correspond. If the latest is undefined, bring me all the triples with whatever values. Something like this.

Bind ( if ('+test+'=true, ?x g1:state true, Bind ( if ('+test+'=false, ?x g1:state false, ?x g1:state ?y1) as ?y) as ?xf)


Solution

  • Ι bypassed this obstacle with a different approach, outside the sparql query

    var booleanvar = req.params.booleanvar
    
    if (booleanvar==='true' || booleanvar==='false'){
    
            } else {
                booleanvar= '?'+booleanvar
            }
    

    and then I just added a simple triple statement into the query

    ?x g1:state '+booleanvar+'