<docbook><section><title>VirtTipsAndTricksGuideSPARQLBIIF</title><title> Does Virtuoso support an equivalent to the SPARQL 1.1 &quot;IF&quot; operator?</title> Does Virtuoso support an equivalent to the SPARQL 1.1 &quot;IF&quot; operator?
<emphasis>Note</emphasis>: Virtuoso does now support <ulink url="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection">SPARQL 1.1</ulink> and the <ulink url="https://community.openlinksw.com/t/does-virtuoso-support-the-sparql-1-1-if-operator/1659">IF</ulink> operator.
<para>However, Virtuoso does currently support <ulink url="VOSArticleBISPARQL2">SPARQL-BI</ulink>, an extension of SPARQL 1.0 which was created before SPARQL 1.1 was ratified.
 This includes <ulink url="http://docs.openlinksw.com/virtuoso/fn_either.html">bif:either</ulink>, an equivalent built-in function (&quot;bif&quot;) which should enable the desired results to be obtained.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Using bif:either</bridgehead>
<para>For this example, a SPARQL query will be executed against the <ulink url="http://dbpedia.org/sparql">Virtuoso DBpedia SPARQL endpoint</ulink> to retrieve the decimal longitude of the &quot;NJ Devils&#39; hometown&quot; with cardinal direction (that is, East or West).</para>
<para>The bif:either function is used to set the numeric result to positive (East) or negative (West).</para>
<programlisting>PREFIX  rdfs:  &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX   dbo:  &lt;http://dbpedia.org/ontology/&gt;
PREFIX   dbp:  &lt;http://dbpedia.org/property/&gt;
SELECT  ?team 
        ( 
          ( bif:either ( ?ew = &#39;W&#39;, -1, 1 ) ) * (?d + ( ( ( ?m * 60 ) + ?s ) / 3600.0 ) ) 
          as ?v
        )
  { 
    ?team  a           dbo:HockeyTeam          . 
    ?team  rdfs:label  &#39;New Jersey Devils&#39;@en  . 
    ?team  dbp:city    ?cityname               .
    ?city  rdfs:label  ?cityname               . 
    ?city  dbp:longd   ?d                      ; 
           dbp:longm   ?m                      ; 
           dbp:longs   ?s                      ;
           dbp:longew  ?ew                     . 
  }  
</programlisting><para><ulink url="http://lod.openlinksw.com/sparql?default-graph-uri=&amp;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&amp;should-sponge=&amp;format=text%2Fhtml&amp;CXML_redir_for_subjs=121&amp;CXML_redir_for_hrefs=&amp;timeout=15000&amp;debug=on">View the results</ulink> of the query execution on the <ulink url="http://lod.openlinksw.com">LOD</ulink> instance.</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Related</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="VirtTipsAndTricksGuide">Virtuoso Tips and Tricks Collection</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/virtuoso/rdfsparql.html#rdfsparqlimplementatioptragmas">Supported SPARQL-BI &quot;define&quot; pragmas</ulink> </listitem>
<listitem><ulink url="VOSArticleBISPARQL2">SPARQL-BI</ulink> </listitem>
</itemizedlist></section></docbook>