%META:TOPICPARENT{name="VirtTipsAndTricksGuide"}%
---+ Does Virtuoso support an equivalent to the SPARQL 1.1 "IF
" operator?
Note: Virtuoso does now support [[VirtTipsAndTricksSPARQL11FeaturesExamplesCollection][SPARQL 1.1]] and the [[https://community.openlinksw.com/t/does-virtuoso-support-the-sparql-1-1-if-operator/1659][IF]] operator.
However, Virtuoso does currently support [[VOSArticleBISPARQL2][SPARQL-BI]], an extension of SPARQL 1.0 which was created before SPARQL 1.1 was ratified. This includes [[http://docs.openlinksw.com/virtuoso/fn_either.html][bif:either]]
, an equivalent built-in function ("bif") which should enable the desired results to be obtained.
---++ Using bif:either
For this example, a SPARQL query will be executed against the [[http://dbpedia.org/sparql][Virtuoso DBpedia SPARQL endpoint]] to retrieve the decimal longitude of the "NJ Devils' hometown" with cardinal direction (that is, East or West).
The bif:either
function is used to set the numeric result to positive (East) or negative (West).
PREFIX rdfs:
PREFIX dbo:
PREFIX dbp:
SELECT ?team
(
( bif:either ( ?ew = 'W', -1, 1 ) ) * (?d + ( ( ( ?m * 60 ) + ?s ) / 3600.0 ) )
as ?v
)
{
?team a dbo:HockeyTeam .
?team rdfs:label 'New Jersey Devils'@en .
?team dbp:city ?cityname .
?city rdfs:label ?cityname .
?city dbp:longd ?d ;
dbp:longm ?m ;
dbp:longs ?s ;
dbp:longew ?ew .
}
[[http://lod.openlinksw.com/sparql?default-graph-uri=&query=%0D%0APREFIX++rdfs%3A++%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+++dbo%3A++%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2F%3E%0D%0APREFIX+++dbp%3A++%3Chttp%3A%2F%2Fdbpedia.org%2Fproperty%2F%3E%0D%0ASELECT++%3Fteam+%0D%0A++++++++%28+%0D%0A++++++++++%28+bif%3Aeither+%28+%3Few+%3D+%27W%27%2C+-1%2C+1+%29+%29+*+%28%3Fd+%2B+%28+%28+%28+%3Fm+*+60+%29+%2B+%3Fs+%29+%2F+3600.0+%29+%29+%0D%0A++++++++++as+%3Fv%0D%0A++++++++%29%0D%0A++%7B+%0D%0A++++%3Fteam++a+++++++++++dbo%3AHockeyTeam++++++++++.+%0D%0A++++%3Fteam++rdfs%3Alabel++%27New+Jersey+Devils%27%40en++.+%0D%0A++++%3Fteam++dbp%3Acity++++%3Fcityname+++++++++++++++.%0D%0A++++%3Fcity++rdfs%3Alabel++%3Fcityname+++++++++++++++.+%0D%0A++++%3Fcity++dbp%3Alongd+++%3Fd++++++++++++++++++++++%3B+%0D%0A+++++++++++dbp%3Alongm+++%3Fm++++++++++++++++++++++%3B+%0D%0A+++++++++++dbp%3Alongs+++%3Fs++++++++++++++++++++++%3B%0D%0A+++++++++++dbp%3Alongew++%3Few+++++++++++++++++++++.+%0D%0A++%7D++%0D%0A&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=15000&debug=on][View the results]] of the query execution on the [[http://lod.openlinksw.com][LOD]] instance.
---+++Related
* [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]]
* [[http://docs.openlinksw.com/virtuoso/rdfsparql.html#rdfsparqlimplementatioptragmas][Supported SPARQL-BI "define" pragmas]]
* [[VOSArticleBISPARQL2][SPARQL-BI]]