Does Virtuoso support an equivalent to the SPARQL 1.1 "IF" operator?

Note: Virtuoso does now support SPARQL 1.1 and the IF operator.

However, Virtuoso does currently support SPARQL-BI, an extension of SPARQL 1.0 which was created before SPARQL 1.1 was ratified. This includes 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 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:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX   dbo:  <http://dbpedia.org/ontology/>
PREFIX   dbp:  <http://dbpedia.org/property/>
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                     . 
  }  

View the results of the query execution on the LOD instance.

Related