<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE spec SYSTEM "xmlspec.dtd" [
  <!ENTITY base.uri "http://www.w3.org/TR/">
  <!ENTITY maturity.level "WD">
  <!ENTITY doc.shortname "sparql11-query">
  <!ENTITY draft.year "2012">
  <!ENTITY draft.month.name "October">
  <!ENTITY draft.month "05">
  <!ENTITY draft.day "99">
  <!ENTITY iso6.doc.date "&draft.year;&draft.month;&draft.day;">
  <!ENTITY doc.ident "&maturity.level;-&doc.shortname;-&iso6.doc.date;">
  <!ENTITY this.version "&base.uri;&draft.year;/&doc.ident;">
  <!ENTITY xml.version "&doc.ident;.xml">
  <!ENTITY review.version "&doc.ident;-review.html">
  <!ENTITY pdf.version "&doc.ident;.pdf">
  <!ENTITY errataloc "http://www.w3.org/2009/sparql/docs/query-1.1/query-errata">
  <!ENTITY preverrataloc "http://www.w3.org/2001/sw/DataAccess/query-errata">
  <!ENTITY translationloc "http://www.w3.org/2003/03/Translations/byTechnology?technology=&doc.shortname;">
  <!ENTITY impreploc "">
  <!ENTITY versionOfSPARQL "1.1">
  <!ENTITY nbsp "&#160;">
  <!ENTITY ndash "&#x2013;">
  <!ENTITY mdash "&#x2014;">
  <!ENTITY eacute "&#xe9;">
  <!ENTITY aacute "&#xe1;">
  <!ENTITY udotdot "&#xfc;">
  <!ENTITY mu "&#x3bc;">
  <!ENTITY Psi "&#x3a8;">
  <!ENTITY psi "&#968;">
  <!ENTITY Omega "&#x3a9;">
  <!ENTITY prime "&#x2032;">
  <!ENTITY rarr "&#8594;">
  <!ENTITY forall "&#8704;">
  <!ENTITY exists "&#8707;">
  <!-- Union -->
  <!ENTITY cup "&#8746;">
  <!-- Intersection -->
  <!ENTITY cap "&#8745;">
  <!ENTITY member "&#8712;">
  <!ENTITY notmember "&#8713;">
  <!-- Empty set -->
  <!ENTITY empty "&#8709;">
  <!ENTITY magicents "<code>amp</code>,
<code>lt</code>,
<code>gt</code>,
<code>apos</code>,
<code>quot</code>">
  <!ENTITY may "may">
  <!ENTITY MAY "<rfc2119>MAY</rfc2119>">
  <!ENTITY SHOULD "<rfc2119>SHOULD</rfc2119>">
  <!ENTITY MUST "<rfc2119>MUST</rfc2119>">
  <!ENTITY % local.common.att "xml:lang    CDATA  #IMPLIED">
]>
<?xml-stylesheet type="text/xsl" href="REC-xml.xsl"?>

<!-- Process: 
    Set the date above correctly.
    Look for the string "publication-process" (3 places, one immediately next)
    1/ set the w3c-doctype
    2/ set the link to the previous version
    3/ comment out the working draft paragraph
 -->
 
<!-- publication-process 
    Set w3c-doctype="wd" etc for publication ; "ed" or "review" for editor's working draft 
-->

<spec w3c-doctype="ed" xml:lang="en">
  <header>
    <title>SPARQL &versionOfSPARQL; Query Language</title>
    <!--<w3c-doctype>Editors' Working Draft</w3c-doctype>-->
    <w3c-doctype>W3C Working Draft</w3c-doctype>
    <w3c-designation>&doc.ident;</w3c-designation>
    <pubdate>
      <day>&draft.day;</day>
      <month>&draft.month.name;</month>
      <year>&draft.year;</year>
    </pubdate>
    <publoc>
      <loc href="&this.version;/">&this.version;/</loc>
    </publoc>
    <!--
    <altlocs>
      <!- -loc href="&xml.version;">XML</loc- ->
      <!- -loc href="&pdf.version;">PDF</loc- ->
      <loc href="&review.version;">XHTML with color-coded revision indicators</loc>
    </altlocs>
    -->
    <latestloc>
      <loc href="http://www.w3.org/TR/&doc.shortname;/">http://www.w3.org/TR/&doc.shortname;/</loc>
    </latestloc>
    <prevlocs>
      <!--  publication-process
           Make this a link to the previous version -->
      <!--
      <loc href="http://www.w3.org/TR/2010/WD-sparql11-query-YYYYMMMDD">http://www.w3.org/TR/2010/WD-sparql11-query-YYYYMMMDD/</loc>
      -->
      <loc href="http://www.w3.org/TR/WD-sparql11-query-20120724/">http://www.w3.org/TR/WD-sparql11-query-20120724/</loc>
    </prevlocs>
    <authlist>
      <author role="Editor">
        <name>Steve Harris</name>
        <affiliation>Garlik, a part of Experian</affiliation>
      </author>
      <author role="Editor">
        <name>Andy Seaborne</name>
        <affiliation>The Apache Software Foundation</affiliation>
      </author>
      <author role="PreviousEditor">
        <name>Eric Prud'hommeaux</name>
        <affiliation>W3C</affiliation>
      </author>
    </authlist>
    <!-- errataloc href="&errataloc;"/ -->
    <preverrataloc href="&preverrataloc;"/>
    <translationloc href="&translationloc;"/>
    <abstract>
      <p>
  RDF is a directed, labeled graph data format for representing information 
  in the Web. This specification defines the syntax and semantics of the 
  SPARQL query language for RDF. SPARQL can be used to express queries 
  across diverse data sources, whether the data is stored natively as RDF or 
  viewed as RDF via middleware. SPARQL contains capabilities for querying 
  required and optional graph patterns along with their conjunctions and 
  disjunctions. SPARQL also supports aggregation, subqueries, negation,
  creating values by expressions, extensible value testing, and constraining queries
  by source RDF graph. The results of SPARQL queries can be result
  sets or RDF graphs.
       </p>
    </abstract>
    <status>

      <p><em>This section describes the status of this document at the
      time of its publication. Other documents may supersede this
      document. A list of current W3C publications and the latest
      revision of this technical report can be found in the <a href=
      "http://www.w3.org/TR/">W3C technical reports index</a> at
      http://www.w3.org/TR/.</em></p>

      <!-- Working Draft text -->
      <p>Publication as a Working Draft does not imply endorsement by the W3C Membership. 
      This is a draft document and may be updated, replaced or obsoleted by other documents at any time. 
      It is inappropriate to cite this document as other than work in progress.</p>

      <!-- publication-process : comment out this paragraph -->
      <p>This is an <a href="http://www.w3.org/2005/10/Process-20051014/tr.html#RecsWD">Editors' Working Draft</a>.</p>

      <p>The set of SPARQL documents comprises:</p>
      <ul>
	<li>SPARQL 1.1 Query (this document)</li>
	<li><a href="http://www.w3.org/TR/sparql11-update/">SPARQL 1.1 Update</a></li>
	<li><a href="http://www.w3.org/TR/sparql11-protocol/">SPARQL 1.1 Protocol for RDF</a></li>
	<li><a href="http://www.w3.org/TR/sparql11-http-rdf-update/">SPARQL 1.1 Graph Store HTTP Protocol</a></li>
	<li><a href="http://www.w3.org/TR/sparql11-entailment/">SPARQL 1.1 Entailment Regimes</a></li>
	<li><a href="http://www.w3.org/TR/sparql11-service-description/">SPARQL 1.1 Service Description</a></li>
	<li><a href="http://www.w3.org/TR/sparql11-federated-query/">SPARQL 1.1 Federated Query</a></li>
	<li><a href="http://www.w3.org/2009/sparql/docs/tests/">SPARQL 1.1 Conformance Tests</a></li>
	<li><a href="http://www.w3.org/TR//sparql11-results-json/">SPARQL 1.1 Query Results JSON Format</a></li>
	<li><a href="http://www.w3.org/TR/sparql11-results-csv-tsv/">SPARQL 1.1 Query Results CSV and TSV Formats</a></li>
	<li><a href= "http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query Results XML Format</a></li>
      </ul>

       <!-- Working Draft text -->
      <p>The design of the features presented here is work-in-progress and does not represent
      the final decisions of the working group.  Implementers and application writers should
      not assume that the designs in this document will not change.</p>

      <p>Comments on this document should be sent to <a href="mailto:public-rdf-dawg-comments@w3.org">public-rdf-dawg-comments@w3.org</a>, a mailing list with a <a href="http://lists.w3.org/Archives/Public/public-rdf-dawg-comments">public archive</a>. Questions and comments about SPARQL that are not related to this specification, including extensions and features, can be discussed on the mailing list <a href="mailto:public-sparql-dev@w3.org">public-sparql-dev@w3.org</a>, (<a href="http://lists.w3.org/Archives/Public/public-sparql-dev">public archive</a>).</p>

      <p>This document was produced by the <a href="http://www.w3.org/2001/sw/DataAccess/">SPARQL Working Group</a>, which is part of the <a href="http://www.w3.org/2001/sw/Activity">W3C Semantic Web Activity</a>.</p>

      <p>This document was produced by a group operating under the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>. W3C maintains a <a rel="disclosure" href="http://www.w3.org/2004/01/pp-impl/35463/status">public list of any patent disclosures</a> made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.</p>
    </status>
    <pubstmt>
      <!-- Unused -->
      <p>Copyright © 2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.</p>
    </pubstmt>
    <sourcedesc>
      <p>Created in electronic form.</p>
    </sourcedesc>
    <langusage>
      <language id="EN">English</language>
      <language id="ebnf">Extended Backus-Naur Form (formal grammar)</language>
    </langusage>
    <revisiondesc>
      <p role="cvsid">$Id: rq25.xml,v 1.407 2013/03/20 17:50:09 sandro Exp $</p>
    </revisiondesc>
  </header>
  <body>
    <div1 id="introduction">
      <head>Introduction</head>

<p>
 RDF is a directed, labeled graph data format for representing information 
 in the Web. RDF is often used to represent, among other things, personal 
 information, social networks, metadata about digital artifacts, as well as 
 to provide a means of integration over disparate sources of information. 
 This specification defines the syntax and semantics of the SPARQL query 
 language for RDF.
</p>

<p>
  The SPARQL query language for RDF is designed to meet the use cases and requirements
  identified by the RDF Data Access Working Group in 
  
  <a href="http://www.w3.org/TR/rdf-dawg-uc/" class="inform">RDF Data Access Use 
  Cases and Requirements</a> [<a href="#UCNR">UCNR</a>] and 
  
  <a href="http://www.w3.org/TR/sparql-features/" class="inform">SPARQL New Features and Rationale</a>
  [<a href="#UCNR2">UCNR2</a>].
</p>

      <div2 id="docOutline">
        <head>Document Outline</head>
<p>Unless otherwise noted in the section heading, all sections and appendices in this document are normative.</p>

<p>
This section of the document, <a href="#introduction">section 1</a>, introduces the SPARQL query 
language specification. It presents the organization of this specification 
document and the conventions used throughout the specification.
</p>

<p><a href="#basicpatterns">Section 2</a> of the specification introduces the SPARQL query language itself 
via a series of example queries and query results. <a href="#termConstraint">Section 3</a> continues 
the introduction of the SPARQL query language with more examples that 
demonstrate SPARQL's ability to express constraints on the RDF terms that 
appear in a query's results.</p>

<p><a href="#sparqlSyntax">Section 4</a> presents details of the SPARQL query language's syntax. It is a 
companion to the full grammar of the language and defines how grammatical 
constructs represent IRIs, blank nodes, literals, and variables. Section 4 
also defines the meaning of several grammatical constructs that serve as 
syntactic sugar for more verbose expressions.</p>

<p><a href="#GraphPattern">Section 5</a> introduces basic graph patterns and group graph patterns, the 
building blocks from which more complex SPARQL query patterns are 
constructed. Sections 6, 7, and 8 present constructs that combine SPARQL 
graph patterns into larger graph patterns. In particular, <a href="#optionals">Section 6</a> 
introduces the ability to make portions of a query optional; <a href="#alternatives">Section 7</a> 
introduces the ability to express the disjunction of alternative graph 
patterns; and <a href="#negation">Section 8</a> introduces patterns to test for the absense of information.</p>

<p><a href="#propertypaths">Section 9</a> adds property paths to graph pattern matching, giving
a compact representation of queries and also the ability to match arbitrary length paths in the graph.</p>

<p><a href="#assignment">Section 10</a> describes the forms of assignment possible in SPARQL.</p>

<p><a href="#aggregates">Sections 11</a> introduces the mechanism to group and aggregate results, 
which can be incorporated as subqueries as described in <a href="#subqueries">Section 12</a>.</p>

<p><a href="#rdfDataset">Section 13</a> introduces the ability to constrain portions of a 
query to particular source graphs. Section 13 also presents SPARQL's 
mechanism for defining the source graphs for a query.</p>

<p><a href="#basic-federated-query">Section 14</a> refers to the separate document 
<a href="http://www.w3.org/TR/sparql11-federated-query/">SPARQL 1.1 Federated Query</a>.</p>

<p><a href="#solutionModifiers">Section 15</a> defines the constructs that affect the solutions of a query by 
ordering, slicing, projecting, limiting, and removing duplicates from a 
sequence of solutions.</p>

<p><a href="#QueryForms">Section 16</a> defines the four types of SPARQL queries that produce results 
in different forms.</p>

<p><a href="#expressions">Section 17</a> defines SPARQL's extensible value testing and expression framework.
It presents the functions and operators that can be used to constrain the 
values that appear in a query's results and also calculate new values to be returned by a query.</p>

<p><a href="#sparqlDefinition">Section 18</a> is a formal definition of the evaluation of SPARQL graph 
patterns and solution modifiers.</p>

<p><a href="#grammar">Section 19</a> contains the normative definition of the syntax for the 
SPARQL query and <a href="http://www.w3.org/TR/sparql11-update/">SPARQL update</a> languages,
as given by a grammar expressed in EBNF notation.
</p>
      </div2>

      <div2 id="docConventions">
        <head>Document Conventions</head>
        <div3 id="docNamespaces">
          <head>Namespaces</head>
<p>In this document, examples assume the following namespace prefix bindings unless 
otherwise stated:</p>
<div style="text-align: center;">
  <table style="border-collapse: collapse; border-color: #000000" border="1" cellpadding="5">
    <tr>
      <th>Prefix</th>
      <th>IRI</th>
    </tr>
    <tr>
      <td><code>rdf:</code></td>
      <td><code>http://www.w3.org/1999/02/22-rdf-syntax-ns#</code></td>
    </tr>
    <tr>
      <td><code>rdfs:</code></td>
      <td><code>http://www.w3.org/2000/01/rdf-schema#</code></td>
    </tr>
    <tr>
      <td><code>xsd:</code></td>
      <td><code>http://www.w3.org/2001/XMLSchema#</code></td>
    </tr>
    <tr>
      <td><code>fn:</code></td>
      <td><code>http://www.w3.org/2005/xpath-functions#</code></td>
    </tr>
    <tr>
      <td><code>sfn:</code></td>
      <td><code>http://www.w3.org/ns/sparql#</code></td>
    </tr>
  </table>
</div>
        </div3>
        <div3 id="docDataDesc">
          <head>Data Descriptions</head>
<p>This document uses the 
<a class="inform" href="http://www.w3.org/TR/turtle/">Turtle</a> [<a href="#TURTLE">TURTLE</a>]
data format to show each triple explicitly. Turtle allows IRIs to be abbreviated with prefixes:</p>
<pre class="data">@prefix dc:   &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix :     &lt;http://example.org/book/&gt; .
:book1  dc:title  &quot;SPARQL Tutorial&quot; .</pre>
        </div3>
        <div3 id="docResultDesc">
          <head>Result Descriptions</head>
<p>Result sets are illustrated in tabular form.
</p>
<div class="result">
  <table class="resultTable" id="table39">
    <tr>
      <th>x</th>
      <th>y</th>
      <th>z</th>
    </tr>
    <tr>
      <td>&quot;Alice&quot;</td>
      <td><code>&lt;http://example/a&gt;</code></td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
    </tr>
  </table>
</div>
<p>A 'binding' is a pair (<a href="#defn_QueryVariable">variable</a>,
<a href="#defn_RDFTerm">RDF term</a>). In this result set, there are three
variables:
<code>x</code>, <code>y</code> and <code>z</code> (shown as column headers). Each 
solution is shown as one row in the body of the table.&nbsp; Here, there is a single 
solution, in which variable <code>x</code> is bound to <code>&quot;Alice&quot;</code>, variable
<code>y</code> is bound to <code>&lt;http://example/a&gt;</code>, and variable <code>z</code> 
is not bound to an RDF term. Variables are not required to be bound in a 
solution.</p>

        </div3>
        <div3 id="docTerminology">
          <head>Terminology</head>

  <p>The SPARQL language includes IRIs, a subset of RDF URI References that omits spaces. Note that all IRIs 
  in SPARQL queries are absolute; they may or may not include a fragment identifier [<a href=
  "#rfc3987">RFC3987</a>, section 3.1]. IRIs include URIs [<a href="#rfc3986">RFC3986</a>] and URLs. The abbreviated
  forms (<a href="#QSynIRI">relative IRIs and prefixed names</a>) in the SPARQL syntax are resolved to produce absolute
  IRIs.</p>
<p>The following terms are defined in
<a class="norm" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/">RDF
  Concepts and Abstract Syntax</a> <a href="#CONCEPTS">[CONCEPTS]</a> and used 
in SPARQL:</p>

  <ul>
    <li><a class="type IRI" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-URI-reference">IRI</a> (corresponds to the Concepts and Abstract Syntax term "<code>RDF URI reference</code>")</li>
    <li><a class="type literal" href=    "http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-literal">literal</a></li>
    <li><a class="type lexicalForm" href="http://www.w3.org/TR/rdf-concepts/#dfn-lexical-form">lexical form</a></li>
    <li><a class="type plainLiteral" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-plain-literal">plain literal</a></li>
    <li><a class="type langTag" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-language-identifier">language tag</a></li>
    <li><a class="type typedLiteral" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-typed-literal">typed literal</a></li>
    <li><a class="type datatypeIRI" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-datatype-URI">datatype IRI</a> (corresponds to the Concepts and Abstract Syntax term "<code>datatype URI</code>")</li>
    <li><a class="type bNode" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-blank-node">blank node</a></li>
  </ul>

  <p>In addition, we define the following terms:</p>
  <ul>
    <li><a class="type" href="#defn_RDFTerm">RDF Term</a>, which includes IRIs, blank nodes and literals</li>
    <li><a class="type" href="#defn_SimpleLiteral">Simple Literal</a>, which covers literals without language tag or datatype IRI</li>
  </ul>
        </div3>
      </div2>
    </div1>
    <div1 id="basicpatterns">
      <head>Making Simple Queries (Informative)</head>
    <p>Most forms of SPARQL query contain a set of triple patterns called a <em>basic graph pattern</em>. Triple patterns are like RDF triples except that each of the subject, predicate and object may be a variable. A basic graph pattern <em>matches</em> a subgraph of the RDF data when <a href="#defn_RDFTerm">RDF terms</a> from that subgraph may be substituted for the variables and the result is RDF graph equivalent to the subgraph.</p>

      <div2 id="WritingSimpleQueries">
        <head>Writing a Simple Query</head>
<p>The example below shows a SPARQL query to find the title of a book from the 
given data graph. The query consists of two parts:
the <code>SELECT</code> clause identifies 
the variables to appear in the query results, and the <code>WHERE</code> clause 
provides the basic graph pattern to match against the data graph. The basic graph pattern in this example 
consists of a single triple pattern with a single variable (<code>?title</code>) in the object position.</p>
<div class="exampleGroup">
  <p>Data:</p>
  <pre class="data">&lt;http://example.org/book/book1&gt; &lt;http://purl.org/dc/elements/1.1/title&gt; &quot;SPARQL Tutorial&quot; .</pre>
  <div class="queryGroup">
    <p>Query:</p>
    <pre class="query">SELECT ?title
WHERE
{
  &lt;http://example.org/book/book1&gt; &lt;http://purl.org/dc/elements/1.1/title&gt; ?title .
}</pre>
    <p>This query, on the data above, has one solution:</p>
    <p>Query Result:</p>
    <div class="result">
      <table class="resultTable" id="table109">
        <tr>
          <th>title</th>
        </tr>
        <tr>
          <td>&quot;SPARQL Tutorial&quot;</td>
        </tr>
      </table>
    </div>
  </div>
</div>
      </div2>
      <div2 id="MultipleMatches">
        <head>Multiple Matches</head>
<p>The result of a query is a <a href="#defn_sparqlSolutionSequence">solution sequence</a>, corresponding to the ways in which 
the query's graph pattern matches the data. There may be 
zero, one or multiple solutions to a query.</p>
<p>Data:</p>
<div class="exampleGroup">
  <pre class="data">@prefix foaf:  &lt;<a href="http://xmlns.com/foaf/0.1/">http://xmlns.com/foaf/0.1/</a>&gt; .

_:a  foaf:name   &quot;Johnny Lee Outlaw&quot; .
_:a  foaf:mbox   &lt;mailto:jlow@example.com&gt; .
_:b  foaf:name   &quot;Peter Goodguy&quot; .
_:b  foaf:mbox   &lt;mailto:peter@example.org&gt; .
_:c  foaf:mbox   &lt;mailto:carol@example.org&gt; .
</pre>
  <p>Query:</p>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
WHERE
  { ?x foaf:name ?name .
    ?x foaf:mbox ?mbox }</pre>
    <p>Query Result:</p>
    <div class="result">
      <table class="resultTable">
        <tr>
          <th>name</th>
          <th>mbox</th>
        </tr>
        <tr>
          <td>&quot;Johnny Lee Outlaw&quot;</td>
          <td>&lt;mailto:jlow@example.com&gt;</td>
        </tr>
        <tr>
          <td>&quot;Peter Goodguy&quot;</td>
          <td>&lt;mailto:peter@example.org&gt;</td>
        </tr>
      </table>
    </div>
  </div>
</div>
<p>Each solution gives one way in which the selected variables can be bound 
to RDF terms so that the query pattern matches the data. The result set gives 
all the possible solutions. In the above example, 
the following two subsets of the data provided the two matches.</p>
<pre class="dataExcerpt untested"> _:a foaf:name  &quot;Johnny Lee Outlaw&quot; .
 _:a foaf:box   &lt;mailto:jlow@example.com&gt; .</pre>

<pre class="dataExcerpt untested"> _:b foaf:name  &quot;Peter Goodguy&quot; .
 _:b foaf:box   &lt;mailto:peter@example.org&gt; .</pre>

<p>This is a <a href="#BGPsparql">basic graph pattern match</a>; all the 
variables used in the query pattern must be bound in every solution.</p>

      </div2>
      <div2 id="matchingRDFLiterals">
        <head>Matching RDF Literals</head>
<p>The data below contains three RDF literals:</p>
<div class="exampleGroup">
  <pre class="data">@prefix dt:   &lt;http://example.org/datatype#&gt; .
@prefix ns:   &lt;http://example.org/ns#&gt; .
@prefix :     &lt;http://example.org/ns#&gt; .
@prefix xsd:  &lt;<code>http://www.w3.org/2001/XMLSchema#&gt; .</code>

:x   ns:p     "cat"@en .
:y   ns:p     "42"^^xsd:integer .
:z   ns:p     "abc"^^dt:specialDatatype .</pre>

      <p>Note that, in Turtle, <code>"cat"@en</code> is an RDF literal with a lexical form "cat" and a language tag "en"; <code>"42"^^xsd:integer</code> is a typed literal with the datatype <code>http://www.w3.org/2001/XMLSchema#integer</code>; and <code>"abc"^^dt:specialDatatype</code> is a typed literal with the datatype <code>http://example.org/datatype#specialDatatype</code>.</p>
</div>

  <p>This RDF data is the data graph for the query examples in sections 2.3.1&ndash;2.3.3.</p>
          <div3 id="matchLangTags">
          <head>Matching Literals with Language Tags</head>
      <p>Language tags in SPARQL are expressed using <code>@</code> and the 
      language tag, as defined in <a class="norm" href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">Best Common Practice 47</a> [<a href="#BCP47">BCP47</a>].</p>

  <p>This following query has no solution because <code>&quot;cat&quot;</code> is not the 
  same RDF literal as <code>&quot;cat&quot;@en</code>:</p>
  <div class="queryGroup">
    <pre class="query">SELECT ?v WHERE { ?v ?p &quot;cat&quot; }</pre>

    <div class="result">
      <table class="resultTable">
        <tr>
          <th>&nbsp;&nbsp; v&nbsp;&nbsp;&nbsp;&nbsp; </th>
        </tr>
      </table>
    </div>
    <p>but the query below will find a solution where variable <code>v</code> is bound to
    <code>:x</code> because the language tag is specified and matches the given data:</p>
    <pre class="query">SELECT ?v WHERE { ?v ?p &quot;cat&quot;@en }
</pre>
    <div class="result">
      <table class="resultTable">
        <tr>
          <th>v</th>
        </tr>
        <tr>
          <td>&lt;http://example.org/ns#x&gt;</td>
        </tr>
      </table>
    </div>
  </div>
        </div3>

          <div3 id="matchNumber">
          <head>Matching Literals with Numeric Types</head>
    <p>Integers in a SPARQL query indicate an RDF typed literal with the datatype
    <code>xsd:integer</code>. For example: <code>42</code> is a shortened form 
    of&nbsp; <code>"42"^^&lt;http://www.w3.org/2001/XMLSchema#integer&gt;</code>.</p>
  <p>The pattern in the following query has a solution with variable <code>v</code> 
  bound to <code>:y</code>.</p>
  <div class="queryGroup">
    <pre class="query">SELECT ?v WHERE { ?v ?p 42 }
</pre>
    <div class="result">
      <table class="resultTable" id="table60">
        <tr>
          <th>v</th>
        </tr>
        <tr>
          <td>&lt;http://example.org/ns#y&gt;</td>
        </tr>
      </table>
    </div>
  </div>
    <p><a href="#QSynLiterals">Section 4.1.2</a> defines SPARQL shortened forms for <code>xsd:float</code> and <code>xsd:double</code>.</p>
        </div3>
          <div3 id="matchArbDT">
          <head>Matching Literals with Arbitrary Datatypes</head>
  <p>The following query has a solution with variable <code>v</code> bound to
  <code>:z</code>. The query processor does not have to have any understanding 
  of the values in the space of the datatype. Because the lexical form and 
  datatype IRI both match, the literal matches.</p>
  <div class="queryGroup">
    <pre class="query">SELECT ?v WHERE { ?v ?p &quot;abc&quot;^^&lt;http://example.org/datatype#specialDatatype&gt; }
</pre>
    <div class="result">
      <table class="resultTable" id="table61">
        <tr>
          <th>v</th>
        </tr>
        <tr>
          <td>&lt;http://example.org/ns#z&gt;</td>
        </tr>
      </table>
    </div>
  </div>

        </div3>
      </div2>           
      <div2 id="BlankNodesInResults">
        <head>Blank Node Labels in Query Results</head>
<p>
  Query results can contain blank nodes. Blank nodes in the example
  result sets in this document are written in the form
  "_:" followed by a blank node label.
</p>

<p>Blank node labels are scoped to a result set (see 
&quot;<a class="inform" href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL 
Query Results XML Format</a>&quot; and  
&quot;<a href="http://www.w3.org/TR/sparql11-results-json/">SPARQL 1.1 Query Results JSON Format</a>&quot;)
or, for the <code>CONSTRUCT</code> query 
form, the result graph. 
Use of the same label within a 
result set indicates the same blank node.</p>
<div class="exampleGroup">
  Data:
  <pre class="data">@prefix foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name   &quot;Alice&quot; .
_:b  foaf:name   &quot;Bob&quot; .
</pre>
  <div class="queryGroup">
    Query:
    <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?x ?name
WHERE  { ?x foaf:name ?name }
</pre>
    <div class="result">
      <table class="resultTable" id="table56">
        <tr>
          <th>x</th>
          <th>name</th>
        </tr>
        <tr>
          <td>_:c</td>
          <td>&quot;Alice&quot;</td>
        </tr>
        <tr>
          <td>_:d</td>
          <td>&quot;Bob&quot;</td>
        </tr>
      </table>
    </div>
  </div>
  <p>The results above could equally be given with different blank node labels because 
  the labels in the results only indicate whether RDF terms in the solutions are 
  the same or different.</p>
  <div class="result untested">
    <table class="resultTable" id="table57">
      <tr>
        <th>x</th>
        <th>name</th>
      </tr>
      <tr>
        <td>_:r</td>
        <td>&quot;Alice&quot;</td>
      </tr>
      <tr>
        <td>_:s</td>
        <td>&quot;Bob&quot;</td>
      </tr>
    </table>
  </div>
</div>
<p>These two results have the same information: the blank nodes used to match the 
query are different in the two solutions. There need not be any relation between a 
label
<code>_:a</code> in the result set and a blank node in the data graph 
with the same label.</p>

<p>An application writer should not expect blank node labels in a query to refer to a particular blank node in the data.</p>


      </div2>

      <div2 id="CreatingValuesWithExpressions">
        <head>Creating Values with Expressions</head>
        <p>SPARQL 1.1 allows to create values from complex expressions.
        The queries below show how to the <a href="#func-concat">CONCAT</a> function 
	can be used to concatenate first names and last names from foaf data, then assign
	the value using an <a href="#selectExpressions">expression in the <code>SELECT</code> clause</a> 
	and also assign the value by using the <a href="#bind">BIND</a> form.</p>

        <div class="exampleGroup">
          Data:
          <pre class="data">@prefix foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .
          
_:a  foaf:givenName   &quot;John&quot; .
_:a  foaf:surname  &quot;Doe&quot; .</pre>

          <div class="queryGroup">
            Query:
            <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ( CONCAT(?G, " ", ?S) AS ?name )
WHERE  { ?P foaf:givenName ?G ; foaf:surname ?S }</pre>
            Query:
            <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name
WHERE  { 
   ?P foaf:givenName ?G ; 
      foaf:surname ?S 
   BIND(CONCAT(?G, " ", ?S) AS ?name)
}</pre>
            <div class="result">
	      <table class="resultTable" id="table59">
		<tr>
		  <th>name</th>
		</tr>
		<tr>
		  <td>&quot;John Doe&quot;</td>
		</tr>
	      </table>
             </div>
           </div>
        </div>

      </div2>
          
      <div2 id="constructGraph">
        <head>Building RDF Graphs</head>
<p>SPARQL has several <a href="#QueryForms">query forms</a>.
The <code>SELECT</code> query form 
returns variable bindings. The <code>CONSTRUCT</code> query form
returns an RDF graph. The graph is built based on a template
which is used to generate RDF triples based on the results of matching
the graph pattern of the query.</p>

<div class="exampleGroup">
<p>Data:</p>
  <pre class="data">@prefix org:    &lt;http://example.com/ns#&gt; .

_:a  org:employeeName   &quot;Alice&quot; .
_:a  org:employeeId     12345 .

_:b  org:employeeName   &quot;Bob&quot; .
_:b  org:employeeId     67890 .</pre>
  <div class="queryGroup">
<p>Query:</p>
    <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX org:    &lt;http://example.com/ns#&gt;

CONSTRUCT { ?x foaf:name ?name }
WHERE  { ?x org:employeeName ?name }</pre>
<p>Results:</p>
    <div class="result">
      <pre class="resultGraph">@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .
      
_:x foaf:name &quot;Alice&quot; .
_:y foaf:name &quot;Bob&quot; .</pre>
      </div>
  </div>

  <p>which can be serialized in
  <a href="http://www.w3.org/TR/rdf-syntax-grammar/">RDF/XML</a> as:</p>
  
  <div class="result">
      <pre class="resultGraph" style="text-align: left;">&lt;rdf:RDF
    xmlns:rdf=&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;
    xmlns:foaf=&quot;http://xmlns.com/foaf/0.1/&quot;
    &gt;
  &lt;rdf:Description&gt;
    &lt;foaf:name&gt;Alice&lt;/foaf:name&gt;
  &lt;/rdf:Description&gt;
  &lt;rdf:Description&gt;
    &lt;foaf:name&gt;Bob&lt;/foaf:name&gt;
  &lt;/rdf:Description&gt;
&lt;/rdf:RDF&gt;</pre>
  </div>
  </div>



      </div2>
    </div1>
    <div1 id="termConstraint">
      <head>RDF Term Constraints (Informative)</head>
  <p>Graph pattern matching produces a solution sequence, where each solution has a set of bindings of variables to RDF terms. SPARQL <code>FILTER</code>s
  restrict solutions to those for which the filter expression evaluates to <code>TRUE</code>.</p>

    <p>This section provides an informal introduction to SPARQL <code>FILTER</code>s; their semantics are defined in section '<a href="#expressions">Expressions and Testing Values</a>' where there is a <a href="#SparqlOps">comprehensive function library</a>. The examples in this section share one input graph:</p>

<div class="exampleGroup">
  Data:
  <pre class="data">@prefix dc:   &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix :     &lt;http://example.org/book/&gt; .
@prefix ns:   &lt;http://example.org/ns#&gt; .

:book1  dc:title  &quot;SPARQL Tutorial&quot; .
:book1  ns:price  42 .
:book2  dc:title  &quot;The Semantic Web&quot; .
:book2  ns:price  23 .
</pre>
</div>
        <div2 id="restrictString">
        <head>Restricting the Value of Strings</head>
  <p>SPARQL <code>FILTER</code> functions like <code><a href="#func-regex">regex</a></code> can test RDF literals. <code>regex</code> matches only <a href="#func-string">string literals</a>.
  <code>regex</code> can be used to match the lexical forms of other literals by 
  using the <a href="#func-str">str</a> 
  function.</p>
  <p>Query:</p>
  <div class="queryGroup">
    <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
SELECT  ?title
WHERE   { ?x dc:title ?title
          FILTER regex(?title, &quot;^SPARQL&quot;) 
        }
</pre>
    <p>Query Result:</p>
    <div class="result">
      <table class="resultTable" id="table63">
        <tr>
          <th>title</th>
        </tr>
        <tr>
          <td>&quot;SPARQL Tutorial&quot;</td>
        </tr>
      </table>
    </div>
  </div>
  <p>Regular expression matches may be made case-insensitive with the &quot;<code>i</code>&quot; 
  flag.</p>
  <p>Query:</p>
  <div class="queryGroup">
    <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
SELECT  ?title
WHERE   { ?x dc:title ?title
          FILTER regex(?title, &quot;web&quot;, &quot;i&quot; ) 
        }
</pre>
    <p>Query Result:</p>
    <div class="result">
      <table class="resultTable" id="table64">
        <tr>
          <th>title</th>
        </tr>
        <tr>
          <td>&quot;The Semantic Web&quot;</td>
        </tr>
      </table>
    </div>
  </div>
      <p>The regular expression language is <a href="http://www.w3.org/TR/xpath-functions/#regex-syntax">defined by XQuery 1.0 and XPath 2.0 Functions and Operators</a> and is based on <a href="http://www.w3.org/TR/xmlschema-2/#regexs">XML Schema Regular Expressions</a>.</p>
      </div2>
        <div2 id="restrictNumber">
        <head>Restricting Numeric Values</head>
        <p>SPARQL <code>FILTER</code>s can restrict on arithmetic expressions.</p>
        <p>Query:</p>
        <div class="queryGroup">
          <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  ns:  &lt;http://example.org/ns#&gt;
SELECT  ?title ?price
WHERE   { ?x ns:price ?price .
          FILTER (?price &lt; 30.5)
          ?x dc:title ?title . }</pre>
                            <p>Query Result:</p>
          <div class="result">
            <table class="resultTable" id="table58">
              <tr>
          <th>title</th>
          <th>price</th>
              </tr>
              <tr>
          <td>&quot;The Semantic Web&quot;</td>
          <td>23</td>
              </tr>
            </table>
          </div>
        </div>
      </div2>




<p>By constraining the <code>price</code> variable, only <code>:book2</code> matches 
the query because only <code>:book2</code> has a price less than <code>30.5</code>, 
as the filter condition requires. </p>

      <div2 id="otherTermConstraints">
        <head>Other Term Constraints</head>

	<p>In addition to <span class="type numeric">numeric</span> types, SPARQL supports 
	types <code>xsd:string</code>, <code>xsd:boolean</code> and <code>xsd:dateTime</code>
	(see <a href="#operandDataTypes">Operand Data Types</a>). 
	Section <a href="#OperatorMapping">Operator Mapping</a> describes the operators 
	and section <a href="#SparqlOps">Function Definitions</a> the functions that can be 
	that can be applied to RDF terms.</p>
      </div2>
    </div1>
    <div1 id="sparqlSyntax">
      <head>SPARQL Syntax</head>
<p>This section covers the syntax used by SPARQL for <a href="#sparqlBasicTerms">
RDF terms</a> and <a href="#sparqlTriplePatterns">triple patterns</a>. The full grammar 
is given in <a href="#grammar">section 19</a>.</p>
      <div2 id="syntaxTerms">
        <head>RDF Term Syntax</head>
        <div3 id="QSynIRI">
          <head>Syntax for IRIs</head>

    <p>The <a href="#riri">iri</a> production designates the set of IRIs [<a href="#rfc3987">RFC3987</a>]; IRIs are a generalization of URIs [<a href="#rfc3986">RFC3986</a>] and are fully compatible with URIs and URLs. The <a href="#rPrefixedName">PrefixedName</a> production designates a prefixed name. The mapping from a prefixed name to an IRI is described below. IRI references (relative or absolute IRIs) are designated by the <a href="#rIRIREF">IRIREF</a> production, where the '&lt;' and '&gt;' delimiters do not form part of the IRI reference.  Relative IRIs match the <code>irelative-ref</code> reference in section 2.2 ABNF for IRI References and IRIs in [<a href="#rfc3987">RFC3987</a>] and are resolved to IRIs as described below.</p>

<p>The set of RDF terms defined in RDF Concepts and Abstract Syntax
   includes RDF URI references while SPARQL terms include IRIs. RDF URI
   references containing "<code>&lt;</code>", "<code>&gt;</code>", '<code>&quot;</code>' (double 
quote), space, &quot;<code>{</code>&quot;, &quot;<code>}</code>&quot;, &quot;<code>|</code>&quot;,
&quot;<code>\</code>&quot;, &quot;<code>^</code>&quot;, and 
&quot;<code>`</code>&quot; are not IRIs. The behavior of a SPARQL query against RDF
   statements composed of such RDF URI references is not defined.</p>
          <div4 id="prefNames">
            <head>Prefixed Names</head>
<p>The <code>PREFIX</code> keyword associates a prefix label with an IRI. A prefixed 
name is a prefix label and a local part, separated by a colon &quot;<code>:</code>&quot;. 
A prefixed name is mapped to an IRI by concatenating the IRI associated with the prefix and the local part. 
The prefix label or the local part may be empty. 
Note that <a href="#rPN_LOCAL">SPARQL local names</a> allow leading digits while <a href="http://www.w3.org/TR/2006/REC-xml-names11-20060816/#NT-LocalPart">XML local names</a> do not.
<a href="#rPN_LOCAL">SPARQL local names</a> also allow the non-alphanumeric characters allowed in IRIs 
via backslash character escapes (e.g. <code>ns:id\=123</code>). 
<a href="#rPN_LOCAL">SPARQL local names</a> have more syntactic restrictions than <a href="http://www.w3.org/TR/curie/">CURIE</a>s.
</p>

          </div4>
          <div4 id="relIRIs">
            <head>Relative IRIs</head>
<p>Relative IRIs are combined with base IRIs as per
<a class="norm" href="http://www.ietf.org/rfc/rfc3986.txt">Uniform Resource Identifier 
(URI): Generic Syntax</a> [<a href="#rfc3986">RFC3986</a>] using only the basic 
algorithm in section 5.2. Neither Syntax-Based Normalization nor Scheme-Based Normalization 
(described in sections 6.2.2 and 6.2.3 of RFC3986) are performed. Characters additionally 
allowed in IRI references are treated in the same way that unreserved characters 
are treated in URI references, per section 6.5 of
<a class="norm" href="http://www.ietf.org/rfc/rfc3987.txt">Internationalized Resource 
Identifiers (IRIs)</a> [<a href="#rfc3987">RFC3987</a>].</p>
<p>The <code>BASE</code> keyword defines the Base IRI used to resolve relative IRIs 
per RFC3986 section 5.1.1, &quot;Base URI Embedded in Content&quot;. Section 5.1.2, &quot;Base 
URI from the Encapsulating Entity&quot; defines how the Base IRI may come from an encapsulating 
document, such as a SOAP envelope with an xml:base directive or a mime multipart 
document with a Content-Location header. The &quot;Retrieval URI&quot; identified in 5.1.3, 
Base &quot;URI from the Retrieval URI&quot;, is the URL from which a particular SPARQL query 
was retrieved. If none of the above specifies the Base URI, the default Base URI 
(section 5.1.4, &quot;Default Base URI&quot;) is used.</p>
<p>The following fragments are some of the different ways to write the same IRI:</p>
<pre class="data">&lt;http://example.org/book/book1&gt;</pre>
<pre class="data">BASE &lt;http://example.org/book/&gt;
&lt;book1&gt;</pre>
<pre class="data">PREFIX book: &lt;http://example.org/book/&gt;
book:book1</pre>
          </div4>
        </div3>
        <div3 id="QSynLiterals">
          <head>Syntax for Literals</head>
<p>The general syntax for literals is a string (enclosed in either double 
quotes, <code>&quot;...&quot;</code>, or single quotes, <code>&#39;...&#39;</code>), with either an optional 
language tag (introduced by <code>@</code>) or an optional datatype IRI or prefixed 
name (introduced by <code>^^</code>).</p>
<p>As a convenience, integers can be written directly (without quotation marks and an explicit datatype IRI) and are interpreted as typed 
literals of datatype <code>xsd:integer</code>; decimal numbers for which there is &#39;.&#39; 
in the number but no exponent are interpreted as <code>xsd:decimal</code>; and 
numbers with exponents are interpreted as <code>xsd:double</code>. Values of 
type <code>xsd:boolean</code> can also be written as <code>true</code> or <code>
false</code>.</p>
<p>To facilitate writing literal values which themselves contain quotation marks 
or which are long and contain newline characters, SPARQL provides an additional 
quoting construct in which literals are enclosed in three single- or double-quotation 
marks.</p>
<p>Examples of literal syntax in SPARQL include:</p>
<ul>
  <li><code>&quot;chat&quot;</code></li>
  <li><code>&#39;chat&#39;@fr</code> with language tag &quot;fr&quot;</li>
  <li><code>&quot;xyz&quot;^^&lt;http://example.org/ns/userDatatype&gt;</code></li>
  <li><code>&quot;abc&quot;^^appNS:appDataType</code></li>
  <li><code>'''The librarian said, &quot;Perhaps you would enjoy &#39;War and Peace&#39;.&quot;'''</code></li>
  <li><code>1</code>, which is the same as <code>&quot;1&quot;^^xsd:integer</code></li>
  <li><code>1.3</code>, which is the same as <code>&quot;1.3&quot;^^xsd:decimal</code></li>
  <li><code>1.300</code>, which is the same as <code>&quot;1.300&quot;^^xsd:decimal</code></li>
  <li><code>1.0e6</code>, which is the same as <code>&quot;1.0e6&quot;^^xsd:double</code></li>
  <li><code>true</code>, which is the same as <code>&quot;true&quot;^^xsd:boolean</code></li>
  <li><code>false</code>, which is the same as <code>&quot;false&quot;^^xsd:boolean</code></li>
</ul>

    <p>
  Tokens matching the productions <a href="#rINTEGER">INTEGER</a>, <a href="#rDECIMAL">DECIMAL</a>, <a href="#rDOUBLE">DOUBLE</a> and
  <a href="#rBooleanLiteral">BooleanLiteral</a> are equivalent to a typed
  literal with the lexical value of the token and the corresponding
  datatype (<code>xsd:integer</code>, <code>xsd:decimal</code>, <code>xsd:double</code>, <code>xsd:boolean</code>).
    </p>

        </div3>
        <div3 id="QSynVariables">
          <head>Syntax for Query Variables</head>

	  <p>A query variable is marked by the use of either "?" or "$"; 
	  the "?" or "$" is not part of the variable name. 
	  In a query, <code>$abc</code> and <code>?abc</code> identify the same variable. The
	  <a href="#rVARNAME">possible names</a> for variables are given in the
	  <a href="#grammar">SPARQL grammar</a>.</p>

        </div3>
        <div3 id="QSynBlankNodes">
          <head>Syntax for Blank Nodes</head>
<p><a class="norm" href="http://www.w3.org/TR/rdf-concepts/#section-blank-nodes">Blank 
nodes</a> in graph patterns act as variables, not as references to specific blank nodes in the 
data being queried.</p>
    <p>Blank nodes are indicated by either the label form, such as "<code>_:abc</code>", or the abbreviated form "<code>[]</code>". A blank 
node that is used in only one place in the query syntax can be indicated with
<code>[]</code>. A unique blank node will be used to form the triple 
pattern. Blank node labels are written as &quot;<code>_:abc</code>&quot; for a blank node with 
label &quot;<code>abc</code>&quot;. The same blank node label cannot be used 
    in two different basic graph patterns in the same query.</p>
<p>The <code>[:p :v]</code> construct can be used in triple patterns. It creates 
a blank node label which is used as the subject of all contained predicate-object 
pairs. The created blank node can also be used in further triple patterns in the 
subject and object positions.</p>
<p>The following two forms</p>
<pre class="query untested">[ :p &quot;v&quot; ] .
</pre>
<pre class="query untested">[] :p &quot;v&quot; .
</pre>
<p>allocate a unique blank node label (here &quot;<code>b57</code>&quot;) and are equivalent 
to writing:</p>
<pre class="query untested">_:b57 :p &quot;v&quot; .
</pre>
<p>This allocated blank node label can be used as the subject or object of further 
triple patterns. For example, as a subject:</p>
<pre class="query untested">[ :p &quot;v&quot; ] :q &quot;w&quot; .
</pre>
<p>which is equivalent to the two triples:</p>
<pre class="query untested">_:b57 :p &quot;v&quot; .
_:b57 :q &quot;w&quot; .
</pre>
<p>and as an object:</p>
<pre class="query untested">:x :q [ :p &quot;v&quot; ] .
</pre>
<p>which is equivalent to the two triples:</p>
<pre class="query untested">:x  :q _:b57 .
_:b57 :p &quot;v&quot; .
</pre>
<p>Abbreviated blank node syntax can be combined with other abbreviations for 
<a href="#predObjLists">common 
subjects</a> and <a href="#objLists">common predicates</a>.</p>
<pre class="query untested">  [ foaf:name  ?name ;
    foaf:mbox  &lt;mailto:alice@example.org&gt; ]
</pre>
<p>This is the same as writing the following basic graph pattern for some uniquely 
allocated blank node label, &quot;<code>b18</code>&quot;:</p>
<pre class="query untested">  _:b18  foaf:name  ?name .
  _:b18  foaf:mbox  &lt;mailto:alice@example.org&gt; .
</pre>

        </div3>
      </div2>
      <div2 id="QSynTriples">
        <head>Syntax for Triple Patterns</head>
<p><a href="#defn_TriplePattern">Triple Patterns</a> are written as subject, 
predicate and object; there are abbreviated ways of writing some common triple pattern 
constructs.</p>
<p>The following examples express the same query:</p>
<pre class="query">PREFIX  dc: &lt;http://purl.org/dc/elements/1.1/&gt;
SELECT  ?title
WHERE   { &lt;http://example.org/book/book1&gt; dc:title ?title }  
</pre>
<pre class="query">PREFIX  dc: &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  : &lt;http://example.org/book/&gt;

SELECT  $title
WHERE   { :book1  dc:title  $title }
</pre>
<pre class="query">BASE    &lt;http://example.org/book/&gt;
PREFIX  dc: &lt;http://purl.org/dc/elements/1.1/&gt;

SELECT  $title
WHERE   { &lt;book1&gt;  dc:title  ?title }
</pre>

        <div3 id="predObjLists">
          <head>Predicate-Object Lists</head>
<p>Triple patterns with a common subject can be written so that the subject is only 
written once and is used for more than one triple pattern by employing the &quot;<code>;</code>&quot; 
notation.</p>
<pre class="query untested">    ?x  foaf:name  ?name ;
        foaf:mbox  ?mbox .
</pre>
<p>This is the same as writing the triple patterns:</p>
<pre class="query untested">    ?x  foaf:name  ?name .
    ?x  foaf:mbox  ?mbox .
</pre>
        </div3>
        <div3 id="objLists">
          <head>Object Lists</head>
<p>If triple patterns share both subject and predicate, the objects may be separated
by "<code>,</code>".</p>
<pre class="query untested">    ?x foaf:nick  &quot;Alice&quot; , &quot;Alice_&quot; .
</pre>
<p>is the same as writing the triple patterns:</p>
<pre class="query untested">   ?x  foaf:nick  &quot;Alice&quot; .
   ?x  foaf:nick  &quot;Alice_&quot; .
</pre>
<p>Object lists can be combined with predicate-object lists:</p>
<pre class="query untested">   ?x  foaf:name ?name ; foaf:nick  &quot;Alice&quot; , &quot;Alice_&quot; .
</pre>
<p>is equivalent to:</p>
<pre class="query untested">   ?x  foaf:name  ?name .
   ?x  foaf:nick  &quot;Alice&quot; .
   ?x  foaf:nick  &quot;Alice_&quot; .
</pre>
        </div3>
        <div3 id="collections">
          <head>RDF Collections</head>
<p>
<a class="norm" href="http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#collections">
RDF collections</a> can be written in triple patterns using the syntax &quot;(element1 element2 ...)&quot;. The 
form "<code>()</code>" is an alternative for the IRI <code>
<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil">http://www.w3.org/1999/02/22-rdf-syntax-ns#nil</a></code>. 
When used with collection elements, such as <code>(1 ?x 3 4)</code>, triple patterns 
with blank nodes are allocated for the collection. The blank node at the head 
of the collection can be used as a subject or object in other triple patterns. The blank nodes allocated by the collection syntax do not occur elsewhere in the query.</p>
<pre class="query untested">(1 ?x 3 4) :p &quot;w&quot; .
</pre>
<p>is syntactic sugar for (noting that <code>b0</code>, <code>b1</code>, <code>b2</code> and <code>b3</code> do not occur anywhere else in the 
query):</p>
<pre class="query untested">    _:b0  rdf:first  1 ;
          rdf:rest   _:b1 .
    _:b1  rdf:first  ?x ;
          rdf:rest   _:b2 .
    _:b2  rdf:first  3 ;
          rdf:rest   _:b3 .
    _:b3  rdf:first  4 ;
          rdf:rest   rdf:nil .
    _:b0  :p         &quot;w&quot; . 
</pre>
<p>RDF collections can be nested and can involve other syntactic forms:</p>
<pre class="query untested">(1 [:p :q] ( 2 ) ) .
</pre>
<p>is syntactic sugar for:</p>
<pre class="query untested">    _:b0  rdf:first  1 ;
          rdf:rest   _:b1 .
    _:b1  rdf:first  _:b2 .
    _:b2  :p         :q .
    _:b1  rdf:rest   _:b3 .
    _:b3  rdf:first  _:b4 .
    _:b4  rdf:first  2 ;
          rdf:rest   rdf:nil .
    _:b3  rdf:rest   rdf:nil .
</pre>

        </div3>
        <div3 id="abbrevRdfType">
          <head>rdf:type</head>
<p>The keyword &quot;<code>a</code>&quot; can be used as a predicate in a triple pattern and 
is an alternative for the IRI&nbsp; <code>
<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#type">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</a></code>. 
This keyword is case-sensitive.</p>
<pre class="query untested">  ?x  a  :Class1 .
  [ a :appClass ] :p &quot;v&quot; .
</pre>
<p>is syntactic sugar for:</p>
<pre class="query untested">  ?x    rdf:type  :Class1 .
  _:b0  rdf:type  :appClass .
  _:b0  :p        &quot;v&quot; .
</pre>

        </div3>
      </div2>
    </div1>
    <div1 id="GraphPattern">
      <head>Graph Patterns</head>

<p>SPARQL is based around graph pattern matching. More complex graph patterns
can be formed by combining smaller patterns in various ways:</p>

<ul>
  <li><a href="#BasicGraphPatterns">Basic Graph Patterns</a>,
  where a set of triple 
  patterns must match</li>
  <li><a href="#GroupPatterns">Group Graph Pattern</a>, where a set of graph 
  patterns must all match</li>
  <li><a href="#optionals">Optional Graph patterns</a>, where additional patterns 
  may extend the solution</li>
  <li><a href="#alternatives">Alternative Graph Pattern</a>, where two or more possible 
  patterns are tried</li>
  <li><a href="#queryDataset">Patterns on Named Graphs</a>, where patterns are matched 
  against named graphs</li>
</ul>

<p>In this section we describe the two forms that combine patterns by 
conjunction: basic graph patterns, which combine triples patterns, and group 
graph patterns, which combine all other graph patterns.</p>

    <p>The outer-most graph pattern in a query is called the query pattern. It is grammatically identified by <code>GroupGraphPattern</code> in</p>

<div class="grammarExtract">
  <div class="grammarTable">
    <table>
  <tr valign="baseline">
    <td><code class="gRuleLabel">[17]&nbsp;&nbsp;</code></td>
    <td><code class="gRuleHead"><a href="#rWhereClause">WhereClause</a></code></td>
    <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
    <td><code class="gRuleBody"><span class="token">'WHERE'</span>? <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
  </tr>
    </table>
  </div>
</div>

      <div2 id="BasicGraphPatterns">
        <head>Basic Graph Patterns</head>

<p>Basic graph patterns are sets of triple patterns. SPARQL graph pattern 
matching is defined in terms of combining the results from matching basic graph patterns.</p>

<p>A sequence of triple patterns, with optional filters, comprises a single
basic graph pattern.  Any other graph pattern terminates a basic graph pattern.</p>

        <div3 id="bgpBNodeLabels">
          <head>Blank Node Labels</head>

<p>When using blank nodes of the form <code>_:abc</code>,&nbsp; labels for blank 
nodes are scoped to the basic graph pattern.&nbsp; A label can be used in only a 
single basic graph pattern in any query.
</p>

        </div3>
        <div3 id="bgpExtend">
          <head>Extending Basic Graph Pattern Matching</head>

	  <p>SPARQL evaluates basic graph patterns using subgraph matching, which
	  is defined for simple entailment. SPARQL can be extended to
	  other forms of entailment given <a href="#sparqlBGPExtend">certain conditions</a> 
	  as described below. 
	  The document <a href="http://www.w3.org/TR/sparql11-entailment/"> SPARQL 1.1 Entailment Regimes</a> 
	  describes several specific entailment regimes.</p>

        </div3>
      </div2>
      <div2 id="GroupPatterns">
        <head>Group Graph Patterns</head>

<p>In a SPARQL query string, a group graph pattern is delimited with braces:
<code>{}</code>. For example, this query's query pattern is a group graph pattern of one basic 
graph pattern.</p><div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:&nbsp;&nbsp;&nbsp; &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
WHERE&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ?x foaf:name ?name .
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ?x foaf:mbox ?mbox .
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
</pre></div></div><div class="exampleGroup">
  <div class="queryGroup">
    The same solutions would be obtained from a query that grouped the triple patterns
    into two basic graph patterns. For example, the query below has a different
    structure but would yield the same solutions as the previous query:
    <pre class="query">PREFIX foaf:&nbsp;&nbsp;&nbsp; &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
WHERE&nbsp; { { ?x foaf:name ?name . }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { ?x foaf:mbox ?mbox . }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</pre></div></div>

        <div3 id="emptyGroupPattern">
          <head>Empty Group Pattern</head>

<p>The group pattern:</p>
<pre class="query untested">{ }</pre>

<p>matches any graph (including the empty graph) with one solution that does not bind any 
variables. For example:</p>

<pre class="query untested">SELECT ?x
WHERE {}
</pre>

<p>matches with one solution in which variable <code>x</code> is not bound.</p>

        </div3>
        <div3 id="scopeFilters">
          <head>Scope of Filters</head>

<p>A constraint, expressed by the keyword <code>FILTER</code>, is a 
restriction on solutions over the whole group in which the filter appears. The 
following patterns all have the same solutions:</p>

<div class="exampleGroup">
<div class="queryGroup">
  <pre class="query">&nbsp;{&nbsp; ?x foaf:name ?name .
    ?x foaf:mbox ?mbox .
&nbsp;&nbsp;&nbsp; FILTER regex(?name, &quot;Smith&quot;)
 }
  </pre>
</div>
</div>

<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">&nbsp;{&nbsp; FILTER regex(?name, &quot;Smith&quot;)
    ?x foaf:name ?name .
    ?x foaf:mbox ?mbox .
&nbsp;}
</pre>
</div>
</div>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">&nbsp;{&nbsp; ?x foaf:name ?name .
&nbsp;&nbsp;&nbsp; FILTER regex(?name, &quot;Smith&quot;)
    ?x foaf:mbox ?mbox .
 }
</pre>
</div>
</div>

        </div3>
        <div3 id="groupExamples">
          <head>Group Graph Pattern Examples</head>

<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">&nbsp; {
&nbsp;&nbsp;&nbsp; ?x foaf:name ?name .
&nbsp;&nbsp;&nbsp; ?x foaf:mbox ?mbox .
&nbsp; }</pre>
  </div>
</div>

<p>is a group of one basic graph pattern and that basic graph pattern consists 
    of two triple patterns.</p>

<div class="exampleGroup">
    <div class="queryGroup">
      <pre class="query">&nbsp; {
&nbsp;&nbsp;&nbsp; ?x foaf:name ?name . FILTER regex(?name, &quot;Smith&quot;)
&nbsp;&nbsp;&nbsp; ?x foaf:mbox ?mbox .
&nbsp; }</pre>

</div>
</div>

<p>is a group of one basic graph pattern and a filter, and that basic graph 
pattern consists of two triple patterns; the filter does not break the 
basic graph pattern into two basic graph patterns.</p>

<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">&nbsp; {
&nbsp;&nbsp;&nbsp; ?x foaf:name ?name .
&nbsp;&nbsp;&nbsp; {}
&nbsp;&nbsp;&nbsp; ?x foaf:mbox ?mbox .
&nbsp; }</pre>
</div>
</div>

<p>is a group of three elements, a basic graph pattern of one triple pattern, 
an empty group, and another basic graph pattern of one triple pattern.
</p>

        </div3>
      </div2>
    </div1>
    <div1 id="optionals">
      <head>Including Optional Values</head>
<p>Basic graph patterns allow applications to make queries where the entire query 
pattern must match for there to be a solution. For every solution of a query containing only group graph patterns with at least one basic graph pattern, 
every variable is bound to an RDF Term in a solution. However, regular, 
complete structures cannot be assumed in all RDF graphs. It is useful to be able 
to have queries that allow information to be added to the solution where the information 
is available, but do not reject the solution because some part of the query 
pattern does not match. Optional matching provides this facility: if the optional 
part does not match, it creates no bindings but does not eliminate
the solution.</p>
      <div2 id="OptionalMatching">
        <head>Optional Pattern Matching</head>
<p>Optional parts of the graph pattern may be specified syntactically with the OPTIONAL 
keyword applied to a graph pattern:</p>
<pre class="query untested"><i>pattern</i> OPTIONAL { <i>pattern</i> }
</pre>
<div class="exampleGroup">
  <p>The syntactic form:</p>
<pre class="query untested">{ OPTIONAL { <i>pattern</i> } }
</pre>
<p>is equivalent to:</p>
<pre class="query untested">{ { } OPTIONAL { <i>pattern</i> } }
</pre>

<p>The <code>OPTIONAL</code> keyword is left-associative :</p>
<pre class="query untested"><i>pattern</i> OPTIONAL { <i>pattern</i> } OPTIONAL { pattern }
</pre>
<p>is the same as:</p>
<pre class="query untested">{ <i>pattern</i> OPTIONAL { <i>pattern</i> } } OPTIONAL { pattern }
</pre>

  <p>In an optional match, either the optional graph pattern matches a graph, thereby 
defining and adding bindings to one or more solutions, or it leaves a solution unchanged without adding 
any additional bindings.</p>
  <p>Data:</p>
  <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix rdf:        &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .

_:a  rdf:type        foaf:Person .
_:a  foaf:name       &quot;Alice&quot; .
_:a  foaf:mbox       &lt;mailto:alice@example.com&gt; .
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  rdf:type        foaf:Person .
_:b  foaf:name       &quot;Bob&quot; .
</pre>
  <div class="queryGroup">
    Query:<pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
WHERE  { ?x foaf:name  ?name .
         OPTIONAL { ?x  foaf:mbox  ?mbox }
       }
</pre>
    <p>With the data above, the query result is:</p>
    <div class="result">
      <table class="resultTable" id="table92">
        <tr>
          <th>name</th>
          <th>mbox</th>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
          <td>&lt;mailto:alice@example.com&gt;</td>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
          <td>&lt;mailto:alice@work.example&gt;</td>
        </tr>
        <tr>
          <td>&quot;Bob&quot;</td>
          <td></td>
        </tr>
      </table>
    </div>
  </div>
</div>
<p>There is no value of <code>mbox</code> in the solution where the name is
<code>&quot;Bob&quot;</code>.</p>
<p>This query finds the names of people in the data. If there is a triple with predicate
<code>mbox</code> and the same subject, a solution will contain the object of that triple 
as well. In this example, only a single triple pattern is given in the optional match 
part of the query but, in general, the optional part may be any graph pattern. The entire
optional graph pattern must match for the optional graph pattern to affect 
the query solution.</p>
      </div2>
      <div2 id="OptionalAndConstraints">
        <head>Constraints 
in Optional Pattern Matching</head>
<p>Constraints can be given in an optional graph pattern. For example:</p>
<div class="exampleGroup">
  <pre class="data">@prefix dc:   &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix :     &lt;http://example.org/book/&gt; .
@prefix ns:   &lt;http://example.org/ns#&gt; .

:book1  dc:title  &quot;SPARQL Tutorial&quot; .
:book1  ns:price  42 .
:book2  dc:title  &quot;The Semantic Web&quot; .
:book2  ns:price  23 .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  ns:  &lt;http://example.org/ns#&gt;
SELECT  ?title ?price
WHERE   { ?x dc:title ?title .
          OPTIONAL { ?x ns:price ?price . FILTER (?price &lt; 30) }
        }
</pre>
    <div class="result">
      <table class="resultTable" id="table93">
        <tr>
          <th>title</th>
          <th>price</th>
        </tr>
        <tr>
          <td>&quot;SPARQL Tutorial&quot;</td>
          <td></td>
        </tr>
        <tr>
          <td>&quot;The Semantic Web&quot;</td>
          <td>23</td>
        </tr>
      </table>
    </div>
  </div>
</div>
<p>No price appears for the book with title &quot;SPARQL Tutorial&quot; because the optional 
graph pattern did not lead to a solution involving the variable &quot;<code>price</code>&quot;.</p>
      </div2>
      <div2 id="MultipleOptionals">
        <head>Multiple Optional Graph 
Patterns</head>
<p>Graph patterns are defined recursively. A graph pattern may have zero or more 
optional graph patterns, and any part of a query pattern may have an optional part. 
In this example, there are two optional graph patterns.</p>
<div class="exampleGroup">
  Data:<pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       &quot;Alice&quot; .
_:a  foaf:homepage   &lt;http://work.example.org/alice/&gt; .

_:b  foaf:name       &quot;Bob&quot; .
_:b  foaf:mbox       &lt;mailto:bob@work.example&gt; .
</pre>
  <div class="queryGroup">
    Query:<pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox ?hpage
WHERE  { ?x foaf:name  ?name .
         OPTIONAL { ?x foaf:mbox ?mbox } .
         OPTIONAL { ?x foaf:homepage ?hpage }
       }
</pre>
    <p>Query result:</p>
    <div class="result">
      <table class="resultTable" id="table94">
        <tr>
          <th>name</th>
          <th>mbox</th>
          <th>hpage</th>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
          <td></td>
          <td>&lt;http://work.example.org/alice/&gt;</td>
        </tr>
        <tr>
          <td>&quot;Bob&quot;</td>
          <td>&lt;mailto:bob@work.example&gt;</td>
          <td></td>
        </tr>
      </table>
    </div>
  </div>
</div>

      </div2>
    </div1>
    <div1 id="alternatives">
      <head>Matching Alternatives</head>
<p>SPARQL provides a means of combining graph patterns so that one of several alternative 
graph patterns may match. If more than one of the alternatives matches, all the 
possible pattern solutions are found.</p>
<p>Pattern alternatives are syntactically specified with the <code>UNION</code> keyword.</p>
<div class="exampleGroup">
  Data:<pre class="data">@prefix dc10:  &lt;http://purl.org/dc/elements/1.0/&gt; .
@prefix dc11:  &lt;http://purl.org/dc/elements/1.1/&gt; .

_:a  dc10:title     &quot;SPARQL Query Language Tutorial&quot; .
_:a  dc10:creator   &quot;Alice&quot; .

_:b  dc11:title     &quot;SPARQL Protocol Tutorial&quot; .
_:b  dc11:creator   &quot;Bob&quot; .

_:c  dc10:title     &quot;SPARQL&quot; .
_:c  dc11:title     &quot;SPARQL (updated)&quot; .
</pre>
  <div class="queryGroup">
    Query:<pre class="query">PREFIX dc10:  &lt;http://purl.org/dc/elements/1.0/&gt;
PREFIX dc11:  &lt;http://purl.org/dc/elements/1.1/&gt;

SELECT ?title
WHERE  { { ?book dc10:title  ?title } UNION { ?book dc11:title  ?title } }
</pre>
    <p>Query result:</p>
    <div class="result">
      <table class="resultTable" id="table97">
        <tr>
          <th>title</th>
        </tr>
        <tr>
          <td>&quot;SPARQL Protocol Tutorial&quot;</td>
        </tr>
        <tr>
          <td>&quot;SPARQL&quot;</td>
        </tr>
        <tr>
          <td>&quot;SPARQL (updated)&quot;</td>
        </tr>
        <tr>
          <td>&quot;SPARQL Query Language Tutorial&quot;</td>
        </tr>
      </table>
    </div>
  </div>
  <p>This query finds titles of the books in the data, whether the title is recorded 
  using <a class="inform" href="http://dublincore.org/">Dublin Core</a> properties 
  from version 1.0 or version 1.1. To determine exactly how the information was 
  recorded, a query could use different variables for the two alternatives:</p> 
  <div class="queryGroup">
    <pre class="query">PREFIX dc10:  &lt;http://purl.org/dc/elements/1.0/&gt;
PREFIX dc11:  &lt;http://purl.org/dc/elements/1.1/&gt;

SELECT ?x ?y
WHERE  { { ?book dc10:title ?x } UNION { ?book dc11:title  ?y } }
</pre>
    <div class="result">
      <table class="resultTable" id="table98">
        <tr>
          <th>x</th>
          <th>y</th>
        </tr>
        <tr>
          <td></td>
          <td>&quot;SPARQL (updated)&quot;</td>
        </tr>
        <tr>
          <td></td>
          <td>&quot;SPARQL Protocol Tutorial&quot;</td>
        </tr>
        <tr>
          <td>&quot;SPARQL&quot;</td>
          <td></td>
        </tr>
        <tr>
          <td>&quot;SPARQL Query Language Tutorial&quot;</td>
          <td></td>
        </tr>
      </table>
    </div>
  </div>
  <p>This will return results with the variable <code>x</code> bound for solutions from the left branch of the <code>UNION</code>, and <code>y</code> bound 
  for the solutions from the right branch. If neither part of the <code>UNION</code> 
  pattern matched, then the graph pattern would not match.</p>
  <p>The <code>UNION</code> pattern combines graph patterns; each alternative possibility can contain more 
  than one triple 
  pattern:</p>
  <div class="queryGroup">
    <pre class="query">PREFIX dc10:  &lt;http://purl.org/dc/elements/1.0/&gt;
PREFIX dc11:  &lt;http://purl.org/dc/elements/1.1/&gt;

SELECT ?title ?author
WHERE  { { ?book dc10:title ?title .  ?book dc10:creator ?author }
         UNION
         { ?book dc11:title ?title .  ?book dc11:creator ?author }
       }
</pre>
    <div class="result">
      <table class="resultTable" id="table99">
        <tr>
          <th>title</th>
          <th>author</th>
        </tr>
        <tr>
          <td>&quot;SPARQL Query Language Tutorial&quot;</td>
          <td>&quot;Alice&quot;</td>
        </tr>
        <tr>
          <td>&quot;SPARQL Protocol Tutorial&quot;</td>
          <td>&quot;Bob&quot;</td>
        </tr>
      </table>
    </div>
  </div>
</div>
<p>This query will only match a book if it has both a title and creator predicate 
from the same version of Dublin Core.</p>

</div1>


<div1 id="negation">
  <head>Negation</head> 

  <p>The SPARQL query language incorporates two styles of negation, one
  based on filtering results depending on whether a graph pattern does or
  does not match in the context of the query solution being filtered, 
  and one based on removing solutions related to another pattern.</p>
 
   <div2 id="neg-pattern">
     <head>Filtering Using Graph Patterns</head>

     <p>Filtering of query solutions is done within a <code>FILTER</code> 
     expression using <code>NOT EXISTS</code> and <code>EXISTS</code>. 
     Note that the filter scope rules
     <a href="#scopeFilters">apply to the 
     whole group in which the filter appears</a>.</p>

     <div3 id="neg-notexists">
       <head>Testing For the Absence of a Pattern</head>

       <p>The <code>NOT EXISTS</code> filter expression tests whether a graph pattern does 
       not match the dataset, given the values of variables in the group graph pattern
       in which the filter occurs. It does 
       not generate any additional bindings.</p>
  
       <div class="exampleGroup">
         <p>Data:</p>

         <pre class="data">@prefix  :       &lt;http://example/&gt; .
@prefix  rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix  foaf:   &lt;http://xmlns.com/foaf/0.1/&gt; .

:alice  rdf:type   foaf:Person .
:alice  foaf:name  "Alice" .
:bob    rdf:type   foaf:Person .     </pre>
  
          <p>Query:</p>
      
          <div class="queryGroup">
            <pre class="query">PREFIX  rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; 
PREFIX  foaf:   &lt;http://xmlns.com/foaf/0.1/&gt; 

SELECT ?person
WHERE 
{
    ?person rdf:type  foaf:Person .
    FILTER NOT EXISTS { ?person foaf:name ?name }
}     </pre>
            <p>Query Result:</p>
      
            <div class="result">
              <table class="resultTable">
                <tbody><tr>
                <th>person</th>
                </tr>
                <tr>
                  <td>&lt;http://example/bob&gt;</td>
                </tr>
                </tbody>
              </table>
            </div>
          </div>
       </div>
     </div3>

     <div3 id="neg-exists">
       <head>Testing For the Presence of a Pattern</head> 

       <p>The filter expression <code>EXISTS</code> is also provided.  
       It tests whether the pattern can be found in the data;
       it does not generate any additional bindings.</p>
  
       <div class="exampleGroup">
         <p>Query:</p>
      
         <div class="queryGroup">
           <pre class="query">PREFIX  rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; 
PREFIX  foaf:   &lt;http://xmlns.com/foaf/0.1/&gt; 

SELECT ?person
WHERE 
{
    ?person rdf:type  foaf:Person .
    FILTER EXISTS { ?person foaf:name ?name }
}</pre>

           <p>Query Result:</p>
      
           <div class="result">
             <table class="resultTable">
               <tbody><tr>
               <th>person</th>
               </tr>
               <tr>
                 <td>&lt;http://example/alice&gt;</td>
               </tr>
               </tbody>
             </table>
           </div>
         </div>
       </div>
     </div3>
  </div2>

    
  <div2 id="neg-minus">
    <head>Removing Possible Solutions</head>

    <p>The other style of negation provided in SPARQL is
    <code>MINUS</code> which evaluates both its arguments, 
    then calculates solutions in the left-hand side that are not
    compatible with the solutions on the right-hand side.</p>
    
    <div class="exampleGroup">
      Data:
      <pre class="data">@prefix :       &lt;http://example/&gt; .
@prefix foaf:   &lt;http://xmlns.com/foaf/0.1/&gt; .

:alice  foaf:givenName "Alice" ;
        foaf:familyName "Smith" .

:bob    foaf:givenName "Bob" ;
        foaf:familyName "Jones" .

:carol  foaf:givenName "Carol" ;
        foaf:familyName "Smith" .</pre>
        <div class="queryGroup">
          Query:
          <pre class="query">PREFIX :       &lt;http://example/&gt;
PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT DISTINCT ?s
WHERE {
   ?s ?p ?o .
   MINUS {
      ?s foaf:givenName "Bob" .
   }
}</pre>
          <p>Results:</p>
          <div class="result">
            <table class="resultTable">
              <tr>
                <th>s</th>
              </tr>
              <tr>
              <td>&lt;http://example/carol&gt;</td>
              </tr>
              <tr>
                <td>&lt;http://example/alice&gt;</td>
              </tr>
            </table>
          </div>
        </div>
    </div>
  </div2>
    
  <div2 id="neg-notexists-minus">
    <head>Relationship and differences between NOT EXISTS and MINUS</head>
    <p><code>NOT EXISTS</code> and <code>MINUS</code> represent two ways of 
    thinking about negation, one based on
    testing whether a pattern exists in the data, given the bindings
    already determined by the query pattern,
    and one based on removing matches based on the evaluation of
    two patterns.  In some cases they can produce different answers.</p>

    <div3 id="neg-example-1">
      <head>Example: Sharing of variables</head>
    
      <pre class="data">@prefix : &lt;http://example/&gt; .
:a :b :c .</pre>

      <pre class="query">SELECT *
{ 
  ?s ?p ?o
  FILTER NOT EXISTS { ?x ?y ?z }
}</pre>
      <p>evaluates to a result set with no solutions because <code>{ ?x ?y ?z }</code>
      matches given any <code>?s ?p ?o</code>, so <code>NOT EXISTS { ?x ?y ?z }</code> 
      eliminates any solutions.</p>
      
      <div class="result">
	<table class="resultTable">
	  <tr>
	    <th>s</th>
	    <th>p</th>
	    <th>o</th>
	  </tr>
	</table>
      </div>
      
      <p>whereas with <code>MINUS</code>, there is no shared variable between the
      first part (<code>?s ?p ?o</code>) and the second (<code>?x ?y ?z</code>)
      so no bindings are eliminated.</p>
      
      <pre class="query">SELECT *
{ 
   ?s ?p ?o 
   MINUS 
     { ?x ?y ?z }
}</pre>

      <p>Results:</p>
      <div class="result">
	<table class="resultTable">
	  <tr>
	    <th>s</th>
	    <th>p</th>
	    <th>o</th>
	  </tr>
	  <tr>
	    <td>&lt;http://example/a&gt;</td>
            <td>&lt;http://example/b&gt;</td>
	    <td>&lt;http://example/c&gt;</td>
	  </tr>
	</table>
      </div>
    </div3>

    <div3 id="neg-example-2">
      <head>Example: Fixed pattern</head>

      <p>Another case is where there is a concrete pattern (no variables) in the example:</p>
      <pre class="query">PREFIX : &lt;http://example/&gt;
SELECT * 
{ 
  ?s ?p ?o 
  FILTER NOT EXISTS { :a :b :c }
}</pre>
      <p>evaluates to a result set with no query solutions:</p>
      Results:
      <div class="result">
        <table class="resultTable">
          <tr>
            <th>s</th>
            <th>p</th>
            <th>o</th>
          </tr>
        </table>
      </div>
      <p>whereas</p>
      <pre class="query">PREFIX : &lt;http://example/&gt;
SELECT * 
{ 
  ?s ?p ?o 
  MINUS { :a :b :c }
}</pre>
       <p>evaluates to result set with one query solution:</p>
       <p>Results:</p>
       <div class="result">
	 <table class="resultTable">
	   <tr>
            <th>s</th>
	    <th>p</th>
	    <th>o</th>
	   </tr>
          <tr>
	    <td>&lt;http://example/a&gt;</td>
	    <td>&lt;http://example/b&gt;</td>
	    <td>&lt;http://example/c&gt;</td>
	   </tr>
	 </table>
       </div>
       <p>because there is no match of bindings and so no solutions are eliminated.</p>
    </div3>

    <div3>
      <head>Example: Inner FILTERs</head>

      <p>Differences also arise because in a filter, variables from the group are 
      <a href="#scopeFilters">in scope</a>. In this example, the <code>FILTER</code> inside
      the <code>NOT EXISTS</code> has access to the value of ?n for the solution being considered.
      </p>

      <pre class="data">@prefix : &lt;http://example.com/&gt; .
:a :p 1 .
:a :q 1 .
:a :q 2 .

:b :p 3.0 .
:b :q 4.0 .
:b :q 5.0 .</pre>
      <p>When using <code>FILTER NOT EXISTS</code>, the test is on each possible solution to <code>?x :p ?n</code>:</p>
      <pre class="query">PREFIX : &lt;http://example.com/>
SELECT * WHERE {
        ?x :p ?n
        FILTER NOT EXISTS {
                ?x :q ?m .
                FILTER(?n = ?m)
        }
}</pre>
      <div class="result">
	<table class="resultTable">
	  <tr>
	    <th>x</th>
	    <th>n</th>
	  </tr>
	  <tr>
	    <td>&lt;http://example.com/b&gt;</td>
	    <td>3.0</td>
	  </tr>
        </table>
      </div>

      <p>whereas with <code>MINUS</code>, the <code>FILTER</code> inside the pattern does not have a value for ?n and it is always unbound:</p>

      <pre class="query">PREFIX : &lt;http://example/>
SELECT * WHERE {
        ?x :p ?n
        MINUS {
                ?x :q ?m .
                FILTER(?n = ?m)
        }
}</pre>
       <div class="result">
	 <table class="resultTable">
	   <tr>
	     <th>x</th>
	     <th>n</th>
	   </tr>
	   <tr>
	     <td>&lt;http://example.com/b&gt;</td>
            <td>3.0</td>
	   </tr>
	   <tr>
	     <td>&lt;http://example.com/a&gt;</td>
	     <td>1</td>
	   </tr>
	 </table>
       </div>
    </div3>
  </div2>

</div1>

  <div1 id="propertypaths">
    <head>Property Paths</head>
    
    <p>A property path is a possible route through a graph between two graph nodes.
    A trivial case is a property path of length exactly 1, which is a triple pattern.
    The ends of the path may be RDF terms or variables. Variables 
    can not be used as part of the path itself, only the ends. 
    </p>
    <p>
    Property paths allow for more concise expressions for
    some SPARQL basic graph patterns and they also add the ability 
    to match connectivity of two resources by an arbitrary length path.
    </p>

    <div2 id="pp-language">
      <head>Property Path Syntax</head>
      
      <p>In the description below, <i><tt>iri</tt></i> is either <a href="#QSynIRI">an IRI written
      in full or abbreviated by a prefixed name</a>, or the keyword <tt>a</tt>.
      <i><tt>elt</tt></i> is a path element, which may itself 
      be composed of path constructs.
      </p>

      <table border="1" cellspacing="0">
        <tbody>
          <tr>
            <th>Syntax Form</th>
	    <th>Property Path Expression Name</th>
            <th>Matches</th>
          </tr>
          <tr>
            <td><tt><i>iri</i></tt></td>
	    <td>PredicatePath</td>
            <td> An IRI. A path of length one.</td>
          </tr>
          <tr>
            <td><tt>^<i>elt</i></tt></td>
	    <td>InversePath</td>
            <td>Inverse path (object to subject).</td>
          </tr>
          <tr>
            <td><tt><i>elt1</i> / <i>elt2</i></tt></td>
	    <td>SequencePath</td>
            <td>A sequence path of <tt><i>elt1</i></tt> followed by <tt><i>elt2</i></tt>.</td>
          </tr>
          <tr>
            <td> <tt><i>elt1</i> | <i>elt2</i></tt></td>
	    <td>AlternativePath</td>
            <td>A alternative path of <tt><i>elt1</i></tt> or <tt><i>elt2</i></tt> (all possibilities are tried).</td>
          </tr>
          <tr>
            <td><tt><i>elt</i>*</tt></td>
	    <td>ZeroOrMorePath</td>
            <td>A path that connects the subject and object of the path by zero or more matches of <tt><i>elt</i></tt>.</td>
          </tr>

          <tr>
            <td><tt><i>elt</i>+</tt></td>
	    <td>OneOrMorePath</td>
            <td>A path that connects the subject and object of the path by one or more matches of <tt><i>elt</i></tt>.</td>
          </tr>

          <tr>
            <td><tt><i>elt</i>?</tt></td>
	    <td>ZeroOrOnePath</td>
            <td>A path that connects the subject and object of the path by zero or one matches of <tt><i>elt</i></tt>.</td>
          </tr>

          <tr>
            <td><tt>!<i>iri</i></tt> or <tt>!(<i>iri<sub>1</sub></i>| ...|<i>iri<sub>n</sub></i>)</tt></td>
	    <td>NegatedPropertySet</td>
            <td>Negated property set. An IRI which is not one of <tt><i>iri<sub>i</sub></i></tt>.
	    <tt>!<i>iri</i></tt> is short for <tt>!<i>(iri)</i></tt>.
	    </td>
          </tr>
          <tr>
            <td><tt>!^<i>iri</i></tt> or <tt>!(^<i>iri<sub>1</sub></i>| ...|^<i>iri<sub>n</sub></i>)</tt></td>
	    <td>NegatedPropertySet</td>
            <td>Negated property set where the excluded matches are based on reversed path.<br/>
	    That is, not one of <i>iri<sub>1</sub></i>...<i>iri<sub>n</sub></i> as reverse paths.
	    <tt>!^<i>iri</i></tt> is short for <tt>!(^<i>iri</i>)</tt>.
            </td>
          </tr>
          <tr>
            <td>
	    <tt>!(<i>iri<sub>1</sub></i>| ...|<i>iri<sub>j</sub></i>|^<i>iri<sub>j+1</sub></i>| ...|^<i>iri<sub>n</sub></i>)</tt></td>
	    <td>NegatedPropertySet</td>
	    <td>
	      A combination of forward and reverse properties in a negated property set.
	    </td>
          </tr>
          <tr>
            <td><tt>(<i>elt</i>)</tt></td>
	    <td>&nbsp;</td>
            <td>A group path <tt><i>elt</i></tt>, brackets control precedence.</td>
          </tr>
        </tbody>
      </table>

      <p>The order of IRIs, and reverse IRIs, in a negated property set is not significant
      and they can occur in a mixed order.</p>

      <p>The precedence of the syntax forms is, from highest to lowest:
      </p>
      <ul>
        <li>IRI, prefixed names</li>
        <li>Negated property sets</li>
        <li>Groups</li>
        <li>Unary operators <tt>*</tt>, <tt>?</tt> and <tt>+</tt></li>
        <li>Unary ^ inverse links</li>
        <li>Binary operator <tt>/</tt></li>
        <li>Binary operator <tt>|</tt></li>
      </ul>
      <p>Precedence is left-to-right within groups.</p>

    </div2>
    
    <div2 id="propertypath-examples">
      <head>Examples</head>

      <p><i>Alternatives</i>: Match one or both possibilities</p>
      <pre class="query">  { :book1 dc:title|rdfs:label ?displayString }</pre>

      <p>which could have writen: </p>

      <pre class="query">  { :book1 &lt;http://purl.org/dc/elements/1.1/title&gt; | &lt;http://www.w3.org/2000/01/rdf-schema#label&gt; ?displayString }</pre>

      <p><i>Sequence</i>: Find the name of any people that Alice knows.</p>
      <pre class="query">  {
    ?x foaf:mbox &lt;mailto:alice@example&gt; .
    ?x foaf:knows/foaf:name ?name .
  }</pre>

      <p><i>Sequence</i>: Find the names of people 2 "<tt>foaf:knows</tt>" links away.</p>
      <pre class="query">  { 
    ?x foaf:mbox &lt;mailto:alice@example&gt; .
    ?x foaf:knows/foaf:knows/foaf:name ?name .
  }</pre>

      <p>This is the same as the SPARQL query:</p>
      <pre class="query">  SELECT ?x ?name 
  {
     ?x  foaf:mbox &lt;mailto:alice@example&gt; .
     ?x  foaf:knows [ foaf:knows [ foaf:name ?name ]]. 
  }</pre>

      <p>or, with explicit variables:</p>
      <pre class="query">  SELECT ?x ?name
  {
    ?x  foaf:mbox &lt;mailto:alice@example&gt; .
    ?x  foaf:knows ?a1 .
    ?a1 foaf:knows ?a2 .
    ?a2 foaf:name ?name .
  }</pre>

      <p><i>Filtering duplicates</i>: Because someone Alice knows may well know Alice, the example above may 
      include Alice herself. This could be avoided with:
      </p>
      <pre class="query">  { ?x foaf:mbox &lt;mailto:alice@example&gt; .
    ?x foaf:knows/foaf:knows ?y .
    FILTER ( ?x != ?y )
    ?y foaf:name ?name 
  }</pre>

      <p>
	<i>Inverse Property Paths</i>: These two are the same query: the second is just reversing the property 
	direction which swaps the roles of subject and object.
      </p> 
        
      <pre class="query">  { ?x foaf:mbox &lt;mailto:alice@example&gt; }</pre>
      <pre class="query">  { &lt;mailto:alice@example&gt; ^foaf:mbox ?x }</pre>

      <p><i>Inverse Path Sequence</i>: Find all the people who know someone <tt>?x</tt> knows.</p>
      <pre class="query">  {
    ?x foaf:knows/^foaf:knows ?y .  
    FILTER(?x != ?y)
  }</pre>
      <p>which is equivalent to (<code>?gen1</code> is a system generated variable):</p>
      <pre class="query">  {
    ?x foaf:knows ?gen1 .
    ?y foaf:knows ?gen1 .  
    FILTER(?x != ?y)
  }</pre>

      <p><i>Arbitrary length match</i>: Find the names of all the people that can be reached from Alice by <tt>foaf:knows</tt>:</p>
      <pre class="query">  {
    ?x foaf:mbox &lt;mailto:alice@example&gt; .
    ?x foaf:knows+/foaf:name ?name .
  }</pre>

      <p><i>Alternatives in an arbitrary length path</i>:</p>
      <pre class="query">  { ?ancestor (ex:motherOf|ex:fatherOf)+ &lt;#me&gt; }</pre>

      <p>
	<i>Arbitrary length path match</i>: Some forms of limited inference are possible as well. 
	For example, for RDFS, all types 
      and supertypes of a resource:
      </p>
      <pre class="query">  { &lt;http://example/thing&gt; rdf:type/rdfs:subClassOf* ?type }</pre>

      <p>All resources and all their inferred types:</p>
      <pre class="query">  { ?x rdf:type/rdfs:subClassOf* ?type }</pre>

      <p><i>Subproperty</i>:</p>
      <pre class="query">  { ?x ?p ?v . ?p rdfs:subPropertyOf* :property }</pre>

      <p><i>Negated Property Paths</i>: Find nodes connected but not by rdf:type (either way round): </p>
      <pre class="query">  { ?x !(rdf:type|^rdf:type) ?y }</pre>

      <p><i>Elements in an RDF collection</i>:</p>
      <pre class="query">  { :list rdf:rest*/rdf:first ?element }</pre>
      <p><i>Note: This path expression does not guarantee the order of the results.</i></p>
    </div2>

    <div2 id="propertypath-syntaxforms">
      <head>Property Paths and Equivalent Patterns</head>

      <p>
	SPARQL property paths treat the RDF triples as a directed, possibly cyclic, graph
	with named edges. Some property paths are equivalent to a
	<a href="#sparqlTranslatePathExpressions">translation</a> into triple patterns 
	and SPARQL UNION graph patterns. Evaluation of a property path expression can lead
	to duplicates because any variables introduced in the equivalent pattern are not part
	of the results and are not already used elsewhere.  They are hidden by implicit
	projection of the results to just the variables given in the query.
      </p>
      
      <p>For example, on the data:</p>

      <pre class="data">@prefix :       &lt;http://example/> .

:order  :item :z1 .
:order  :item :z2 .

:z1 :name "Small" .
:z1 :price 5 .

:z2 :name "Large" .
:z2 :price 5 .</pre>

        <p>Query:</p>
	<pre class="query">PREFIX :   &lt;http://example/&gt;
SELECT * 
{  ?s :item/:price ?x . }</pre>
        <p>Results:</p>
	<div class="result">
	  <table class="resultTable">
	    <tr>
	      <th>s</th>
	      <th>x</th>
	    </tr>
	    <tr>
	      <td>&lt;http://example/order></td>
	      <td>5</td>
	    </tr>
	    <tr>
	      <td>&lt;http://example/order></td>
		<td>5</td>
	    </tr>
	  </table>
	</div>

	<p>whereas if the query were written out to include the intermediate variable 
	(<code>?_a</code>), no rows in the results are duplicates:</p>
	<pre class="query">PREFIX :   &lt;http://example/&gt;
SELECT * 
{  ?s :item ?_a .
   ?_a :price ?x . }</pre>
       <p>Results:</p>
       <div class="result">
	 <table class="resultTable">
	   <tr>
	     <th>s</th>
	     <th>_a</th>
	     <th>x</th>
	   </tr>
	   <tr>
	    <td>&lt;http://example/order></td>
	    <td>&lt;http://example/z1></td>
	    <td>5</td>
	   </tr>
	   <tr>
	     <td>&lt;http://example/order></td>
	     <td>&lt;http://example/z2></td>
	     <td>5</td>
	  </tr>
	 </table>
       </div>

       <p>The equivalance to graphs patterns is particularly significant
       when query also involves an aggregation operation. The total cost
       of the order can be found with
       </p> 

       <pre class="query">  PREFIX :   &lt;http://example/&gt;
  SELECT (sum(?x) AS ?total)
  { 
    :order :item/:price ?x
  }</pre>

  <div class="result">
	 <table class="resultTable">
	   <tr>
	     <th>total</th>
	   </tr>
	   <tr>
	    <td>10</td>
	   </tr>
	 </table>
       </div>

    </div2>

    <div2 id="propertypath-arbitrary-length">
      <head>Arbitrary Length Path Matching</head>

      <p>
	Connectivity between the subject and object by a property path 
	of arbitrary length can be found using the "zero or more" 
	property path operator, <code>*</code>, and the "one or more" 
	property path operator, <code>+</code>.  
	There is also a "zero or one" connectivity property path operator,
	<code>?</code>.
      </p>

      <p>
	Each of these operators uses the property path expression 
	to try to find a connection between subject and object, using the
	path step a number of times, as restricted by the operator.
      </p>
       
       <p>
	 For example, finding all the the possible types of a resource,
	 including supertypes of resources, can be achieved with:
       </p>

       <pre class="query">  PREFIX  rdfs:   &lt;http://www.w3.org/2000/01/rdf-schema#&gt; . 
  PREFIX  rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
  SELECT ?x ?type
  { 
    ?x rdf:type/rdfs:subClassOf* ?type
  }</pre>

       <p>
	 Similarly, finding all the people <code>:x</code> connects to via the
	 <code>foaf:knows</code> relationship, 
       </p>

       <pre class="query">  PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
  PREFIX :     &lt;http://example/&gt;
  SELECT ?person
  { 
    :x foaf:knows+ ?person
  }</pre>

       <p>
	 Such connectivity matching does not introduce duplicates (it does not
	 incorporate any count of the number of ways the connection can be made) even
	 if the repeated path itself would otherwise result in duplicates.
       </p>

       <p>
	 The graph matched may include cycles. Connectivity matching is defined so that
	 matching cycles does not lead to undefined or infinite results.
       </p>

    </div2>

  </div1>

  <div1 id="assignment">
    <head>Assignment</head>
    
    <p>The value of an expression can be added to a solution mapping by binding a new variable
    to the value of the expression, which is an RDF term.  
    The variable can then be used in the query and also can be returned
    in results.</p>

    <p>Three syntax forms allow this: the <a href="#assignment"><code>BIND</code> keyword</a>, 
    <a href="#selectExpressions">expressions in the
    <code>SELECT</code> clause</a> and <a href="#groupby">expressions in the <code>GROUP BY</code> clause</a>.
    The assignment form is <code>(<i>expression</i> AS ?var)</code>. 
    </p>

    <p>If the evaluation of the expression produces an error, 
    the variable remains unbound for that solution but the query evaluation continues.</p>

    <p>Data can also be directly included in a query using 
    <a href="#inline-data"><code>VALUES</code></a> for inline data.
    </p>

    <div2 id="bind">
      <head>BIND: Assigning to Variables</head>

      <p>The <code>BIND</code> form allows a value to be assigned to a variable from a  
      basic graph pattern or property path expression. Use of <code>BIND</code>
      ends the preceding basic graph pattern.  The variable introduced by
      the <code>BIND</code> clause must not have been used in the group graph 
      pattern up to the point of use in <code>BIND</code>.
      </p>

      <p>Example:</p>
      <div class="exampleGroup">
        <p>Data:</p>
        <pre class="data">@prefix dc:   &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix :     &lt;http://example.org/book/&gt; .
@prefix ns:   &lt;http://example.org/ns#&gt; .

:book1  dc:title     "SPARQL Tutorial" .
:book1  ns:price     42 .
:book1  ns:discount  0.2 .

:book2  dc:title     "The Semantic Web" .
:book2  ns:price     23 .
:book2  ns:discount  0.25 .</pre>
        <p>Query:</p>
        <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  ns:  &lt;http://example.org/ns#&gt;

SELECT  ?title ?price
{  ?x ns:price ?p .
   ?x ns:discount ?discount
   BIND (?p*(1-?discount) AS ?price)
   FILTER(?price &lt; 20)
   ?x dc:title ?title . 
}</pre>
         <p>Equivalent query (<code>BIND</code> ends the basic graph pattern;
           the <code>FILTER</code> applies to the whole group graph pattern):</p>
        <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  ns:  &lt;http://example.org/ns#&gt;

SELECT  ?title ?price
{  { ?x ns:price ?p .
     ?x ns:discount ?discount
     BIND (?p*(1-?discount) AS ?price)
   }
   {?x dc:title ?title . }
   FILTER(?price &lt; 20)
}</pre>

        <p>Results:</p>
        <div class="result">
          <table class="resultTable">
            <tr>
              <th>title</th>
              <th>price</th>
            </tr>
            <tr>
              <td>&nbsp;&quot;The Semantic Web&quot;</td>
              <td>17.25</td>
            </tr>
          </table>
        </div>
      </div>

    </div2>

    <div2 id="inline-data">
      <head>VALUES: Providing inline data</head>

      <p>Data can be directly written in a graph pattern or added to a query using
      <code>VALUES</code>.  <code>VALUES</code> provides inline data as a
      <a href="#defn_sparqlSolutionSequence">solution sequence</a>
      which are combined with the results of query evaluation by a 
      <a href="#defn_algJoin">join</a> operation. It can be used by an 
      application to provide specific requirements on query results 
      and also by SPARQL query engine implementations that provide 
      <a href="#basic-federated-query">federated query</a> through 
      the <code>SERVICE</code> keyword to send a more constrained query to a 
      remote query service.
      </p>

      <div3 id="inline-data-syntax">
	<head>VALUES syntax</head>

	<p><code>VALUES</code> allows multiple variables to be specified in the
	data block; there is a special syntax for the common case of specifying
	just one variable and some values.</p>

	<p>In the following example, there is a table of two variables, 
	<code>?x</code> and <code>?y</code>. The second row has no value for 
	<code>?y</code>.</p>
	<pre class="data">VALUES (?x ?y) {
  (:uri1 1)
  (:uri2 UNDEF)
}</pre>

        <p>Optionally, when there is a single variable and some values:</p>
	<pre class="data">VALUES ?z { "abc" "def" }</pre>

	<p>which is the same as using the general form:</p>

	<pre class="data">VALUES (?z) { ("abc") ("def") }</pre>

      </div3>

      <div3 id="inline-data-examples">
	<head>VALUES Examples</head>
	
	<p>A <code>VALUES</code> block of data can appear in a query pattern or
	at the end of a <code>SELECT</code> query, including a 
	<a href="#subqueries">subquery</a>.</p>


	<div class="exampleGroup">
	  <p>Data:</p>
	  <pre class="data">@prefix dc:   &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix :     &lt;http://example.org/book/&gt; .
@prefix ns:   &lt;http://example.org/ns#&gt; .

:book1  dc:title  "SPARQL Tutorial" .
:book1  ns:price  42 .
:book2  dc:title  "The Semantic Web" .
:book2  ns:price  23 .
</pre>
	<p>Query:</p>
	<pre class="query">PREFIX dc:   &lt;http://purl.org/dc/elements/1.1/&gt; 
PREFIX :     &lt;http://example.org/book/&gt; 
PREFIX ns:   &lt;http://example.org/ns#&gt; 

SELECT ?book ?title ?price
{
   VALUES ?book { :book1 :book3 }
   ?book dc:title ?title ;
         ns:price ?price .
}</pre>
        <p>Result:</p>
	<div class="result">
	  <table class="resultTable" id="table110">
	    <tr>
	      <th>book</th>
	      <th>title</th>
	      <th>price</th>
	    </tr>
	    <tr>
	      <td>&lt;http://example.org/book/book1&gt;</td>
	      <td>&quot;SPARQL Tutorial&quot;</td>
	      <td>42</td>
	    </tr>
	  </table>
	</div>
      </div>
      <p>If a variable has no value for a particular solution in the
      <code>VALUES</code> clause, the keyword <code>UNDEF</code> is used
      instead of an RDF term.</p>
      <pre class="query">PREFIX dc:   &lt;http://purl.org/dc/elements/1.1/&gt; 
PREFIX :     &lt;http://example.org/book/&gt; 
PREFIX ns:   &lt;http://example.org/ns#&gt; 

SELECT ?book ?title ?price
{
   ?book dc:title ?title ;
         ns:price ?price .
   VALUES (?book ?title)
   { (UNDEF "SPARQL Tutorial")
     (:book2 UNDEF)
   }
}</pre>
	<div class="result">
	  <table class="resultTable" id="table111">
	    <tr>
	      <th>book</th>
	      <th>title</th>
	      <th>price</th>
	    </tr>
	    <tr>
	      <td>&lt;http://example.org/book/book1&gt;</td>
	      <td>&quot;SPARQL Tutorial&quot;</td>
	      <td>42</td>
	    </tr>
	    <tr>
	      <td>&lt;http://example.org/book/book2&gt;</td>
	      <td>&quot;The Semantic Web&quot;</td>
	      <td>23</td>
	    </tr>
	  </table>
	</div>
	<p>In this example, the <code>VALUES</code> might have been specified
	to execute over the results of the <code>SELECT</code> query:</p>
	      <pre class="query">PREFIX dc:   &lt;http://purl.org/dc/elements/1.1/&gt; 
PREFIX :     &lt;http://example.org/book/&gt; 
PREFIX ns:   &lt;http://example.org/ns#&gt; 

SELECT ?book ?title ?price
{
   ?book dc:title ?title ;
         ns:price ?price .
}
VALUES (?book ?title)
{ (UNDEF "SPARQL Tutorial")
  (:book2 UNDEF)
}</pre>
        <p>This is a different query but, in the example situation, has the same results.</p>
      </div3>
    </div2>
  </div1>


<div1 id="aggregates">
  <head>Aggregates</head>
  <p>Aggregates apply expressions over groups of solutions. By default
a solution set consists of a single group, containing all solutions.</p>
  <p>Grouping may be specified using the <code>GROUP BY</code> syntax.</p>
  <p>Aggregates defined in version 1.1 of SPARQL are
<code>COUNT</code>, <code>SUM</code>, <code>MIN</code>, <code>MAX</code>, <code>AVG</code>, <code>GROUP_CONCAT</code>, and <code>SAMPLE</code>.</p>
  <p>Aggregates are used where the querier wishes to see a result which is computed over a group of solutions, rather than a single solution. For example the maximum value that a particular variable takes, rather than each value individually.</p>
 <div2 id="aggregateExample">
  <head>Aggregate Example</head>
  <div class="exampleGroup">
   <p>Data:</p>
   <pre class="data">@prefix : &lt;http://books.example/&gt; .

:org1 :affiliates :auth1, :auth2 .
:auth1 :writesBook :book1, :book2 .
:book1 :price 9 .
:book2 :price 5 .
:auth2 :writesBook :book3 .
:book3 :price 7 .
:org2 :affiliates :auth3 .
:auth3 :writesBook :book4 .
:book4 :price 7 .</pre>
    <p>Query:</p>
      <pre class="query">PREFIX : &lt;http://books.example/&gt;
SELECT (SUM(?lprice) AS ?totalPrice)
WHERE {
  ?org :affiliates ?auth .
  ?auth :writesBook ?book .
  ?book :price ?lprice .
}
GROUP BY ?org
HAVING (SUM(?lprice) &gt; 10)</pre>
    <p>Results:</p>
      <div class="result">        <table class="resultTable">
          <tr><th>totalPrice</th></tr>
          <tr><td>21</td></tr>
        </table>
      </div>
    </div>

    <p>This example demonstrates two features of aggregates: <code>GROUP BY</code>, which
    groups query solutions according to one or more expressions (in this case
    <code>?org</code>), and <code>HAVING</code>, which is analogous to a <code>FILTER</code> 
    expression, but operates over groups, rather than individual solutions.</p>

  <p>The example is produced by grouping solutions according to the <code>GROUP BY</code> 
    expression (i.e. all solutions where <code>?org</code> takes a particular value appear
    within the same group), and evaluating the Set Function <code>SUM</code> over that group. 
    The groups are then filtered by the <code>HAVING</code> expression, which removes 
    all groups where <code>SUM(?lprice)</code> is not greater than 10.</p>

<p>In aggregate queries and sub-queries, variables that appear in the
query pattern, but are not in the <code>GROUP BY</code> clause, can only be
projected or used in select expressions if they are aggregated. The
<code>SAMPLE</code> aggregate may be used for this purpose. For details see the
section on <a href="#aggregateRestrictions">Projection Restrictions</a>.</p>

  <p>It should be noted that <a href="#selectExpressions">as per functions</a>, aggregate expressions are required to be aliased (again, similar to the <code>BIND</code> clause, using the keyword <code>AS</code>) in order to project them from queries or subqueries. In the example above this is done using the variable <code>?totalPrice</code>. It is an error for aggregates to project variables with a name already used in other aggregate projections, or in the <code>WHERE</code> clause.</p>
  </div2>

  <div2 id="groupby"><head>GROUP BY</head>

  <p>In order to calculate aggregate values for a solution, the solution is first divided into one or more groups, and the aggregate value is calculated for each group.</p>

  <p>If aggregates are used in the query level in <code>SELECT</code>,
  <code>HAVING</code> or <code>ORDER BY</code> but the <code>GROUP BY</code> term is not used,
  then this is taken to be a single implicit group, to which all solutions belong.</p>

  <p>Within <code>GROUP BY</code> clauses the binding keyword, <code>AS</code>, may be used, such as <code>GROUP BY (?x + ?y AS ?z)</code>. This is equivalent to <code>{ ... BIND (?x + ?y AS ?z) } GROUP BY ?z</code>.</p>

    <p>For example, given a solution sequence S, ( {?x&rarr;2, ?y&rarr;3}, {?x&rarr;2, ?y&rarr;5}, {?x&rarr;6, ?y&rarr;7} ), we might wish to group the solutions according to the value of ?x, and calculate the average of the values of ?y for each group.</p>

    <p>This could be written as:</p>

    <pre class="query">SELECT (AVG(?y) AS ?avg)
WHERE {
  ?a :x ?x ;
     :y ?y .
}
GROUP BY ?x</pre>
    </div2>

    <div2 id="having" ><head>HAVING</head>

    <p><code>HAVING</code> operates over grouped solution sets, in the same way that <code>FILTER</code> operates over un-grouped ones.</p>
    <p><code>HAVING</code> expressions have the same evaluation rules as projections from
grouped queries, as described in the following section.</p>

    <p>An example of the use of <code>HAVING</code> is given below.</p>

    <pre class="query">PREFIX : &lt;http://data.example/&gt;
SELECT (AVG(?size) AS ?asize)
WHERE {
  ?x :size ?size
}
GROUP BY ?x
HAVING(AVG(?size) > 10)</pre>

<p>This will return average sizes, grouped by the subject, but only where the mean size is greater than 10.</p>
  
    </div2>

    <div2 id="aggregateRestrictions"><head>Aggregate Projection Restrictions</head>
    <p>In a query level which uses aggregates, only expressions consisting of aggregates and constants may be projected, with one exception. When <code>GROUP BY</code> is given with one or more simple expressions consisting of just a variable, those variables may be projected from the level.</p>

    <p>For example, the following query is legal as ?x is given as a <code>GROUP BY</code> term.</p>

    <pre class="query">PREFIX : &lt;http://example.com/data/#&gt;
SELECT ?x (MIN(?y) * 2 AS ?min)
WHERE {
  ?x :p ?y .
  ?x :q ?z .
} GROUP BY ?x (STR(?z))</pre>

    <p>Note that it would not be legal to project <code>STR(?z)</code> as this is not a simple variable expression. However, with <code>GROUP BY (STR(?z) AS ?strZ)</code> it would be possible to project <code>?strZ</code>.</p>

    <p>Other expressions, not using <code>GROUP BY</code> variables, or aggregates may have non-deterministic values projected from their groups using the <code>SAMPLE</code> aggregate.</p>
    </div2>

  <div2 id="aggregateExample2"><head>Aggregate Example (with errors)</head>
    <p>This section shows an example query using aggregation, which demonstrates how errors are handled in results, in the presence of aggregates.</p>
    <p>Data:</p>
    <pre class="data">@prefix : &lt;http://example.com/data/#&gt; .

:x :p 1, 2, 3, 4 .
:y :p 1, _:b2, 3, 4 .
:z :p 1.0, 2.0, 3.0, 4 .</pre>

    <p>Query:</p>

    <pre class="query">PREFIX : &lt;http://example.com/data/#&gt;
SELECT ?g (AVG(?p) AS ?avg) ((MIN(?p) + MAX(?p)) / 2 AS ?c)
WHERE {
  ?g :p ?p .
}
GROUP BY ?g</pre>

    <p>Result:</p>

    <div class="result">
      <table class="resultTable">
        <tr><th>g</th><th>avg</th><th>c</th></tr>
        <tr><td>&lt;http://example.com/data/#x&gt;</td><td>2.5</td><td>2.5</td></tr>
        <tr><td>&lt;http://example.com/data/#y&gt;</td><td></td><td></td></tr>
        <tr><td>&lt;http://example.com/data/#z&gt;</td><td>2.5</td><td>2.5</td></tr>
      </table>
    </div>

    <p>Note that the bindings for the :y group is not included in the results as the evaluation of Avg({1, _:b2, 3, 4}), and (_:b2 + 4) / 2 is an error, removing the bindings from the solution.</p>
  </div2>
</div1>

<div1 id="subqueries">
 <head>Subqueries</head>

  <p>Subqueries are a way to embed SPARQL queries within other queries, normally to achieve results which cannot otherwise be achieved, such as limiting the number of results from some sub-expression within the query.</p>
  <p>Due to the bottom-up nature of SPARQL query evaluation, the subqueries are evaluated logically first, and the results are projected up to the outer query.</p>
  <p>Note that only variables projected out of the subquery will be visible, or 
  <a href="#variableScope">in scope</a>,
  to the outer query.</p>
     <h3 id="subquery-example">Example</h3>

    <p>Data:</p>
    <div class="exampleGroup">
    <pre class="data">@prefix : &lt;http://people.example/&gt; .

:alice :name "Alice", "Alice Foo", "A. Foo" .
:alice :knows :bob, :carol .
:bob :name "Bob", "Bob Bar", "B. Bar" .
:carol :name "Carol", "Carol Baz", "C. Baz" .</pre>
    <p>Return a name (the one with the lowest sort order) for all the people that know Alice and have a name.</p>
    <p>Query:</p>
    <pre class="query">PREFIX : &lt;http://people.example/&gt;
PREFIX : &lt;http://people.example/&gt;
SELECT ?y ?minName
WHERE {
  :alice :knows ?y .
  {
    SELECT ?y (MIN(?name) AS ?minName)
    WHERE {
      ?y :name ?name .
    } GROUP BY ?y
  }
}</pre>
    </div>
    <p>Results:</p>
    <div class="result">
      <table class="resultTable">
        <tbody>
          <tr><th>y</th><th>minName</th></tr>
          <tr><td>:bob</td><td>"B. Bar"</td></tr>
          <tr><td>:carol</td><td>"C. Baz"</td></tr>
        </tbody>
      </table>
    </div>

    <p>This result is achieved by first evaluating the inner query:</p>

    <pre class="query">SELECT ?y (MIN(?name) AS ?minName)
WHERE {
  ?y :name ?name .
} GROUP BY ?y</pre>

    <p>This produces the following solution sequence:</p>

    <div class="result">
      <table class="resultTable">
        <tbody>
          <tr><th>y</th><th>minName</th></tr>
          <tr><td>:alice</td><td>"A. Foo"</td></tr>
          <tr><td>:bob</td><td>"B. Bar"</td></tr>
          <tr><td>:carol</td><td>"C. Baz"</td></tr>
        </tbody>
      </table>
    </div>

    <p>Which is joined with the results of the outer query:</p>

    <div class="result">
      <table class="resultTable">
        <tbody>
          <tr><th>y</th></tr>
          <tr><td>:bob</td></tr>
          <tr><td>:carol</td></tr>
        </tbody>
      </table>
    </div>

</div1>


<div1 id="rdfDataset">
      <head>RDF Dataset</head>
<p>The RDF data model expresses information as graphs consisting of triples with 
subject, predicate and object. Many RDF data stores hold multiple RDF graphs and 
record information about each graph, allowing an application to make queries that 
involve information from more than one graph.</p>
<p>A SPARQL query is executed against an <em>RDF Dataset</em> which represents a 
collection of graphs. An RDF Dataset comprises one graph, the default graph, which 
does not have a name, and zero or more named graphs, where each named graph is identified by 
an IRI. A SPARQL 
query can match different parts of the query pattern against different graphs as 
described in section <a href="#queryDataset">13.3 Querying the Dataset</a>. </p>
<p>An RDF Dataset may contain zero named graphs; an RDF Dataset always contains one default graph. 
A query does not need to involve 
matching the default graph; the query can just involve matching named graphs.</p>
<p>The graph that is used for matching a basic graph pattern is the <i>active 
graph</i>. In the previous sections, all queries have been shown executed 
against a single graph, the default graph of an RDF dataset as the active graph. 
The <code>GRAPH</code> keyword is used to make the active graph one of all of 
the named graphs in the dataset for part of the query.</p>
      <div2 id="exampleDatasets">
        <head>Examples of RDF Datasets</head>
<p>The definition of RDF Dataset does not restrict the relationships of named and 
default graphs. Information can be repeated in different graphs; relationships between 
graphs can be exposed. Two useful arrangements are:</p>
<ul>
  <li>to have information in the default graph that includes provenance information 
  about the named graphs</li>
  <li>to include the information in the named graphs in the default graph as well.</li>
</ul>
<div class="exampleGroup">
  <b>Example 1:</b><pre class="data"># <b>Default graph</b>
@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt; .

&lt;http://example.org/bob&gt;    dc:publisher  &quot;Bob&quot; .
&lt;http://example.org/alice&gt;  dc:publisher  &quot;Alice&quot; .
</pre>
  <pre class="data"># <b>Named graph: http://example.org/bob</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Bob&quot; .
_:a foaf:mbox &lt;mailto:bob@oldcorp.example.org&gt; .
</pre>
  <pre class="data"># <b>Named graph: http://example.org/alice</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a foaf:mbox &lt;mailto:alice@work.example.org&gt; .
</pre>
</div>
<p>In this example, the default graph contains the names of the publishers of two 
named graphs. The triples in the named graphs are not visible in the default graph 
in this example.</p>
<p id="ex_2"><b>Example 2:</b></p>
<p>RDF data can be combined by the
<a class="norm" href="http://www.w3.org/TR/rdf-mt/#graphdefs">RDF merge</a>
[<a href="#RDF-MT">RDF-MT</a>] of graphs. One possible arrangement of graphs in 
an RDF Dataset is to have the default graph be the RDF merge of some or all of 
the information in the named graphs.</p>
<p>In this next example, the named graphs contain the same triples as before. The 
RDF dataset includes an RDF merge of the named graphs in the default graph, re-labeling 
blank nodes to keep them distinct.</p>
<div class="exampleGroup">
  <pre class="data"># <b>Default graph</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:x foaf:name &quot;Bob&quot; .
_:x foaf:mbox &lt;mailto:bob@oldcorp.example.org&gt; .

_:y foaf:name &quot;Alice&quot; .
_:y foaf:mbox &lt;mailto:alice@work.example.org&gt; .
</pre>
  <pre class="data"># <b>Named graph: http://example.org/bob</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Bob&quot; .
_:a foaf:mbox &lt;mailto:bob@oldcorp.example.org&gt; .
</pre>
  <pre class="data"># <b>Named graph: http://example.org/alice</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a foaf:mbox &lt;<a href="mailto:alice@work.example">mailto:alice@work.example</a>&gt; .</pre>
  <p>In an RDF merge, blank nodes in the merged graph are not shared with blank 
  nodes from the graphs being merged.</p>
</div>
      </div2>
      <div2 id="specifyingDataset">
        <head>Specifying RDF Datasets</head>
<p>A SPARQL query may specify the dataset to be used for matching by using the
<code>FROM</code> clause and the <code>FROM NAMED</code> clause to describe the 
RDF dataset. If a query provides such a dataset description, then it is used in 
place of any dataset that the query service would use if no dataset description 
is provided in a query. The RDF dataset may also be
<a class="inform" href="http://www.w3.org/TR/sparql11-protocol/">
specified in a SPARQL protocol request</a>, in which case the protocol description 
overrides any description in the query itself. A query service may refuse a query 
request if the dataset description is not acceptable to the service.</p>
<p>The <code>FROM</code> and <code>FROM NAMED</code> keywords allow a query to specify 
an RDF dataset by reference; they indicate that the dataset should include graphs 
that are obtained from representations of the resources identified by the given 
IRIs (i.e. the absolute form of the given IRI references). The dataset resulting 
from a number of <code>FROM</code> and <code>FROM NAMED</code> clauses is:</p>
<ul>
  <li>a default graph consisting of the RDF merge of the graphs referred to in the
  <code>FROM</code> clauses, and</li>
  <li>a set of (IRI, graph) pairs, one from each <code>FROM NAMED</code> clause.</li>
</ul>
<p>If there is no <code>FROM</code> clause, but there is one or more <code>FROM NAMED</code> 
clauses, then the dataset includes an empty graph for the default graph.</p>

        <div3 id="unnamedGraph">
          <head>Specifying the Default Graph</head>
<p>Each <code>FROM</code> clause contains an IRI that indicates a graph to be 
used to form the default graph. This does not put the graph in as a named graph.</p>
<p>In this example, the RDF Dataset contains a single default graph and no named graphs:</p>
<div class="exampleGroup">
  <pre class="data"><b># Default graph (located at http://example.org/foaf/aliceFoaf)
</b>@prefix  foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name     &quot;Alice&quot; .
_:a  foaf:mbox     &lt;mailto:alice@work.example&gt; .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT  ?name
FROM    &lt;http://example.org/foaf/aliceFoaf&gt;
WHERE   { ?x foaf:name ?name }
</pre>
    <div class="result">
      <table class="resultTable" id="table102">
        <tr>
          <th>name</th>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
      </table>
    </div>
  </div>
</div>
<p>If a query provides more than one <code>FROM</code> clause, providing more than 
one IRI to indicate the default graph, then the default graph is the
<a class="norm" href="http://www.w3.org/TR/rdf-mt/#graphdefs">RDF merge</a> of the 
graphs obtained from representations of the resources identified by the given IRIs.</p>
        </div3>
        <div3 id="namedGraphs">
          <head>Specifying Named Graphs</head>
<p>A query can supply IRIs for the named graphs in the RDF Dataset using the
<code>FROM NAMED</code> clause. Each IRI is used to provide one named graph in the 
RDF Dataset. Using the same IRI in two or more <code>FROM NAMED</code> clauses results 
in one named graph with that IRI appearing in the dataset.</p>
<pre class="data"><b># Graph: http://example.org/bob</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Bob&quot; .
_:a foaf:mbox &lt;mailto:bob@oldcorp.example.org&gt; .
</pre>
<pre class="data"><b># Graph: http://example.org/alice</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a foaf:mbox &lt;mailto:alice@work.example&gt; .
</pre>
<div class="queryGroup">
  <pre class="query">...
FROM NAMED &lt;http://example.org/alice&gt;
FROM NAMED &lt;http://example.org/bob&gt;
...</pre>
</div>
<p>The <code>FROM NAMED</code> syntax suggests that the IRI identifies the corresponding 
graph, but the relationship between an IRI and a graph in an RDF dataset 
is indirect. The IRI identifies a resource, and the resource is represented by a 
graph (or, more precisely: by a document that serializes a graph). For
<a class="inform" href="http://www.w3.org/TR/webarch/#intro">further details</a> 
see [<a href="#WEBARCH">WEBARCH</a>].</p>
        </div3>
        <div3 id="specDataset">
          <head>Combining FROM and FROM NAMED</head>
<p>The <code>FROM</code> clause and <code>FROM NAMED</code> clause can be used in 
the same query.</p>
<div class="exampleGroup">
  <pre class="data"># <b>Default graph (located at http://example.org/dft.ttl)
</b>@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt; .

&lt;http://example.org/bob&gt;    dc:publisher  &quot;Bob Hacker&quot; .
&lt;http://example.org/alice&gt;  dc:publisher  &quot;Alice Hacker&quot; .
</pre>
  <pre class="data"># <b>Named graph: http://example.org/bob</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Bob&quot; .
_:a foaf:mbox &lt;mailto:bob@oldcorp.example.org&gt; .
</pre>
  <pre class="data"># <b>Named graph: http://example.org/alice</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a foaf:mbox &lt;mailto:alice@work.example.org&gt; .
</pre>
    <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;

SELECT ?who ?g ?mbox
FROM &lt;http://example.org/dft.ttl&gt;
FROM NAMED &lt;http://example.org/alice&gt;
FROM NAMED &lt;http://example.org/bob&gt;
WHERE
{
   ?g dc:publisher ?who .
   GRAPH ?g { ?x foaf:mbox ?mbox }
}
</pre>
</div>
<p>The RDF Dataset for this query contains a default graph and two named graphs. 
The <code>GRAPH</code> keyword is described below.</p>

<p>The actions required to construct the dataset are not determined by the
dataset description alone.  If an IRI is given twice in a dataset
description, either by using two <code>FROM</code> clauses, or a <code>FROM</code> clause and a
<code>FROM NAMED</code> clause, then it does not assume that exactly one or exactly
two attempts are made to obtain an RDF graph associated with the IRI.
Therefore, no assumptions can be made about blank node identity in
triples obtained from the two occurrences in the dataset description.
In general, no assumptions can be made about the equivalence of the graphs.
</p>
        </div3>
      </div2>
      <div2 id="queryDataset">
        <head>Querying the Dataset</head>
<p>When querying a collection of graphs, the <code>GRAPH</code> keyword is used 
to match patterns against named graphs. <code>GRAPH</code> can provide an IRI to select 
one graph or use a variable which will range over the IRI of all the named graphs in the query's RDF dataset.</p>
<p>The use of <code>GRAPH</code> changes the active graph for matching
graph patterns within that part of the query. Outside the use of <code>GRAPH</code>, 
matching is done using the default graph.</p>
<p>The following two graphs will be used in examples:</p>
<div class="exampleGroup">
  <pre class="data"><b># Named graph: http://example.org/foaf/aliceFoaf
</b>@prefix  foaf:     &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix  rdf:      &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix  rdfs:     &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .

_:a  foaf:name     &quot;Alice&quot; .
_:a  foaf:mbox     &lt;mailto:alice@work.example&gt; .
_:a  foaf:knows    _:b .

_:b  foaf:name     &quot;Bob&quot; .
_:b  foaf:mbox     &lt;mailto:bob@work.example&gt; .
_:b  foaf:nick     &quot;Bobby&quot; .
_:b  rdfs:seeAlso  &lt;http://example.org/foaf/bobFoaf&gt; .

&lt;http://example.org/foaf/bobFoaf&gt;
     rdf:type      foaf:PersonalProfileDocument .
</pre>
  <pre class="data"><b># Named graph: http://example.org/foaf/bobFoaf
</b>@prefix  foaf:     &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix  rdf:      &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix  rdfs:     &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .

_:z  foaf:mbox     &lt;mailto:bob@work.example&gt; .
_:z  rdfs:seeAlso  &lt;http://example.org/foaf/bobFoaf&gt; .
_:z  foaf:nick     &quot;Robert&quot; .

&lt;http://example.org/foaf/bobFoaf&gt;
     rdf:type      foaf:PersonalProfileDocument .
</pre>
</div>

          <div3 id="accessByLabel">
          <head>Accessing Graph Names</head>
  <p>The query below matches the graph pattern against each of the named graphs in the 
  dataset and forms solutions which have the <code>src</code> variable bound to 
  IRIs of the graph being matched. The graph pattern is matched with the active 
  graph being each of the named graphs in the dataset. </p>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT ?src ?bobNick
FROM NAMED &lt;http://example.org/foaf/aliceFoaf&gt;
FROM NAMED &lt;http://example.org/foaf/bobFoaf&gt;
WHERE
  {
    GRAPH ?src
    { ?x foaf:mbox &lt;mailto:bob@work.example&gt; .
      ?x foaf:nick ?bobNick
    }
  }
</pre>
    <p>The query result gives the name of the graphs where the information was found 
    and the value for Bob&#39;s nick:</p>
    <div class="result">
      <table class="resultTable" id="table105">
        <tr>
          <th>src</th>
          <th>bobNick</th>
        </tr>
        <tr>
          <td>&lt;http://example.org/foaf/aliceFoaf&gt;</td>
          <td>&quot;Bobby&quot;</td>
        </tr>
        <tr>
          <td>&lt;http://example.org/foaf/bobFoaf&gt;</td>
          <td>&quot;Robert&quot;</td>
        </tr>
      </table>
    </div>
  </div>
        </div3>
          <div3 id="restrictByLabel">
          <head>Restricting by Graph 
  IRI</head>
  <p>The query can restrict the matching applied to a specific graph by supplying 
  the graph IRI. This sets the active graph to the graph named by the IRI. This query looks for Bob&#39;s nick as given in the graph <code>http://example.org/foaf/bobFoaf</code>.</p>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX data: &lt;http://example.org/foaf/&gt;

SELECT ?nick
FROM NAMED &lt;http://example.org/foaf/aliceFoaf&gt;
FROM NAMED &lt;http://example.org/foaf/bobFoaf&gt;
WHERE
  {
     GRAPH data:bobFoaf {
         ?x foaf:mbox &lt;mailto:bob@work.example&gt; .
         ?x foaf:nick ?nick }
  }
</pre>
    <p>which yields a single solution:</p>
    <div class="result">
      <table class="resultTable" id="table106">
        <tr>
          <th>nick</th>
        </tr>
        <tr>
          <td>&quot;Robert&quot;</td>
        </tr>
      </table>
    </div>
  </div>
        </div3>
          <div3 id="restrictInQuery">
          <head>Restricting Possible Graph IRIs</head>
  <p>A variable used in the <code>GRAPH</code> clause may also be used in another
  <code>GRAPH</code> clause or in a graph pattern matched against the default graph 
  in the dataset.</p>
  <p>The query below uses the graph 
  with IRI <code>http://example.org/foaf/aliceFoaf</code> to find the profile document 
  for Bob; it then matches another pattern against that graph. The pattern in the 
  second <code>GRAPH</code> clause finds the blank node (variable <code>w</code>) 
  for the person with the same mail box (given by variable <code>mbox</code>) as 
  found in the first <code>GRAPH</code> clause (variable <code>whom</code>), because 
  the blank node used to match for variable <code>whom</code> from Alice&#39;s FOAF 
  file is not the same as the blank node in the profile document (they are in different 
  graphs).</p>
  <div class="queryGroup">
    <pre class="query">PREFIX  data:  &lt;http://example.org/foaf/&gt;
PREFIX  foaf:  &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX  rdfs:  &lt;http://www.w3.org/2000/01/rdf-schema#&gt;

SELECT ?mbox ?nick ?ppd
FROM NAMED &lt;http://example.org/foaf/aliceFoaf&gt;
FROM NAMED &lt;http://example.org/foaf/bobFoaf&gt;
WHERE
{
  GRAPH data:aliceFoaf
  {
    ?alice foaf:mbox &lt;mailto:alice@work.example&gt; ;
           foaf:knows ?whom .
    ?whom  foaf:mbox ?mbox ;
           rdfs:seeAlso ?ppd .
    ?ppd  a foaf:PersonalProfileDocument .
  } .
  GRAPH ?ppd
  {
      ?w foaf:mbox ?mbox ;
         foaf:nick ?nick
  }
}
</pre>
    <div class="result">
      <table class="resultTable" id="table107">
        <tr>
          <th>mbox</th>
          <th>nick</th>
          <th>ppd</th>
        </tr>
        <tr>
          <td>&lt;mailto:bob@work.example&gt;</td>
          <td>&quot;Robert&quot;</td>
          <td>&lt;http://example.org/foaf/bobFoaf&gt;</td>
        </tr>
      </table>
    </div>
  </div>
        </div3>

<p>Any triple in Alice&#39;s FOAF file giving Bob&#39;s <code>nick</code> is not used to 
provide a nick for Bob because the pattern involving variable <code>nick</code> 
is restricted by <code>ppd</code> to a particular Personal Profile Document.</p>
        <div3 id="namedAndDefaultGraph">
          <head>Named and Default 
Graphs</head>
<p>Query patterns can involve both the default graph and the named graphs. In this 
example, an aggregator has read in a Web resource on two different occasions. Each 
time a graph is read into the aggregator, it is given an IRI by the local system. 
The graphs are nearly the same but the email address for &quot;Bob&quot; has changed.</p>
<p>In this example, the default graph is being used to record the provenance information and the 
RDF data actually read is kept in two separate graphs, each of which is given a 
different IRI by the system. The RDF dataset consists of two named graphs and the 
information about them.</p>
<p>RDF Dataset:</p>
<div class="exampleGroup">
  <pre class="data"># <b>Default graph</b>
@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix g:  &lt;tag:example.org,2005-06-06:&gt; .
@prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; .

g:graph1 dc:publisher &quot;Bob&quot; .
g:graph1 dc:date &quot;2004-12-06&quot;^^xsd:date .

g:graph2 dc:publisher &quot;Bob&quot; .
g:graph2 dc:date &quot;2005-01-10&quot;^^xsd:date .
</pre>
  <pre class="data"># <b>Graph: locally allocated IRI: tag:example.org,2005-06-06:graph1</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a foaf:mbox &lt;mailto:alice@work.example&gt; .

_:b foaf:name &quot;Bob&quot; .
_:b foaf:mbox &lt;mailto:bob@oldcorp.example.org&gt; .
</pre>
  <pre class="data"># <b>Graph: locally allocated IRI: tag:example.org,2005-06-06:graph2</b>
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a foaf:mbox &lt;mailto:alice@work.example&gt; .

_:b foaf:name &quot;Bob&quot; .
_:b foaf:mbox &lt;mailto:bob@newcorp.example.org&gt; .
</pre>
  <p>This query finds email addresses, detailing the name of the person and the 
  date the information was discovered.</p>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX dc:   &lt;http://purl.org/dc/elements/1.1/&gt;

SELECT ?name ?mbox ?date
WHERE
  {  ?g dc:publisher ?name ;
        dc:date ?date .
    GRAPH ?g
      { ?person foaf:name ?name ; foaf:mbox ?mbox }
  }
</pre>
    <p>The results show that the email address for &quot;Bob&quot; has changed.</p>
    <div class="result">
      <table class="resultTable" id="table108">
        <tr>
          <th>name</th>
          <th>mbox</th>
          <th>date</th>
        </tr>
        <tr>
          <td>&quot;Bob&quot;</td>
          <td>&lt;mailto:bob@oldcorp.example.org&gt;</td>
          <td>&quot;2004-12-06&quot;^^xsd:date</td>
        </tr>
        <tr>
          <td>&quot;Bob&quot;</td>
          <td>&lt;mailto:bob@newcorp.example.org&gt;</td>
          <td>&quot;2005-01-10&quot;^^xsd:date</td>
        </tr>
      </table>
    </div>
  </div>
</div>
        </div3>
      </div2>
    </div1>

    <div1 id="basic-federated-query">
      <head>Basic Federated Query</head>

      <p>This document incorporates the syntax for SPARQL federation extensions.</p>
      
      <p>This feature is defined in the document 
      <a href="http://www.w3.org/TR/sparql11-federated-query/">SPARQL 1.1 Federated Query</a>.</p>

    </div1>

    <div1 id="solutionModifiers">
      <head>Solution Sequences and Modifiers</head>
<p>Query patterns generate an unordered collection of solutions, each
<a href="#defn_sparqlSolutionMapping">solution</a> being a partial function from variables to RDF terms. 
These solutions are then treated as a sequence (a solution sequence), initially in no specific order; 
any sequence modifiers are then applied to create another sequence. Finally, this 
latter sequence is used to generate one of the results of a
<a href="#QueryForms">SPARQL query form</a>.</p>
<p>A <span class="definedTerm">solution sequence modifier</span> is one of:</p>
<ul>
  <li><a href="#modOrderBy">Order</a> modifier: put the solutions in order</li>
  <li><a href="#modProjection">Projection</a> modifier: choose certain 
  variables</li>
  <li><a href="#modDistinct">Distinct</a> modifier: ensure solutions in the 
  sequence are unique</li>
  <li><a href="#modReduced">Reduced</a> modifier: permit elimination of some non-distinct solutions</li>
  <li><a href="#modOffset">Offset</a> modifier: control where the solutions 
  start from in the overall sequence of solutions</li>
  <li><a href="#modResultLimit">Limit</a> modifier: restrict the number of solutions</li>
</ul>
<p>Modifiers are applied in the order given by the list above.</p>
      <div2 id="modOrderBy">
        <head>ORDER BY</head>

<p>The <code>ORDER BY</code> clause establishes the order of a solution sequence.</p>

<p>Following the <code>ORDER BY</code> clause is a sequence of order comparators, composed of an expression and an optional order modifier (either <code>ASC()</code> or <code>DESC()</code>). Each ordering comparator is either ascending (indicated by the <code>ASC()</code> modifier or by no modifier) or descending (indicated by the <code>DESC()</code> modifier).</p>

<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT ?name
WHERE { ?x foaf:name ?name }
ORDER BY ?name
</pre>
  </div>
</div>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX     :    &lt;http://example.org/ns#&gt;
PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT ?name
WHERE { ?x foaf:name ?name ; :empId ?emp }
ORDER BY DESC(?emp)
</pre>
  </div>
</div>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX     :    &lt;http://example.org/ns#&gt;
PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT ?name
WHERE { ?x foaf:name ?name ; :empId ?emp }
ORDER BY ?name DESC(?emp)
</pre>
  </div>
</div>

<p>The <a href="#op_lt">&quot;&lt;&quot; operator</a> (see the <a href="#OperatorMapping">Operator Mapping</a> and <a href="#operatorExtensibility">17.3.1 Operator Extensibility</a>) defines 
the relative order of pairs of <code>numerics</code>, <code>simple literals</code>, <code>xsd:strings</code>, <code>xsd:booleans</code> 
and <code>xsd:dateTimes</code>. Pairs of IRIs are ordered by comparing them as <code>simple literals</code>.</p>

<p>SPARQL also fixes an order between some kinds of RDF terms that would not otherwise be ordered:</p>
<ol>
  <li>(Lowest) no value assigned to the variable or expression in this solution.</li>
  <li>Blank nodes</li>
  <li>IRIs</li>
  <li>RDF literals</li>
</ol>
    
    <p>A plain literal is lower than an RDF literal with type <code>xsd:string</code> of the same lexical form.</p>

    <p>SPARQL does not define a total ordering of all possible RDF terms. Here are a few examples of pairs of terms for which the relative order is undefined:</p>

    <ul>
      <li>"a" and "a"@en_gb (a simple literal and a literal with a language tag)</li>
      <li>"a"@en_gb and "b"@en_gb (two literals with language tags)</li>
      <li>"a" and "1"^^xsd:integer (a simple literal and a literal with a supported datatype)</li>
      <li>"1"^^my:integer and "2"^^my:integer (two unsupported datatypes)</li>
      <li>"1"^^xsd:integer and "2"^^my:integer (a supported datatype and an unsupported datatype)</li>
    </ul>

    <p>This list of variable bindings is in ascending order:</p>

    <div class="result">
    <table class="resultTable">
      <thead>
  <tr><th>RDF Term</th><th>Reason</th></tr>
      </thead>
      <tbody>
  <tr><td></td><td>Unbound results sort earliest.</td></tr>
  <tr><td><code>_:z</code></td><td>Blank nodes follow unbound.</td></tr>
  <tr><td><code>_:a</code></td><td>There is no relative ordering of blank nodes.</td></tr>
  <tr><td><code>&lt;http://script.example/Latin&gt;</code></td><td>IRIs follow blank nodes.</td></tr>
  <tr><td><code>&lt;http://script.example/&#1050;&#1080;&#1088;&#1080;&#1083;&#1083;&#1080;&#1094;&#1072;&gt;</code></td><td>The character in the 23rd position, "&#1050;", has a unicode codepoint 0x41A, which is higher than 0x4C ("L").</td></tr>
  <tr><td><code>&lt;http://script.example/&#28450;&#23383;&gt;  </code></td><td>The character in the 23rd position, "&#28450;", has a unicode codepoint 0x6F22, which is higher than 0x41A ("&#1050;").</td></tr>
  <tr><td><code>"http://script.example/Latin"</code></td><td>Simple literals follow IRIs.</td></tr>
  <tr><td><code>"http://script.example/Latin"^^xsd:string</code></td><td>xsd:strings follow simple literals.</td></tr>
      </tbody>
    </table>
    </div>

<p>The ascending order of two solutions with respect to an ordering comparator is established by substituting the solution bindings into the expressions and comparing them with the <a href="#op_lt">"&lt;" operator</a>. The descending order is the reverse of the ascending order.</p>

<p>The relative order of two solutions is the relative order of the two solutions with respect to the first ordering comparator in the sequence. For solutions where the substitutions of the solution bindings produce the same RDF term, the order is the relative order of the two solutions with respect to the next ordering comparator. The relative order of two solutions is undefined if no order expression evaluated for the two solutions produces distinct RDF terms.</p>

<p>Ordering a sequence of solutions always results in a sequence with the same number 
of solutions in it.</p>

<p>Using <code>ORDER BY</code> on a solution sequence for a <code>CONSTRUCT</code> or
<code>DESCRIBE</code> query has no direct effect because only <code>SELECT</code> returns 
a sequence of results. Used in combination with <code>LIMIT</code> and <code>OFFSET</code>, 
<code>ORDER BY</code> can be used to return results generated from a different slice of the solution sequence.
An <code>ASK</code> query does not include <code>ORDER BY</code>, <code>LIMIT</code> or <code>OFFSET</code>.
</p>

      </div2>
      <div2 id="modProjection">
        <head>Projection</head>
<p>The solution sequence can be transformed into one involving only a subset of 
the variables. For each solution in the sequence, a new solution is formed using 
a specified selection of the variables using the SELECT query form.</p>
<p>The following example shows a query to extract just the names of people described 
in an RDF graph using FOAF properties.</p>
<div class="exampleGroup">
  <pre class="data">@prefix foaf:        &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       &quot;Alice&quot; .
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  foaf:name       &quot;Bob&quot; .
_:b  foaf:mbox       &lt;mailto:bob@work.example&gt; .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:       &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name
WHERE
 { ?x foaf:name ?name }
</pre>
    <div class="result">
      <table class="resultTable">
        <tr>
          <th>name</th>
        </tr>
        <tr>
          <td>&quot;Bob&quot;</td>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
      </table>
    </div>
  </div>
</div>

      </div2>
      <div2 id="modDuplicates">
        <head>Duplicate Solutions</head>

<p>A solution sequence with no <code>DISTINCT</code> or <code>REDUCED</code> query modifier 
will preserve duplicate solutions.</p>

<div class="exampleGroup">
  <p>Data:</p>
  <pre class="data">@prefix  foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .

_:x    foaf:name   &quot;Alice&quot; .
_:x    foaf:mbox   &lt;mailto:alice@example.com&gt; .

_:y    foaf:name   &quot;Alice&quot; .
_:y    foaf:mbox   &lt;mailto:asmith@example.com&gt; .

_:z    foaf:name   &quot;Alice&quot; .
_:z    foaf:mbox   &lt;mailto:alice.smith@example.com&gt; .
</pre>
  <div class="queryGroup">
    <p>Query:</p>
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name WHERE { ?x foaf:name ?name }
</pre>
    <div class="result">
      <p>Results:</p>
      <table class="resultTable">
        <tr>
          <th>name</th>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
      </table>
    </div>
  </div>

      <p>The modifiers <code>DISTINCT</code> and <code>REDUCED</code> affect whether duplicates are included in the query results.</p>

        <div3 id="modDistinct">
          <head>DISTINCT</head>

<p>The <code>DISTINCT</code> solution modifier eliminates duplicate solutions.
Only one solution solution that binds the same variables to the same RDF terms is returned from the query.</p>


  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT DISTINCT ?name WHERE { ?x foaf:name ?name }
</pre>
    <div class="result">
      <table class="resultTable">
        <tr>
          <th>name</th>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
      </table>
    </div>
  </div>
<p id="defunSELECT">Note that, per the <a href="#solutionModifiers">order of solution sequence modifiers</a>, duplicates are eliminated before either limit or offset is applied.</p>

        </div3>
        <div3 id="modReduced">
          <head>REDUCED</head>
    <p>While the <code>DISTINCT</code> modifier ensures that duplicate solutions are eliminated from the solution set, <code>REDUCED</code> simply permits them to be eliminated. The cardinality of any set of variable bindings in a <code>REDUCED</code> solution set is at least one and not more than the cardinality of the solution set with no <code>DISTINCT</code> or <code>REDUCED</code> modifier. For example, using the data above, the query</p>

  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT REDUCED ?name WHERE { ?x foaf:name ?name }
</pre>
<p>may have one, two (shown here) or three solutions:</p>
    <div class="result">
      <table class="resultTable">
        <tr>
          <th>name</th>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
        <tr>
          <td>&quot;Alice&quot;</td>
        </tr>
      </table>
    </div>
  </div>
        </div3>
</div>

      </div2>
      <div2 id="modOffset">
        <head>OFFSET</head>
<p><code>OFFSET</code> causes the solutions generated to start after the specified 
number of solutions. An <code>OFFSET</code> of zero has no effect.</p>
<p>Using <code>
LIMIT</code> and <code>OFFSET</code> to select different subsets of the query solutions 
will not be useful unless the order is made predictable by using <code>ORDER BY</code>.</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT  ?name
WHERE   { ?x foaf:name ?name }
ORDER BY ?name
LIMIT   5
OFFSET  10</pre>
  </div>
</div>

      </div2>
      <div2 id="modResultLimit">
        <head>LIMIT</head>
<p>The <code>LIMIT</code> clause puts an upper bound on the number of solutions returned. If the 
number of actual solutions, after <code>OFFSET</code> is applied, is greater than the limit, 
then at most the limit number of solutions will be returned.</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT ?name
WHERE { ?x foaf:name ?name }
LIMIT 20
</pre>
  </div>
</div>
<p>A <code>LIMIT</code> of 0 would cause no results to be returned. A limit may not be negative.</p>


      </div2>
    </div1>
    <div1 id="QueryForms">
      <head>Query Forms</head>
<p>SPARQL has four query forms. These query forms use the solutions from 
pattern matching to form result sets or RDF graphs. The query forms are:</p>
<blockquote>
  <dl>
    <dt><a href="#select">SELECT</a></dt>
    <dd>Returns all, or a subset of, the variables bound in a query pattern match.</dd>
    <dt><a href="#construct">CONSTRUCT</a></dt>
    <dd>Returns an RDF graph constructed by substituting variables in a set of triple 
    templates.</dd>
    <dt><a href="#ask">ASK</a></dt>
    <dd>Returns a boolean indicating whether a query pattern matches or not.</dd>
    <dt><a href="#describe">DESCRIBE</a></dt>
    <dd>Returns an RDF graph that describes the resources found.</dd>
  </dl>
</blockquote>

<p>Formats such as 
<a class="inform" href="http://www.w3.org/TR/sparql11-results-json/">SPARQL 1.1 Query Results JSON Format</a>,
<a class="inform" href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query Results XML Format</a> or
<a class="inform" href="http://www.w3.org/TR/sparql11-results-csv-tsv/">SPARQL 1.1 Query Results CSV and TSV Formats</a>
<a class="inform" href=""></a>
<a class="inform" href=""></a>
can be used to serialize the result set from a <code>
SELECT</code> query or the boolean result of an <code>ASK</code> query.</p>


      <div2 id="select">
        <head>SELECT</head>
	<p>The SELECT form of results returns variables and their bindings directly. It combines the operations of projecting the required variables with introducing new variable bindings into a query solution.</p>

	<div3 id="selectproject">
	  <head>Projection</head>

	  <p>Specific variables and their bindings are 
	  returned when a list of variable names is given in the SELECT clause. The syntax
	  <code>SELECT *</code> is an abbreviation that 
	  selects all of the variables that are <a href="#variableScope">in-scope</a>
	  at that point in the query. It excludes variables only used in 
	  <code>FILTER</code>, in the right-hand side of <code>MINUS</code>,
	  and takes account of subqueries. </p>

	  <p>Use of <code>SELECT *</code> is only permitted when the
	  query does not have a <code>GROUP BY</code> clause.</p>

	  <div class="exampleGroup">
  <pre class="data">@prefix  foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a    foaf:name   &quot;Alice&quot; .
_:a    foaf:knows  _:b .
_:a    foaf:knows  _:c .

_:b    foaf:name   &quot;Bob&quot; .

_:c    foaf:name   &quot;Clare&quot; .
_:c    foaf:nick   &quot;CT&quot; .	    </pre>
            <div class="queryGroup">
	      <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?nameX ?nameY ?nickY
WHERE
  { ?x foaf:knows ?y ;
       foaf:name ?nameX .
    ?y foaf:name ?nameY .
    OPTIONAL { ?y foaf:nick ?nickY }
  }</pre>
	      <div class="result">
		<table class="resultTable" id="table33">
		  <tr>
		    <th>nameX</th>
		    <th>nameY</th>
		    <th>nickY</th>
		  </tr>
		  <tr>
		    <td>&quot;Alice&quot;</td>
		    <td>&quot;Bob&quot;</td>
		    <td></td>
		  </tr>
		  <tr>
		    <td>&quot;Alice&quot;</td>
		    <td>&quot;Clare&quot;</td>
		    <td>&quot;CT&quot;</td>
		  </tr>
		</table>
              </div>
	      <p>Result sets can be accessed by a local API but also can be serialized into 
	      either JSON, XML, CSV or TSV.</p>

	      <p><a class="inform" href="http://www.w3.org/TR/sparql11-results-json/">SPARQL 1.1 Query Results JSON Format</a>:</p>

	      <div class="result">
		<pre class="resultSet">{
  "head": {
    "vars": [ "nameX" , "nameY" , "nickY" ]
  } ,
  "results": {
    "bindings": [
      {
        "nameX": { "type": "literal" , "value": "Alice" } ,
        "nameY": { "type": "literal" , "value": "Bob" }
      } ,
      {
        "nameX": { "type": "literal" , "value": "Alice" } ,
        "nameY": { "type": "literal" , "value": "Clare" } ,
        "nickY": { "type": "literal" , "value": "CT" }
      }
    ]
  }
}</pre>
	      </div>

	      <p><a class="inform" href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query 
	      Results XML Format</a>:</p>

	      <div class="result">
		<pre class="resultSet">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot;&gt;
  &lt;head&gt;
    &lt;variable name=&quot;nameX&quot;/&gt;
    &lt;variable name=&quot;nameY&quot;/&gt;
    &lt;variable name=&quot;nickY&quot;/&gt;
  &lt;/head&gt;
  &lt;results&gt;
    &lt;result&gt;
      &lt;binding name=&quot;nameX&quot;&gt;
        &lt;literal&gt;Alice&lt;/literal&gt;
      &lt;/binding&gt;
      &lt;binding name=&quot;nameY&quot;&gt;
        &lt;literal&gt;Bob&lt;/literal&gt;
      &lt;/binding&gt;
   &lt;/result&gt;
    &lt;result&gt;
      &lt;binding name=&quot;nameX&quot;&gt;
        &lt;literal&gt;Alice&lt;/literal&gt;
      &lt;/binding&gt;
      &lt;binding name=&quot;nameY&quot;&gt;
        &lt;literal&gt;Clare&lt;/literal&gt;
      &lt;/binding&gt;
      &lt;binding name=&quot;nickY&quot;&gt;
        &lt;literal&gt;CT&lt;/literal&gt;
      &lt;/binding&gt;
    &lt;/result&gt;
  &lt;/results&gt;
&lt;/sparql&gt;</pre>
	      </div>
            </div>
	  </div>
	</div3>

	<div3 id="selectExpressions">
	  <head>SELECT Expressions</head>
	  <p>As well as choosing which variables from the pattern matching are included in 
	  the results, the SELECT clause can also introduce new variables. The rules of 
	  assignment in SELECT expression are the same as for assignment in BIND.
	  The expression combines variable bindings already in the query solution, 
	  or defined earlier in the SELECT clause, to produce a binding in the query solution.</p>

	  <p>The scoping for <code>(expr AS v)</code> applies immediately.  In 
	  <code>SELECT</code> expressions, the variable may be used in an expression
	  later in the same <code>SELECT</code> clause and may not be
	  be assigned again in the same <code>SELECT</code> clause.</p>
	  
	  <p>Example:</p>
	  <div class="exampleGroup">
	    <p>Data:</p>
	    <pre class="data">@prefix dc:   &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix :     &lt;http://example.org/book/&gt; .
@prefix ns:   &lt;http://example.org/ns#&gt; .

:book1  dc:title  "SPARQL Tutorial" .
:book1  ns:price  42 .
:book1  ns:discount 0.2 .

:book2  dc:title  "The Semantic Web" .
:book2  ns:price  23 .
:book2  ns:discount 0.25 .</pre>
             <p>Query:</p>
        <div class="queryGroup">
          <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  ns:  &lt;http://example.org/ns#&gt;
SELECT  ?title (?p*(1-?discount) AS ?price)
{ ?x ns:price ?p .
  ?x dc:title ?title . 
  ?x ns:discount ?discount 
}</pre>
            <p>Results:</p>
	    <div class="result">
	      <table class="resultTable">
		<tr>
		  <th>title</th>
		  <th>price</th>
		</tr>
		<tr>
		  <td>&quot;The Semantic Web&quot;</td>
		  <td>17.25</td>
		</tr>
		<tr>
		  <td>&quot;SPARQL Tutorial&quot;</td>
		  <td>33.6</td>
		</tr>
	      </table>
	    </div>
	     </div>
	  </div>

	  <p>New variables can also be used in expressions if they are introduced earlier, 
	  syntactically, in the same SELECT clause:</p>
	  <div class="exampleGroup">
	    <div class="queryGroup">
	      <pre class="query">PREFIX  dc:  &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX  ns:  &lt;http://example.org/ns#&gt;
SELECT  ?title (?p AS ?fullPrice) (?fullPrice*(1-?discount) AS ?customerPrice)
{ ?x ns:price ?p .
   ?x dc:title ?title . 
   ?x ns:discount ?discount 
}</pre>
            <p>Results:</p>
	    <div class="result">
	      <table class="resultTable">
		<tr>
		  <th>title</th>
		  <th>fullPrice</th>
		  <th>customerPrice</th>
		</tr>
		<tr>
		  <td>&quot;The Semantic Web&quot;</td>
		  <td>23</td>
		  <td>17.25</td>
		</tr>
		<tr>
		  <td>&quot;SPARQL Tutorial&quot;</td>
		  <td>42</td>
		  <td>33.6</td>
		</tr>
	      </table>
	    </div>
	    </div>
	  </div>
	</div3>
      </div2>

      <div2 id="construct">
        <head>CONSTRUCT</head>
<p>The <code>CONSTRUCT</code> query form returns a single RDF graph specified by 
a graph template. The result is an RDF graph formed by taking each query solution 
in the solution sequence, substituting for the variables in the graph template, 
and combining the triples into a single RDF graph by set union.</p>
<p>If any such instantiation produces a triple containing an unbound variable or 
an illegal RDF construct, such as a literal in subject or predicate position, then 
that triple is not included in the output RDF graph. The graph template can contain 
triples with no variables (known as ground or explicit triples), and these also appear 
in the output RDF graph returned by the CONSTRUCT query form.</p>
<div class="exampleGroup">
  <pre class="data">@prefix  foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a    foaf:name   &quot;Alice&quot; .
_:a    foaf:mbox   &lt;mailto:alice@example.org&gt; .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX vcard:   &lt;http://www.w3.org/2001/vcard-rdf/3.0#&gt;
CONSTRUCT   { &lt;http://example.org/person#Alice&gt; vcard:FN ?name }
WHERE       { ?x foaf:name ?name }
</pre>
    <p>creates vcard properties from the FOAF information:</p>
    <div class="result">
      <pre class="resultGraph" style="text-align:left;">@prefix vcard: &lt;http://www.w3.org/2001/vcard-rdf/3.0#&gt; .

&lt;http://example.org/person#Alice&gt; vcard:FN &quot;Alice&quot; .
</pre>
    </div>
  </div>
</div>

      <div3 id="templatesWithBNodes">
	<!-- Preserve old links to misspelt anchor -->
        <head><a id="tempatesWithBNodes"/>Templates with Blank Nodes</head>
<p>A template can create an RDF graph containing blank nodes. The blank node labels 
are scoped to the template for each solution. If the same label occurs twice in 
a template, then there will be one blank node created for each query solution, but 
there will be different blank nodes for triples generated by different query 
solutions.</p>
<div class="exampleGroup">
  <pre class="data">@prefix  foaf:  &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a    foaf:givenname   &quot;Alice&quot; .
_:a    foaf:family_name &quot;Hacker&quot; .

_:b    foaf:firstname   &quot;Bob&quot; .
_:b    foaf:surname     &quot;Hacker&quot; .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX vcard:   &lt;http://www.w3.org/2001/vcard-rdf/3.0#&gt;

CONSTRUCT { ?x  vcard:N _:v .
            _:v vcard:givenName ?gname .
            _:v vcard:familyName ?fname }
WHERE
 {
    { ?x foaf:firstname ?gname } UNION  { ?x foaf:givenname   ?gname } .
    { ?x foaf:surname   ?fname } UNION  { ?x foaf:family_name ?fname } .
 }
</pre>
    <p>creates vcard properties corresponding to the FOAF information:</p>
    <div class="result">
      <pre class="resultGraph" style="text-align:left;">@prefix vcard: &lt;http://www.w3.org/2001/vcard-rdf/3.0#&gt; .

_:v1 vcard:N         _:x .
_:x vcard:givenName  &quot;Alice&quot; .
_:x vcard:familyName &quot;Hacker&quot; .

_:v2 vcard:N         _:z .
_:z vcard:givenName  &quot;Bob&quot; .
_:z vcard:familyName &quot;Hacker&quot; .
</pre>
    </div>
  </div>
</div>
<p>The use of variable <code>x</code> in the template, which in this example will be bound to 
blank nodes with labels <code>_:a</code> and <code>_:b</code> in the data, 
causes different blank node labels (<code>_:v1</code> and <code>_:v2</code>) in the resulting RDF graph.</p> 

      </div3>
      <div3 id="accessingRdfGraphs">
        <head>Accessing Graphs in the RDF Dataset</head>
<p>Using <code>CONSTRUCT</code>, it is possible to extract parts or the whole of 
graphs from the target RDF dataset. This first example returns the graph (if it 
is in the dataset) with IRI label <code>http://example.org/aGraph</code>; otherwise, 
it returns an empty graph.</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">CONSTRUCT { ?s ?p ?o } WHERE { GRAPH &lt;http://example.org/aGraph&gt; { ?s ?p ?o } . }
</pre>
  </div>
</div>
<p>The access to the graph can be conditional on other information. For example, if the 
default graph contains metadata about the named graphs in the dataset, then a query 
like the following one can extract one graph based on information about the named 
graph:</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX  dc: &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX app: &lt;http://example.org/ns#&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

CONSTRUCT { ?s ?p ?o } WHERE
 {
   GRAPH ?g { ?s ?p ?o } .
   ?g dc:publisher &lt;http://www.w3.org/&gt; .
   ?g dc:date ?date .
   FILTER ( app:customDate(?date) &gt; &quot;2005-02-28T00:00:00Z&quot;^^xsd:dateTime ) .
 }
</pre>
  </div>
</div>
<p>where <code>app:customDate</code> identifies an <a href="#extensionFunctions">
extension function</a> to turn the date format into an <code>xsd:dateTime</code> 
RDF term.</p>

      </div3>
      <div3 id="SolModandCONSTRUCT">
        <head>Solution Modifiers and CONSTRUCT</head>
<p>The solution modifiers of a query affect the results of a <code>CONSTRUCT</code> 
query. In this example, the output graph from the <code>CONSTRUCT</code> template 
is formed from just two of the solutions from graph pattern matching. The query outputs 
a graph with the names of the people with the top two sites, rated by hits. The triples 
in the RDF graph are not ordered.</p>
<div class="exampleGroup">
  <pre class="data">@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix site: &lt;http://example.org/stats#&gt; .

_:a foaf:name &quot;Alice&quot; .
_:a site:hits 2349 .

_:b foaf:name &quot;Bob&quot; .
_:b site:hits 105 .

_:c foaf:name &quot;Eve&quot; .
_:c site:hits 181 .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX site: &lt;http://example.org/stats#&gt;

CONSTRUCT { [] foaf:name ?name }
WHERE
{ [] foaf:name ?name ;
     site:hits ?hits .
}
ORDER BY desc(?hits)
LIMIT 2
</pre>
    <div class="result">
      <pre class="resultGraph">@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .
_:x foaf:name &quot;Alice&quot; .
_:y foaf:name &quot;Eve&quot; .
</pre>
    </div>
  </div>
</div>

      </div3>

      <div3 id="constructWhere">
	<head>CONSTRUCT WHERE</head>
	<p>A short form for the CONSTRUCT query form is provided for the case where the template and 
	the pattern are the same and the pattern is just a basic graph pattern 
	(no <code>FILTER</code>s and no complex graph patterns are allowed in the short form).
	The keyword <code>WHERE</code> is required in the short form.</p>

	<p>The following two queries are the same; the first is a short form of the second.</p>

	 <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
CONSTRUCT WHERE { ?x foaf:name ?name } 
</pre>

	 <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;

CONSTRUCT { ?x foaf:name ?name } 
WHERE
{ ?x foaf:name ?name }
</pre>


      </div3>

          </div2>
      <div2 id="ask">
        <head>ASK</head>
<p>Applications can use the <code>ASK</code> form to test whether or not a query 
pattern has a solution. No information is returned about the possible query solutions, 
just whether or not a solution exists.</p>
<div class="exampleGroup">
  <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       &quot;Alice&quot; .
_:a  foaf:homepage   &lt;http://work.example.org/alice/&gt; .

_:b  foaf:name       &quot;Bob&quot; .
_:b  foaf:mbox       &lt;mailto:bob@work.example&gt; .
</pre>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
ASK  { ?x foaf:name  &quot;Alice&quot; }
</pre>
    <div class="result">
      <pre class="resultAsk">true</pre>
    </div>
    <p>The <a class="inform" href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL 
    Query Results XML Format</a> form of this result set gives:</p>
    <div class="result">
      <pre class="resultSet">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot;&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;boolean&gt;true&lt;/boolean&gt;
&lt;/sparql&gt;
</pre>
    </div>
  </div>
  <p>On the same data, the following returns no match because Alice&#39;s <code>mbox</code> 
  is not mentioned.</p>
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:    &lt;http://xmlns.com/foaf/0.1/&gt;
ASK  { ?x foaf:name  &quot;Alice&quot; ;
          foaf:mbox  &lt;mailto:alice@work.example&gt; }
</pre>
    <div class="result">
      <pre class="resultAsk">false</pre>
    </div>
  </div>
</div>
      </div2>
      <div2 id="describe">
        <head>DESCRIBE (Informative)</head>
<p>The <code>DESCRIBE</code> form returns a single result RDF graph containing RDF 
data about resources. This data is not prescribed by a SPARQL query, where the query 
client would need to know the structure of the RDF in the data source, but, instead, 
is determined by the SPARQL query processor. The query pattern is used to create 
a result set. The <code>DESCRIBE</code> form takes each of the resources identified 
in a solution, together with any resources directly named by IRI, and assembles 
a single RDF graph by taking a &quot;description&quot; which can come from any 
information available including the target RDF Dataset. The 
description is determined by the query service. The syntax <code>DESCRIBE *</code> 
is an abbreviation that describes all of the variables in a query.</p>

        <div3 id="explicitIRIs">
          <head>Explicit IRIs</head>
<p>The <code>DESCRIBE</code> clause itself can take IRIs to identify the resources. 
The simplest <code>DESCRIBE</code> query is just an IRI in the <code>DESCRIBE</code> 
clause:</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">DESCRIBE &lt;http://example.org/&gt;
</pre>
  </div>
</div>

        </div3>
        <div3 id="identifyingResources">
          <head>Identifying Resources</head>
<p>The resources to be described can also be taken from the bindings to a query variable in a result set. This enables description 
of resources whether they are identified by IRI or by blank node in the dataset:</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
DESCRIBE ?x
WHERE    { ?x foaf:mbox &lt;mailto:alice@org&gt; }
</pre>
  </div>
</div>
<p>The property <code>foaf:mbox</code> is defined as being an inverse functional property 
in the FOAF vocabulary. If treated as such, this query will return information about 
at most one person. If, however, the query pattern has multiple solutions, the RDF 
data for each is the union of all RDF graph descriptions.</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
DESCRIBE ?x
WHERE    { ?x foaf:name &quot;Alice&quot; }
</pre>
  </div>
</div>
<p>More than one IRI or variable can be given:</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;
DESCRIBE ?x ?y &lt;http://example.org/&gt;
WHERE    {?x foaf:knows ?y}
</pre>
  </div>
</div>

        </div3>
        <div3 id="descriptionsOfResources">
          <head>Descriptions of Resources</head>
<p>The RDF returned is determined by the information publisher. 
It may be information the service deems relevant to the resources being described.
It may include information about other resources: for example, the RDF data for a 
book may also include details about the author.</p>
<p>A simple query such as</p>
<div class="exampleGroup">
  <div class="queryGroup">
    <pre class="query">PREFIX ent:  &lt;http://org.example.com/employees#&gt;
DESCRIBE ?x WHERE { ?x ent:employeeId &quot;1234&quot; }
</pre>
    <p>might return a description of the employee and some other potentially useful 
    details:</p>
    <div class="result">
      <pre class="resultGraph">@prefix foaf:   &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix vcard:  &lt;http://www.w3.org/2001/vcard-rdf/3.0&gt; .
@prefix exOrg:  &lt;http://org.example.com/employees#&gt; .
@prefix <code>rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix owl:    &lt;http://www.w3.org/2002/07/owl#&gt;</code>

_:a     exOrg:employeeId    &quot;1234&quot; ;
       
        <code>foaf:mbox_sha1sum   &quot;bee135d3af1e418104bc42904596fe148e90f033&quot; ;</code>
        vcard:N
         [ vcard:Family       &quot;Smith&quot; ;
           vcard:Given        &quot;John&quot;  ] .

<code>foaf:mbox_sha1sum  rdf:type  owl:InverseFunctionalProperty .</code>
</pre>
    </div>
  </div>
</div>
<p>which includes the blank node closure for the
<a href="http://www.w3.org/TR/vcard-rdf" class="inform">vcard</a> vocabulary vcard:N. 
Other possible mechanisms for deciding what information to return include Concise 
Bounded Descriptions [<a href="#CBD">CBD</a>].</p>
<p>For a vocabulary such as FOAF, where the resources are typically blank nodes, 
returning sufficient information to identify a node such as the InverseFunctionalProperty
<code>foaf:mbox_sha1sum</code> as well as information like name and other details recorded 
would be appropriate. In the example, the match to the <code>WHERE</code> clause was returned, 
but this is not required.</p>
        </div3>
      </div2>
    </div1>
    <div1 id="expressions">
      <head>Expressions and Testing Values</head>

      <p>SPARQL <code>FILTERs</code> restrict the solutions of a graph pattern match according to a given <a href="#rConstraint">constraint</a>. Specifically,
      <code>FILTERs</code> eliminate any solutions that, when substituted into the expression, either result in an effective boolean value of <code>false</code> or produce an error. Effective boolean values are defined in section <a href="#ebv">17.2.2 <em>Effective Boolean Value</em></a> and errors are defined in XQuery 1.0: An XML Query Language [<a href="#XQUERY">XQUERY</a>] section <a class="norm" href="http://www.w3.org/TR/2007/REC-xquery-20070123/#dt-type-error">2.3.1, <em>Kinds of Errors</em></a>. These errors have no effect outside of <code>FILTER</code> evaluation.</p>

      <div class="exampleGroup">
	<p>RDF literals may have a <a>datatype IRI</a>:</p>

	<pre class="data">@prefix a:          &lt;http://www.w3.org/2000/10/annotation-ns#&gt; .
@prefix dc:         &lt;http://purl.org/dc/elements/1.1/&gt; .

_:a   a:annotates   &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
_:a   dc:date       &quot;2004-12-31T19:00:00-05:00&quot; .

_:b   a:annotates   &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
_:b   dc:date       &quot;2004-12-31T19:01:00-05:00&quot;^^&lt;http://www.w3.org/2001/XMLSchema#dateTime&gt; .</pre>
        <p>The object of the first <code>dc:date</code> triple has no type information. The second has the datatype <code>xsd:dateTime</code>.</p>

    <p>SPARQL expressions are constructed according to the grammar and provide access to functions (named by IRI) and operator functions (invoked by keywords and symbols in the SPARQL grammar). SPARQL operators can be used to compare the values of typed literals:</p>

  <div class="queryGroup">
  <pre class="query">PREFIX a:      &lt;http://www.w3.org/2000/10/annotation-ns#&gt;
PREFIX dc:     &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX xsd:    &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?annot
WHERE { ?annot  a:annotates  &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
        ?annot  dc:date      ?date .
        FILTER ( ?date &gt; &quot;2005-01-01T00:00:00Z&quot;^^xsd:dateTime ) }</pre></div></div>

    <p>The SPARQL operators are listed in <a href="#OperatorMapping">section 17.3</a> and are associated with their productions in the grammar.</p>

    <p>In addition, SPARQL provides the ability to invoke arbitrary functions, including a subset of the XPath casting functions, listed in <a href="#FunctionMapping">section 17.5</a>. These functions are invoked by name (an IRI) within a SPARQL query. For example:</p>

  <pre class="query untested">... FILTER ( xsd:dateTime(?date) &lt; xsd:dateTime(&quot;2005-01-01T00:00:00Z&quot;) ) ...</pre>

  <p>Typographical convention in this section: XPath operators are labeled 
  with the prefix <code>op:</code>. XPath operators have no namespace; 
  <code>op:</code> is a labeling convention.</p>


          <div2 id="operandDataTypes">
        <head>Operand Data Types</head>

    <p>SPARQL functions and operators operate on RDF terms and SPARQL variables. A subset of these functions and operators are taken from the <a class="norm" href=
  "http://www.w3.org/TR/xpath-functions/">XQuery 1.0 and XPath 2.0 Functions and Operators</a> [<a href="#FUNCOP">FUNCOP</a>] and have XML Schema <a href="http://www.w3.org/TR/xpath20/#dt-typed-value">typed value</a> arguments and return types.

RDF <code class="type typedLiteral">typed literals</code> passed as arguments to these functions and operators are mapped to XML Schema typed values with a <a href="http://www.w3.org/TR/xpath20/#dt-string-value">string value</a> of the <code class="type lexicalForm">lexical form</code> and an <a href="http://www.w3.org/TR/xmlschema-2/#dt-atomic">atomic datatype</a> corresponding to the <span class="type datatypeIRI">datatype IRI</span>. The returned typed values are mapped back to RDF <code class="type typedLiteral">typed literals</code> the same way.</p>

    <p>SPARQL has additional operators which operate on specific subsets of RDF terms. When referring to a type, the following terms denote a <code class="type typedLiteral">typed literal</code> with the corresponding <a class="norm" href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/">XML Schema</a> [<a class="norm" href="#XSDT">XSDT</a>] <span class="type datatypeIRI">datatype IRI</span>:</p>

    <ul>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-integer">xsd:integer</a></code></li>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-decimal">xsd:decimal</a></code><!-- and derived types:<ul>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-nonPositiveInteger">xsd:nonPositiveInteger</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-negativeInteger">xsd:negativeInteger</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-long">xsd:long</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-int">xsd:int</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-short">xsd:short</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-byte">xsd:byte</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-nonNegativeInteger">xsd:nonNegativeInteger</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedLong">xsd:unsignedLong</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedInt">xsd:unsignedInt</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedShort">xsd:unsignedShort</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedByte">xsd:unsignedByte</a></code></li>
    <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-positiveInteger">xsd:positiveInteger</a></code></li>
  </ul> --></li>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-float">xsd:float</a></code></li>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-double">xsd:double</a></code></li>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-string">xsd:string</a></code></li>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-boolean">xsd:boolean</a></code></li>
      <li><code><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-dateTime">xsd:dateTime</a></code></li>
    </ul>

    <p>The following terms identify additional types used in SPARQL value tests:</p>

    <ul>
      <li><span class="type numeric">numeric</span> denotes <code class="type typedLiteral">typed literals</code> with datatypes <code>xsd:integer</code>, <code>xsd:decimal</code>, <code>xsd:float</code>, and <code>xsd:double</code>.</li>
      <li><span class="type simpleLiteral">simple literal</span> denotes a <code class="type plainLiteral">plain literal</code> with no <code class="type langTag">language tag</code>.</li>
      <li><span class="type RDFterm">RDF term</span> denotes the types <code class="type IRI">IRI</code>, <code class="type literal">literal</code>, and <code class="type bNode">blank node</code>.</li>
      <li><span class="type variable">variable</span> denotes a SPARQL variable.</li>
    </ul>

  <!-- blockquote>
    <dl>
      <dt class="type numeric">numeric</dt> <dd><code class="type typedLiteral">typed literals</code> with datatypes <code>xsd:integer</code>, <code>xsd:decimal</code>, <code>xsd:float</code>, and <code>xsd:double</code></dd>
      <dt></dt>
      <dt class="type simpleLiteral">simple literal</dt> <dd>a <code class="type plainLiteral">plain literal</code> with no <code class="type langTag">language tag</code>.</dd>
      <dt class="type RDFterm">RDF term</dt> <dd>the types <code class="type IRI">IRI</code>, <code class="type literal">literal</code>, and <code class="type bNode">blank node</code></dd>
      <dt class="type variable">variable</dt> <dd>a SPARQL variable</dd>

    </dl>
  </blockquote -->

    <p>The following types are derived from <span class="type numeric">numeric</span> types and are valid arguments to functions and operators taking <span class="type numeric">numeric</span> arguments:</p>

    <ul>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-nonPositiveInteger"><code>xsd:nonPositiveInteger</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-negativeInteger"><code>xsd:negativeInteger</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-long"><code>xsd:long</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-int"><code>xsd:int</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-short"><code>xsd:short</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-byte"><code>xsd:byte</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-nonNegativeInteger"><code>xsd:nonNegativeInteger</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedLong"><code>xsd:unsignedLong</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedInt"><code>xsd:unsignedInt</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedShort"><code>xsd:unsignedShort</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-unsignedByte"><code>xsd:unsignedByte</code></a></li>
      <li><a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-positiveInteger"><code>xsd:positiveInteger</code></a></li>
    </ul>

    <p>SPARQL language extensions may treat additional types as being derived from XML schema datatypes.</p>

      </div2>
          <div2 id="evaluation">
        <head>Filter Evaluation</head>

    <p>SPARQL provides a subset of the functions and operators defined by XQuery <a href="http://www.w3.org/TR/xquery/#mapping" class="norm">Operator Mapping</a>. XQuery 1.0 section <a href="http://www.w3.org/TR/xquery/#id-expression-processing" class="norm">2.2.3 Expression Processing</a> describes the invocation of XPath functions. The following rules accommodate the differences in the data and execution models between XQuery and SPARQL:</p>

    <ul>
      <li>Unlike XPath/XQuery, SPARQL functions do not process node sequences. When interpreting the semantics of XPath functions, assume that each argument is a sequence of a single node.</li>

      <li>Functions invoked with an argument of the wrong type will produce a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>. Effective boolean value arguments (labeled "xsd:boolean (EBV)" in the operator mapping table below), are coerced to <code>xsd:boolean</code> using the <a href="#ebv">EBV rules</a> in section 17.2.2.</li>

      <li>Apart from <a href="#func-bound">BOUND</a>, <a href="#func-coalesce">COALESCE</a>,
      <a href="#func-filter-exists">NOT EXISTS</a> and <a href="#func-filter-exists">EXISTS</a>, 
      all functions and operators operate on RDF Terms and will produce a type error 
      if any arguments are unbound.</li>

      <li>Any expression other than <a href="#func-logical-or">logical-or</a> (<code>||</code>) or <a href="#func-logical-and">logical-and</a> (<code>&amp;&amp;</code>) that encounters an error will produce that error.</li>

      <li>A <a href="#func-logical-or">logical-or</a> that encounters an error on only one branch will return TRUE if the other branch is TRUE and an error if the other branch is FALSE.</li>

      <li>A <a href="#func-logical-and">logical-and</a> that encounters an error on only one branch will return an error if the other branch is TRUE and FALSE if the other branch is FALSE.</li>

      <li>A <a href="#func-logical-or">logical-or</a> or <a href="#func-logical-and">logical-and</a> that encounters errors on both branches will produce <em>either</em> of the errors.</li>

    </ul>

    <p>The logical-and and logical-or truth table for true (<span class="truth">T</span>), false (<span class="truth">F</span>), and error (<span class="truth error">E</span>) is as follows:</p>

    <table id="truthTable" class="truthTable">
      <thead>
  <tr><th>A</th><th>B</th><th>A || B</th><th>A &amp;&amp; B</th></tr>
      </thead>
      <tbody>
  <tr><th>T</th><th>T</th><td>T</td><td>T</td></tr>
  <tr><th>T</th><th>F</th><td>T</td><td>F</td></tr>
  <tr><th>F</th><th>T</th><td>T</td><td>F</td></tr>
  <tr><th>F</th><th>F</th><td>F</td><td>F</td></tr>
      </tbody>
      <tbody>
  <tr><th>T</th><th><span class="error">E</span></th><td>T</td><td><span class="error">E</span></td></tr>
  <tr><th><span class="error">E</span></th><th>T</th><td>T</td><td><span class="error">E</span></td></tr>
  <tr><th>F</th><th><span class="error">E</span></th><td><span class="error">E</span></td><td>F</td></tr>
  <tr><th><span class="error">E</span></th><th>F</th><td><span class="error">E</span></td><td>F</td></tr>
  <tr><th><span class="error">E</span></th><th><span class="error">E</span></th><td><span class="error">E</span></td><td><span class="error">E</span></td></tr>
      </tbody>
    </table>

    <div3 id="invocation">
      <head>Invocation</head>
      <p>SPARQL defines a syntax for invoking functions on a list of arguments. 
      Unless otherwise noted, these are invoked as follows:</p>
      <ul>
	<li>Argument expressions are evaluated, producing argument values. 
	The order of argument evaluation is not defined.</li>
	<li>Numeric arguments are promoted as necessary to fit the expected types for that function or operator.</li>
	<li>The function or operator is invoked on the argument values.</li>
      </ul>
      
      <p>If any of these steps fails, the invocation generates an error.
      The effects of errors are defined in <a href="#evaluation">Filter Evaluation</a>.
      </p>

      <p>There are also "<a href="#func-forms">functional forms</a>" which have different evaluation rules to functions 
      as specified by each such form.</p>

    </div3>

            <div3 id="ebv">
          <head>Effective Boolean Value (EBV)</head>

    <p>Effective boolean value is used to calculate the arguments to the logical functions <a href="#func-logical-and">logical-and</a>, <a href="#func-logical-or">logical-or</a>, and <a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>, as well as evaluate the result of a <code>FILTER</code> expression.</p>

    <p>The XQuery <a href="http://www.w3.org/TR/xquery/#id-ebv"> Effective Boolean Value</a> rules rely on the definition of XPath's <a href="http://www.w3.org/TR/xpath-functions/#func-boolean">fn:boolean</a>. The following rules reflect the rules for <code>fn:boolean</code> applied to the argument types present in SPARQL queries:</p>

    <ul>
      <li>The EBV of any literal whose type is <code>xsd:boolean</code> or <span class="type ">numeric</span> is false if the lexical form is not valid for that datatype (e.g. "abc"^^xsd:integer).</li>
      <li>If the argument is a <span class="type typedLiteral">typed literal</span> with a <span class="type datatype">datatype</span> of <code>xsd:boolean</code>, and it has a valid lexical form, the EBV is the value of that argument.</li>
      <li>If the argument is a <span class="type plainLiteral">plain literal</span> or a <span class="type typedLiteral">typed literal</span> with a <span class="type datatype">datatype</span> of <code>xsd:string</code>, the EBV is false if the operand value has zero length; otherwise the EBV is true.</li>
      <li>If the argument is a <span class="type numeric">numeric</span> type or a <span class="type typedLiteral">typed literal</span> with a datatype derived from a <span class="type numeric">numeric</span> type, and it has a valid lexical form, the EBV is false if the operand value is NaN or is numerically equal to zero; otherwise the EBV is true.</li>
      <li>All other arguments, including unbound arguments, produce a type error.</li>
    </ul>

    <p>An EBV of <code>true</code> is represented as a <span class="type typedLiteral">typed literal</span> with a datatype of <code>xsd:boolean</code> and a lexical value of "true"; an EBV of false is represented as a <span class="type typedLiteral">typed literal</span> with a datatype of <code>xsd:boolean</code> and a lexical value of "false".</p>

        </div3>
      </div2>
          <div2 id="OperatorMapping">
        <head>Operator Mapping</head>

    <p>The SPARQL grammar identifies a set of operators (for instance, <span class="token">&amp;&amp;</span>, <span class="token">*</span>, <span class="token">isIRI</span>) used to construct constraints. The following table associates each of these grammatical productions with the appropriate operands and an operator function defined by either <a class="norm" href="http://www.w3.org/TR/xpath-functions/">XQuery 1.0 and XPath 2.0 Functions and Operators</a> [<a href="#FUNCOP">FUNCOP</a>] or the SPARQL operators specified in <a href="#SparqlOps">section 17.4</a>. When selecting the operator definition for a given set of parameters, the definition  with the most specific parameters applies. For instance, when evaluating <code>xsd:integer = xsd:signedInt</code>, the definition for <code>=</code> with two <code>numeric</code> parameters applies, rather than the one with two <span class="type RDFterm">RDF terms</span>. The table is arranged so that the upper-most viable candidate is the most specific. Operators invoked without appropriate operands result in a type error.</p>

    <p>SPARQL follows XPath's scheme for numeric type promotions and subtype substitution for arguments to numeric operators. The <a href="http://www.w3.org/TR/xpath20/#mapping">XPath Operator Mapping</a> rules for <span class="type numeric">numeric</span> operands (<code>xsd:integer</code>, <code>xsd:decimal</code>, <code>xsd:float</code>, <code>xsd:double</code>, and types derived from a <span class="type numeric">numeric</span> type) apply to SPARQL operators as well (see <a class="norm" href="http://www.w3.org/TR/xpath20/">XML Path Language (XPath) 2.0</a> [<a href="#XPATH20">XPATH20</a>] for definitions of <a class="norm" href="http://www.w3.org/TR/xpath20/#promotion">numeric type promotions</a> and <a class="norm" href="http://www.w3.org/TR/xpath20/#dt-subtype-substitution">subtype substitution</a>). Some of the operators are associated with nested function expressions, e.g. <code>fn:not(op:numeric-equal(A, B))</code>. Note that per the XPath definitions, <code>fn:not</code> and <code>op:numeric-equal</code> produce an error if their argument is an error.</p>

    <p>The collation for <code>fn:compare</code> is <a href="http://www.w3.org/TR/xpath-functions/#collations">defined by XPath</a> and identified by <code>http://www.w3.org/2005/xpath-functions/collation/codepoint</code>. This collation allows for string comparison based on code point values. Codepoint string equivalence can be tested with <span class="type RDFterm">RDF term</span> equivalence.</p>

    <table summary="SPARQL Unary Operators" class="FAndOTable">
      <caption>SPARQL Unary Operators</caption>
      <tbody>
	<tr>
	  <th class="major" scope="col">Operator</th>
	  <th class="major" scope="col">Type(A)</th>
	  <th class="major" scope="col">Function</th>
	  <th class="major" scope="col">Result type</th>
	</tr>
	<tr>
	  <th colspan="4" class="subHeading" scope="col">XQuery Unary Operators</th>
	</tr>
	<tr>
	  <th scope="row"><a href="#rUnaryExpression" title="UnaryExpression"><span class="FAOTtoken">!</span> A</a></th>
	  <td>xsd:boolean <a href="#ebv-arg">(EBV)</a></td><td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(A)</td><td>xsd:boolean</td>
	</tr>
	<tr>
	  <th scope="row"><a href="#rUnaryExpression" title="UnaryExpression"><span class="FAOTtoken">+</span> A</a>
	  </th>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-unary-plus">op:numeric-unary-plus</a>(A)</td>
	<td><span class="type numeric">numeric</span></td></tr>
	<tr>
	  <th scope="row"><a href="#rUnaryExpression" title="UnaryExpression"><span class="FAOTtoken">-</span> A</a>
	  </th>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-unary-minus">op:numeric-unary-minus</a>(A)</td>
	<td><span class="type numeric">numeric</span></td></tr>
      </tbody>
    </table>

    <table summary="SPARQL Binary Operators" class="FAndOTable">
      <caption>SPARQL Binary Operators</caption>
      <tbody>
	<tr>
	  <th class="major" scope="col">Operator</th>
	  <th class="major" scope="col">Type(A)</th>
	  <th class="major" scope="col">Type(B)</th>
	  <th class="major" scope="col">Function</th>
	  <th class="major" scope="col">Result type</th>
	</tr>
	<tr>
	  <th colspan="5" class="subHeading" scope="col">Logical Connectives</th>
	</tr>

	<tr>
	  <th><a href="#rConditionalOrExpression" title="ConditionalOrExpression">A <span class="FAOTtoken">||</span> B</a></th>
	  <td>xsd:boolean <a href="#ebv-arg">(EBV)</a></td>
	  <td>xsd:boolean <a href="#ebv-arg">(EBV)</a></td>
	  <td class="sparqlOp"><a href="#func-logical-or" class="SPARQLoperator">logical-or</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th><a href="#rConditionalAndExpression" title="ConditionalAndExpression">A <span class="FAOTtoken">&amp;&amp;</span> B</a></th>
	  <td>xsd:boolean <a href="#ebv-arg">(EBV)</a></td>
	  <td>xsd:boolean <a href="#ebv-arg">(EBV)</a></td>
	  <td class="sparqlOp"><a href="#func-logical-and" class="SPARQLoperator">logical-and</a>(A, B)</td>
	<td>xsd:boolean</td></tr>

	<tr>
	<th colspan="5" class="subHeading" scope="col">XPath Tests</th></tr>

	<!-- eq -->
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">=</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">=</span> B</a></th>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), 0)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">=</span> B</a></th>
	  <td>xsd:string</td>
	  <td>xsd:string</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(<a href="#func-str" class="FAOTtoken">STR</a>(A), <a href="#func-str" class="FAOTtoken">STR</a>(B)), 0)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">=</span> B</a></th>
	  <td>xsd:boolean</td>
	  <td>xsd:boolean</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-boolean-equal">op:boolean-equal</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">=</span> B</a></th>
	  <td>xsd:dateTime</td>
	  <td>xsd:dateTime</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-dateTime-equal">op:dateTime-equal</a>(A, B)</td>
	<td>xsd:boolean</td></tr>


	<!-- ne -->
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), 0))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	  <td>xsd:string</td>
	  <td>xsd:string</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(<a href="#func-str" class="FAOTtoken">STR</a>(A), <a href="#func-str" class="FAOTtoken">STR</a>(B)), 0))</td>
	<td>xsd:boolean</td></tr>
	<!-- tr>
	     <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	     <td><span class="type simpleLiteral">simple literal</span></td>
	     <td><span class="type simpleLiteral">simple literal</span></td>
	     <td class="sparqlOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), 0))</td>
	     <td>xsd:boolean</td></tr -->
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	  <td>xsd:boolean</td>
	  <td>xsd:boolean</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-boolean-equal">op:boolean-equal</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	  <td>xsd:dateTime</td>
	  <td>xsd:dateTime</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-dateTime-equal">op:dateTime-equal</a>(A, B))</td>
	<td>xsd:boolean</td></tr>

	<!-- lt -->
	<tr id="op_lt">
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-less-than">op:numeric-less-than</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;</span> B</a></th>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), -1)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;</span> B</a></th>
	  <td>xsd:string</td>
	  <td>xsd:string</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(<a href="#func-str" class="FAOTtoken">STR</a>(A), <a href="#func-str" class="FAOTtoken">STR</a>(B)), -1)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;</span> B</a></th>
	  <td>xsd:boolean</td>
	  <td>xsd:boolean</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-boolean-less-than">op:boolean-less-than</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;</span> B</a></th>
	  <td>xsd:dateTime</td>
	  <td>xsd:dateTime</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-dateTime-less-than">op:dateTime-less-than</a>(A, B)</td>
	<td>xsd:boolean</td></tr>

	<!-- gt -->
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-greater-than">op:numeric-greater-than</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;</span> B</a></th>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), 1)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;</span> B</a></th>
	  <td>xsd:string</td>
	  <td>xsd:string</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(<a href="#func-str" class="FAOTtoken">STR</a>(A), <a href="#func-str" class="FAOTtoken">STR</a>(B)), 1)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;</span> B</a></th>
	  <td>xsd:boolean</td>
	  <td>xsd:boolean</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-boolean-greater-than">op:boolean-greater-than</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;</span> B</a></th>
	  <td>xsd:dateTime</td>
	  <td>xsd:dateTime</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-dateTime-greater-than">op:dateTime-greater-than</a>(A, B)</td>
	<td>xsd:boolean</td></tr>

	<!-- le -->
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;=</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a href="#func-logical-or" class="SPARQLoperator">logical-or</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-less-than">op:numeric-less-than</a>(A, B), <a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;=</span> B</a></th>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), 1))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;=</span> B</a></th>
	  <td>xsd:string</td>
	  <td>xsd:string</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(<a href="#func-str" class="FAOTtoken">STR</a>(A), <a href="#func-str" class="FAOTtoken">STR</a>(B)), 1))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;=</span> B</a></th>
	  <td>xsd:boolean</td>
	  <td>xsd:boolean</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-boolean-greater-than">op:boolean-greater-than</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&lt;=</span> B</a></th>
	  <td>xsd:dateTime</td>
	  <td>xsd:dateTime</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-dateTime-greater-than">op:dateTime-greater-than</a>(A, B))</td>
	<td>xsd:boolean</td></tr>

	<!-- ge -->
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;=</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a href="#func-logical-or" class="SPARQLoperator">logical-or</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-greater-than">op:numeric-greater-than</a>(A, B), <a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;=</span> B</a></th>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td><span class="type simpleLiteral">simple literal</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(A, B), -1))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;=</span> B</a></th>
	  <td>xsd:string</td>
	  <td>xsd:string</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-equal">op:numeric-equal</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-compare">fn:compare</a>(<a href="#func-str" class="FAOTtoken">STR</a>(A), <a href="#func-str" class="FAOTtoken">STR</a>(B)), -1))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;=</span> B</a></th>
	  <td>xsd:boolean</td>
	  <td>xsd:boolean</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-boolean-less-than">op:boolean-less-than</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th scope="row"><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">&gt;=</span> B</a></th>
	  <td>xsd:dateTime</td>
	  <td>xsd:dateTime</td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-dateTime-less-than">op:dateTime-less-than</a>(A, B))</td>
	<td>xsd:boolean</td></tr>

	<tr>
	<th colspan="5" class="subHeading" scope="col">XPath Arithmetic</th></tr>

	<tr>
	  <th scope="row"><a href="#rMultiplicativeExpression" title="MultiplicativeExpression">A <span class="FAOTtoken">*</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-multiply">op:numeric-multiply</a>(A, B)</td>
	<td><span class="type numeric">numeric</span></td></tr>
	<tr>
	  <th scope="row"><a href="#rMultiplicativeExpression" title="MultiplicativeExpression">A <span class="FAOTtoken">/</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-divide">op:numeric-divide</a>(A, B)</td>
	<td><span class="type numeric">numeric</span>; but xsd:decimal if both operands are xsd:integer</td></tr>

	<tr>
	  <th scope="row"><a href="#rAdditiveExpression" title="AdditiveExpression">A <span class="FAOTtoken">+</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-add">op:numeric-add</a>(A, B)</td>
	<td><span class="type numeric">numeric</span></td></tr>
	<tr>
	  <th scope="row"><a href="#rAdditiveExpression" title="AdditiveExpression">A <span class="FAOTtoken">-</span> B</a></th>
	  <td><span class="type numeric">numeric</span></td>
	  <td><span class="type numeric">numeric</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-numeric-subtract">op:numeric-subtract</a>(A, B)</td>
	<td><span class="type numeric">numeric</span></td></tr>


	<tr>
	<th colspan="5" class="subHeading" scope="col">SPARQL Tests</th></tr>

	<tr>
	  <th ><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">=</span> B</a></th>
	  <td><span class="type RDFterm">RDF term</span></td>
	  <td><span class="type RDFterm">RDF term</span></td>
	  <td class="xpathOp"><a href="#func-RDFterm-equal" class="SPARQLoperator">RDFterm-equal</a>(A, B)</td>
	<td>xsd:boolean</td></tr>
	<tr>
	  <th ><a href="#rRelationalExpression" title="RelationalExpression">A <span class="FAOTtoken">!=</span> B</a></th>
	  <td><span class="type RDFterm">RDF term</span></td>
	  <td><span class="type RDFterm">RDF term</span></td>
	  <td class="xpathOp"><a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-not">fn:not</a>(<a href="#func-RDFterm-equal" class="SPARQLoperator">RDFterm-equal</a>(A, B))</td>
	<td>xsd:boolean</td></tr>
      </tbody>
    </table>

    <p><a id="ebv-arg" name="ebv-arg" />xsd:boolean function arguments marked with "(EBV)" are coerced to xsd:boolean by evaluating the <a href="#ebv">effective boolean value of that argument.</a></p>

            <div3 id="operatorExtensibility">
          <head>Operator Extensibility</head>

    <p>SPARQL language extensions may provide additional associations between operators and operator functions; this amounts to adding rows to the table above. No additional operator may yield a result that replaces any result other than a type error in the semantics defined above. The consequence of this rule is that SPARQL <code>FILTER</code>s will produce <em>at least</em> the same intermediate bindings after applying a <code>FILTER</code> as an unextended implementation.</p>

    <p>Additional mappings of the '&lt;' operator are expected to control the relative ordering of the operands, specifically, when used in an <a href="#modOrderBy"><code>ORDER BY</code></a> clause.</p>

        </div3>
      </div2>

      <!-- F_DEFS -->
      <div2 id="SparqlOps">
        <head>Function Definitions</head>

        <p>This section defines the operators and functions
        introduced by the SPARQL Query language. The examples 
        show the behavior of the operators as invoked by the 
        appropriate grammatical constructs.
        </p>

        <div3 id="func-forms">
          <head>Functional Forms</head>

          <div4 id="func-bound">
            <head class="SPARQLoperator">bound</head>
            
            <pre class="prototype"><span class="return">xsd:boolean</span>  <span class="operator">BOUND</span> (<span class="type">variable</span> <span class="name">var</span>)</pre>

            <p>Returns <code>true</code> if <code>var</code> is bound to a value. Returns false otherwise. Variables with the value NaN or INF are considered bound.</p>

            <div class="exampleGroup">
              <p>Data:</p>

              <pre class="data">@prefix foaf:        &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix dc:          &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix xsd:          &lt;http://www.w3.org/2001/XMLSchema#&gt; .

_:a  foaf:givenName  "Alice".

_:b  foaf:givenName  "Bob" .
_:b  dc:date         "2005-04-04T04:04:04Z"^^xsd:dateTime .</pre>

              <div class="queryGroup">
                <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX dc:   &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX xsd:   &lt;http://www.w3.org/2001/XMLSchema#&gt;
SELECT ?givenName
 WHERE { ?x foaf:givenName  ?givenName .
         OPTIONAL { ?x dc:date ?date } .
         FILTER ( bound(?date) ) }
</pre>

              <p>Query result:</p>

              <div class="result">
                <table class="resultTable">
                  <tbody>
                    <tr>
                      <th>givenName</th>
                    </tr>
                    <tr>
                      <td>"Bob&quot;</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>

            <p>One may test that a  graph pattern is <em>not</em> expressed by specifying an <a><span class="term">OPTIONAL</span></a> <a>graph pattern</a> that introduces a variable and testing to see that the variable is <a><span class="term">not</span></a> <a><span class="term">bound</span></a>. This is called <em>Negation as Failure</em> in logic programming.</p>

            <div class="queryGroup">
              <p>This query matches the people with a <code>name</code> but <em>no</em> expressed <code>date</code>:</p>
              <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX dc:   &lt;http://purl.org/dc/elements/1.1/&gt;
SELECT ?name
 WHERE { ?x foaf:givenName  ?name .
         OPTIONAL { ?x dc:date ?date } .
         FILTER (!bound(?date)) }</pre>

              <p>Query result:</p>

              <div class="result">
                <table class="resultTable">
                  <tbody>
                    <tr>
                      <th>name</th>
                    </tr>
                    <tr>
                      <td>"Alice&quot;</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
            </div>

            <p>Because Bob's <code>dc:date</code> was known, <code>"Bob&quot;</code> was not a solution to the query.</p>
          </div4>

          <div4 id="func-if">
            <head class="SPARQLoperator">IF</head>
            <pre class="prototype"><span class="return">rdfTerm</span>  <span class="operator">IF</span> (<span class="expression">expression1</span>, <span class="expression">expression2</span>, <span class="expression">expression3</span>)</pre>  

            <p>The <code>IF</code> function form evaluates the first argument, interprets it as a <a href="#ebv">effective boolean value</a>, then returns the value of <code>expression2</code> if the EBV is true, otherwise it returns the value of <code>expression3</code>.  Only one of <code>expression2</code> and <code>expression3</code> is evaluated. 
	    If evaluating the first argument raises an error,
	    then an error is raised for the evaluation of the <code>IF</code> expression.</p> 

            <p>Examples: Suppose ?x = 2, ?z = 0 and ?y is not bound in some query solution:</p>

            <div class="result">
              <table>
                <tbody>
                  <tr>
                    <td><code>IF(?x = 2, "yes", "no")</code></td>
                    <td>returns "yes"</td>
                  </tr>
                  <tr>
                    <td><code>IF(bound(?y), "yes", "no")</code></td>
                    <td>returns "no"</td>
                  </tr>
                  <tr>
                    <td><code>IF(?x=2, "yes", 1/?z)</code></td>
                    <td>returns "yes", the expression <code>1/?z</code> is not evaluated</td>
                  </tr>
                  <tr>
                    <td><code>IF(?x=1, "yes", 1/?z)</code></td>
                    <td>raises an error</td>
                  </tr>
                  <tr>
                    <td><code>IF("2" > 1, "yes", "no")</code></td>
                    <td>raises an error</td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div4>


          <div4 id="func-coalesce">
            <head class="SPARQLoperator">COALESCE</head>
            <pre class="prototype"><span class="return">rdfTerm</span>  <span class="operator">COALESCE</span>(<span class="expression">expression, ....</span>)</pre>

            <p>The <code>COALESCE</code> function form returns the RDF term value
            of the first expression that evaluates without error. In SPARQL,
            evaluating an unbound variable raises an error.</p>

            <p>If none of the arguments evaluates to an RDF term, an error is raised.
            If no expressions are evaluated without error, an error is raised.</p>
            
            <p>Examples: Suppose ?x = 2 and ?y is not bound in some query solution:</p>
            
            <div class="result">
              <table>
                <tbody>
                  <tr>
                    <td><code>COALESCE(?x, 1/0)</code></td>
                    <td>returns 2, the value of <code>x</code></td>
                  </tr>
                  <tr>
                    <td><code>COALESCE(1/0, ?x)</code></td>
                    <td>returns 2</td>
                  </tr>
                  <tr>
                    <td><code>COALESCE(5, ?x)</code></td>
                    <td>returns 5</td>
                  </tr>
                  <tr>
                    <td><code>COALESCE(?y, 3)</code></td>
                    <td>returns 3</td>
                  </tr>
                  <tr>
                    <td><code>COALESCE(?y)</code></td>
                    <td>raises an error because <code>y</code> is not bound.</td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div4>
        
          <div4 id="func-filter-exists">
            <head class="SPARQLoperator">NOT EXISTS and EXISTS</head>
          
            <p>There is a filter operator <code>EXISTS</code> that takes a graph pattern. 
	    <code>EXISTS</code> returns <code>true</code>/<code>false</code>
	    depending on whether 
	    the pattern matches the dataset
            given the bindings in the current group graph pattern, the dataset and
	    the <a href="#defn_ActiveGraph">active graph</a> at this point in the 
	    query evaluation.
            No additional binding of variables occurs. The <code>NOT EXISTS</code> form 
            translates into <code>fn:not(EXISTS{...})</code>.</p>
          
            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">NOT EXISTS</span> { <span class="pattern">pattern</span> }</pre>

            <p>Returns <code>false</code> if <code>pattern</code> matches. Returns true otherwise.</p>

            <p><code>NOT EXISTS { pattern }</code> is equivalent to <code>fn:not(EXISTS { pattern })</code>.</p>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <code>EXISTS</code> { <span class="pattern">pattern</span> }</pre>
            
            <p>Returns <code>true</code> if <code>pattern</code> matches. 
            Returns false otherwise.</p>
          
            <p>Variables in the <code>pattern</code> that are bound in the current
            <a href="http://www.w3.org/TR/rdf-sparql-query/#defn_sparqlSolutionMapping">
              solution mapping</a> take the value that they have from the solution mapping. 
              Variables in the pattern <code>pattern</code> that are not bound in the current 
            solution mapping take part in pattern matching.</p>
            
	    <p>To facilitate this, we introduce a function <a href="#defn_exists">Exists</a> 
	    that evaluates a SPARQL Algebra expression and returns true or false, depending
	    on whether there are any solutions to the pattern, given the solution mapping
	    being tested by the filter operation.</p>

          </div4>

          <div4 id="func-logical-or">
            <head class="SPARQLoperator">logical-or</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="type">xsd:boolean</span> <span class="name">left</span> <span class="operator">||</span> <span class="type">xsd:boolean</span> <span class="name">right</span></pre>

            <p>Returns a logical <code>OR</code> of <code>left</code> and <code>right</code>. Note that <span class="SPARQLoperator">logical-or</span> operates on the <a href="#ebv">effective boolean value</a> of its arguments.</p>

            <p>Note: see section 17.2, <a href="#evaluation">Filter Evaluation</a>, for 
            the <code>||</code> operator's treatment of errors.</p>

          </div4>

          <div4 id="func-logical-and">
            <head class="SPARQLoperator">logical-and</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="type">xsd:boolean</span> <span class="name">left</span> <span class="operator">&amp;&amp;</span> <span class="type">xsd:boolean</span> <span class="name">right</span></pre>

            <p>Returns a logical <code>AND</code> of <code>left</code> and <code>right</code>. Note that <span class="SPARQLoperator">logical-and</span> operates on the <a href="#ebv">effective boolean value</a> of its arguments.</p>

            <p>Note: see section 17.2, <a href="#evaluation">Filter Evaluation</a>, for 
            the <code>&amp;&amp;</code> operator's treatment of errors.</p>

          </div4>

          <div4 id="func-RDFterm-equal">
            <head class="SPARQLoperator">RDFterm-equal</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="type">RDF term</span> <span class="name">term1</span> <span class="operator">=</span> <span class="type">RDF term</span> <span class="name">term2</span></pre>

            <p>Returns TRUE if <code>term1</code> and <code>term2</code> are the same RDF term as defined in <a class="norm" href="http://www.w3.org/TR/rdf-concepts/">Resource Description Framework (RDF): Concepts and Abstract Syntax</a> [<a href="#CONCEPTS">CONCEPTS</a>]; produces a type error if the arguments are both literal but are not the same RDF term <sup><a href="#func-RDFterm-equal-foot1" class="footnote">*</a></sup>; returns FALSE otherwise. <code>term1</code> and <code>term2</code> are the same if any of the following is true:</p>

            <ul>
              <li><span class="name">term1</span> and <span class="name">term2</span> are equivalent <span class="IRI type">IRIs</span> as defined in <a href="http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref">6.4 RDF URI References</a> 
              of [<a href="#CONCEPTS">CONCEPTS</a>].</li>
              <li><span class="name">term1</span> and <span class="name">term2</span> are equivalent <span class="literal type">literals</span> as defined in <a class="norm" href="http://www.w3.org/TR/rdf-concepts/#section-Literal-Equality">6.5.1 Literal Equality</a> 
              of [<a href="#CONCEPTS">CONCEPTS</a>].</li>
              <li><span class="name">term1</span> and <span class="name">term2</span> are the same <span class="bnode type">blank node</span> as described in <a class="norm" href="http://www.w3.org/TR/rdf-concepts/#section-blank-nodes">6.6 Blank Nodes</a> 
              of [<a href="#CONCEPTS">CONCEPTS</a>].</li>
            </ul>

            <div class="exampleGroup">
              <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       "Alice".
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  foaf:name       "Ms A.".
_:b  foaf:mbox       &lt;mailto:alice@work.example&gt; .
              </pre>

              <div class="queryGroup">
                <p>This query finds the people who have multiple <code>foaf:name</code> triples:</p>
                <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name1 ?name2
WHERE { ?x foaf:name  ?name1 ;
        foaf:mbox  ?mbox1 .
        ?y foaf:name  ?name2 ;
        foaf:mbox  ?mbox2 .
        FILTER (?mbox1 = ?mbox2 &amp;&amp; ?name1 != ?name2)
      }</pre>

                <p>Query result:</p>

                <div class="result">
                  <table class="resultTable">
                    <tbody>
                      <tr>
                        <th>name1</th>
                        <th>name2</th>
                      </tr>

                      <tr>
                        <td>"Alice"</td>
                        <td>"Ms A."</td>
                      </tr>

                      <tr>
                        <td>"Ms A."</td>
                        <td>"Alice"</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>

            <p>In this query for documents that were annotated at a specific date and time (New Year's Day 2005, measures in timezone +00:00), the RDF terms are not the same, but have equivalent values:</p>

            <div class="exampleGroup">
              <pre class="data">@prefix a:          &lt;http://www.w3.org/2000/10/annotation-ns#&gt; .
@prefix dc:         &lt;http://purl.org/dc/elements/1.1/&gt; .

_:b   a:annotates   &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
_:b   dc:date       &quot;2004-12-31T19:00:00-05:00&quot;^^&lt;http://www.w3.org/2001/XMLSchema#dateTime&gt; .</pre>

              <div class="queryGroup">
                <pre class="query">PREFIX a:      &lt;http://www.w3.org/2000/10/annotation-ns#&gt;
PREFIX dc:     &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX xsd:    &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?annotates
WHERE { ?annot  a:annotates  ?annotates .
        ?annot  dc:date      ?date .
        FILTER ( ?date = xsd:dateTime(&quot;2005-01-01T00:00:00Z&quot;) ) 
      }</pre>

               <div class="result">
                 <table class="resultTable">
                   <tbody>
                     <tr>
                       <th>annotates</th>
                     </tr>
                     <tr>
                       <td>&lt;http://www.w3.org/TR/rdf-sparql-query/&gt;</td>
                     </tr>
                   </tbody>
                 </table>
              </div>
            </div>
          </div>

	  <div id="func-RDFterm-equal-foot1" class="footnote">
	    <p><sup>*</sup> Invoking RDFterm-equal on two typed literals tests for 
          equivalent values. An extended implementation may have support for additional datatypes. An implementation processing a query that tests for equivalence on unsupported datatypes (and non-identical lexical form and datatype IRI) returns an error, indicating that it was unable to determine whether or not the values are equivalent. For example, an unextended implementation will produce an error when testing either

          <span class="queryExcerpt untested"><code>"iiii"^^my:romanNumeral = "iv"^^my:romanNumeral</code></span> or
          <span class="queryExcerpt untested"><code>"iiii"^^my:romanNumeral != "iv"^^my:romanNumeral</code></span>.</p>
	  </div>

          </div4>
          <div4 id="func-sameTerm">
            <head class="SPARQLoperator">sameTerm</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">sameTerm</span> (<span class="type"><span class="type RDFterm">RDF term</span></span> <span class="name">term1</span>, <span class="type"><span class="type RDFterm">RDF term</span></span> <span class="name">term2</span>)</pre>

            <p>Returns TRUE if <code>term1</code> and <code>term2</code> are the same RDF term as defined in <a class="norm" href="http://www.w3.org/TR/rdf-concepts/">Resource Description Framework (RDF): Concepts and Abstract Syntax</a> [<a href="#CONCEPTS">CONCEPTS</a>]; returns FALSE otherwise.</p>

            <div class="exampleGroup">
              <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       "Alice".
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  foaf:name       "Ms A.".
_:b  foaf:mbox       &lt;mailto:alice@work.example&gt; .</pre>
 
              <div class="queryGroup">
                <p>This query finds the people who have multiple <code>foaf:name</code> triples:</p>
                <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name1 ?name2
WHERE { ?x foaf:name  ?name1 ;
        foaf:mbox  ?mbox1 .
         ?y foaf:name  ?name2 ;
         foaf:mbox  ?mbox2 .
         FILTER (sameTerm(?mbox1, ?mbox2) &amp;&amp; !sameTerm(?name1, ?name2))
      } </pre>

                <p>Query result:</p>

                <div class="result">
                  <table class="resultTable">
                    <tbody>
                      <tr>
                        <th>name1</th>
                        <th>name2</th>
                      </tr>
                      <tr>
                        <td>"Alice"</td>
                        <td>"Ms A."</td>
                      </tr>
                      <tr>
                        <td>"Ms A."</td>
                        <td>"Alice"</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>

            <p>Unlike <span class="operator">RDFterm-equal</span>, <span class="operator">sameTerm</span> can be used to test for non-equivalent <span class="type typedLiteral">typed literals</span> with unsupported datatypes:</p>

            <div class="exampleGroup">
              <pre class="data">@prefix :          &lt;http://example.org/WMterms#&gt; .
@prefix t:         &lt;http://example.org/types#&gt; .

_:c1  :label        "Container 1" .
_:c1  :weight       "100"^^t:kilos .
_:c1  :displacement  "100"^^t:liters .

_:c2  :label        "Container 2" .
_:c2  :weight       "100"^^t:kilos .
_:c2  :displacement  "85"^^t:liters .

_:c3  :label        "Container 3" .
_:c3  :weight       "85"^^t:kilos .
_:c3  :displacement  "85"^^t:liters .</pre>

              <div class="queryGroup">
                <pre class="query">PREFIX  :      &lt;http://example.org/WMterms#&gt;
PREFIX  t:     &lt;http://example.org/types#&gt;

SELECT ?aLabel1 ?bLabel
WHERE { ?a  :label        ?aLabel .
        ?a  :weight       ?aWeight .
        ?a  :displacement ?aDisp .

        ?b  :label        ?bLabel .
        ?b  :weight       ?bWeight .
        ?b  :displacement ?bDisp .

        FILTER ( sameTerm(?aWeight, ?bWeight) &amp;&amp; !sameTerm(?aDisp, ?bDisp)) }</pre>

                <div class="result">
                  <table class="resultTable">
                    <tbody>
                      <tr>
                        <th>aLabel</th>
                        <th>bLabel</th>
                      </tr>
                      <tr>
                        <td>"Container 1"</td>
                        <td>"Container 2"</td>
                      </tr>
                      <tr>
                        <td>"Container 2"</td>
                        <td>"Container 1"</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>

            <p>The test for boxes with the same weight may also be done with the '=' operator (<a href="#func-RDFterm-equal" class="SPARQLoperator">RDFterm-equal</a>) as the test for <code>"100"^^t:kilos = "85"^^t:kilos</code> will result in an error, eliminating that potential solution.</p>

          </div4>
          <div4 id="func-in">
          <head class="SPARQLoperator">IN</head>
          <pre class="prototype"><span class="return">boolean</span>  <code>rdfTerm</code> <span class="operator">IN</span> (<span class="expression">expression</span>, <span class="expression">...</span>)</pre>  

          <p>The <code>IN</code> operator tests whether the RDF term on the 
          left-hand side is found in the values of list of expressions 
          on the right-hand side. 
          The test is done with "=" operator, which tests for the same value, as
          determined by the <a href="#OperatorMapping">operator mapping</a>.
          </p>

          <p>A list of zero terms on the right-hand side is legal.</p>

          <p>Errors in comparisons cause the <code>IN</code> expression 
          to raise an error if the RDF term being tested is not found
          elsewhere in the list of terms.</p>

          <p>The <code>IN</code> operator is equivalent to the SPARQL expression:</p>
          <pre>(lhs = expression1) || (lhs = expression2) || ...</pre>

          <p>Examples:</p>
          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>2 IN (1, 2, 3)</code></td>
                  <td>true</td>
                </tr>
                <tr>
                  <td><code>2 IN ()</code></td>
                  <td>false</td>
                </tr>
                <tr>
                  <td><code>2 IN (&lt;http://example/iri&gt;, "str", 2.0)</code></td>
                  <td>true</td>
                </tr>

                <tr>
                  <td><code>2 IN (1/0, 2)</code></td>
                  <td>true</td>
                </tr>

                <tr>
                  <td><code>2 IN (2, 1/0)</code></td>
                  <td>true</td>
                </tr>
                <tr>
                  <td><code>2 IN (3, 1/0)</code></td>
                  <td>raises an error</td>
                </tr>

              </tbody>
            </table>
          </div>
        </div4>

        <div4 id="func-not-in">
          <head class="SPARQLoperator">NOT IN</head>
          <pre class="prototype"><span class="return">boolean</span>  <code>rdfTerm</code> <span class="operator">NOT IN</span> (<span class="expression">expression</span>, <span class="expression">...</span>)</pre>  

          <p>The <code>NOT IN</code> operator tests whether the RDF term on the 
          left-hand side is not found in the values of list of expressions 
          on the right-hand side. 
          The test is done with "!=" operator, which tests for not the same value, as
          determined by the <a href="#OperatorMapping">operator mapping</a>.</p>

          <p>A list of zero terms on the right-hand side is legal.</p>

          <p>Errors in comparisons cause the <code>NOT IN</code> expression 
          to raise an error if the RDF term being tested is not found
          to be in the list elsewhere in the list of terms.</p>

          <p>The <code>NOT IN</code> operator is equivalent to the SPARQL expression: </p>
          <pre>(lhs != expression1) &amp;&amp; (lhs != expression2) &amp;&amp; ...</pre>

          <p><code>NOT IN (...)</code> is equivalent to <code>!(IN (...))</code>.</p>

          <p>Examples:</p>
          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>2 NOT IN (1, 2, 3)</code></td>
                  <td>false</td>
                </tr>
                <tr>
                  <td><code>2 NOT IN ()</code></td>
                  <td>true</td>
                </tr>
                <tr>
                  <td><code>2 NOT IN (&lt;http://example/iri&gt;, "str", 2.0)</code></td>
                  <td>false</td>
                </tr>

                <tr>
                  <td><code>2 NOT IN (1/0, 2)</code></td>
                  <td>false</td>
                </tr>

                <tr>
                  <td><code>2 NOT IN (2, 1/0)</code></td>
                  <td>false</td>
                </tr>
                <tr>
                  <td><code>2 NOT IN (3, 1/0)</code></td>
                  <td>raises an error</td>
                </tr>
                
              </tbody>
            </table>
          </div>

        </div4>

        </div3>

        <div3 id="func-rdfTerms">
          <head>Functions on RDF Terms</head>

          <div4 id="func-isIRI">
            <head class="SPARQLoperator">isIRI</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">isIRI</span> (<span class="type">RDF term</span> <span class="name">term</span>)
 <span class="return">xsd:boolean</span>  <span class="operator">isURI</span> (<span class="type">RDF term</span> <span class="name">term</span>)</pre>

            <p>Returns <code>true</code> if <code>term</code> is an <span class="type IRI">IRI</span>. Returns <code>false</code> otherwise. <span class="operator">isURI</span> is an alternate spelling for the <span class="operator">isIRI</span> operator.</p>

            <div class="exampleGroup">
              <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       "Alice".
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  foaf:name       "Bob" .
_:b  foaf:mbox       "bob@work.example" .
              </pre>

              <div class="queryGroup">
                <p>This query matches the people with a <code>name</code> and an <code>mbox</code> which is an IRI:</p>
                <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
 WHERE { ?x foaf:name  ?name ;
            foaf:mbox  ?mbox .
         FILTER isIRI(?mbox) }</pre>

                <p>Query result:</p>

                <div class="result">
                  <table class="resultTable">
                    <tbody>
                      <tr>
                        <th>name</th>
                        <th>mbox</th>
                      </tr>
                      
                      <tr>
                        <td>"Alice"</td>
                        <td>&lt;mailto:alice@work.example&gt;</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div4>

          <div4 id="func-isBlank">
            <head class="SPARQLoperator">isBlank</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">isBlank</span> (<span class="type"><span class="type">RDF term</span></span> <span class="name">term</span>)</pre>

            <p>Returns <code>true</code> if <code>term</code> is a <span class="type bNode">blank node</span>. Returns <code>false</code> otherwise.</p>

            <div class="exampleGroup">
              <pre class="data">@prefix a:          &lt;http://www.w3.org/2000/10/annotation-ns#&gt; .
@prefix dc:         &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a   a:annotates   &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
_:a   dc:creator    &quot;Alice B. Toeclips&quot; .

_:b   a:annotates   &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
_:b   dc:creator    _:c .
_:c   foaf:given    &quot;Bob&quot;.
_:c   foaf:family   &quot;Smith&quot;.</pre>

              <div class="queryGroup">
                <p>This query matches the people with a <code>dc:creator</code> which uses
                predicates from the FOAF vocabulary to express the name. </p>
                <pre class="query">PREFIX a:      &lt;http://www.w3.org/2000/10/annotation-ns#&gt;
PREFIX dc:     &lt;http://purl.org/dc/elements/1.1/&gt;
PREFIX foaf:   &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT ?given ?family
WHERE { ?annot  a:annotates  &lt;http://www.w3.org/TR/rdf-sparql-query/&gt; .
  ?annot  dc:creator   ?c .
  OPTIONAL { ?c  foaf:given   ?given ; foaf:family  ?family } .
  FILTER isBlank(?c)
}</pre>
                <p>Query result:</p>

                <div class="result">
                  <table class="resultTable">
                    <tbody>
                      <tr>
                        <th>given</th>
                        <th>family</th>
                      </tr>

                      <tr>
                        <td>"Bob"</td>
                        <td>"Smith"</td>
                      </tr>
                    </tbody>
                  </table>
            </div></div></div>

            <p>In this example, there were two objects of <code>dc:creator</code> predicates, but only one (<code>_:c</code>) was a blank node.</p>

          </div4>

          <div4 id="func-isLiteral">
            <head class="SPARQLoperator">isLiteral</head>

            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">isLiteral</span> (<span class="type"><span class="type">RDF term</span></span> <span class="name">term</span>)</pre>

            <p>Returns <code>true</code> if <code>term</code> is a <span class="type literal">literal</span>. Returns <code>false</code> otherwise.</p>

            <div class="exampleGroup">
              <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .
              
_:a  foaf:name       "Alice".
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  foaf:name       "Bob" .
_:b  foaf:mbox       "bob@work.example" .</pre>

              <div class="queryGroup">
                <p>This query is similar to the one in <a href="#func-isIRI">17.4.2.1</a> except that is matches the people with a <code>name</code> and an <code>mbox</code> which is a literal. This could be used to look for erroneous data (<code>foaf:mbox</code> should only have an 
                IRI as its object).</p>
                <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
WHERE { ?x foaf:name  ?name ;
        foaf:mbox  ?mbox .
        FILTER isLiteral(?mbox) }</pre>

                <p>Query result:</p>

                <div class="result">
                  <table class="resultTable">
                    <tbody>
                      <tr>
                        <th>name</th>
                        <th>mbox</th>
                      </tr>

                      <tr>
                        <td>"Bob"</td>
                        <td>"bob@work.example"</td>
                      </tr>
                    </tbody>
                  </table>
            </div></div></div>

          </div4>
          <div4 id="func-isNumeric">
            <head class="SPARQLoperator">isNumeric</head>
            <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">isNumeric</span> (<span class="type"><span class="type">RDF term</span></span> <span class="name">term</span>)</pre>
            <p>Returns <code>true</code> if <code>term</code> is a numeric value. Returns <code>false</code> otherwise.
            <code>term</code> 
            is numeric if it has an appropriate datatype (see the section <a href="#operandDataTypes">Operand Data Types</a>) and has a valid lexical form, making it
            a valid argument to functions and operators
            taking numeric arguments.
            </p>

            <p>Examples:</p>
            <div class="result">
              <table>
                <tbody>
                  <tr>
                    <td><code>isNumeric(12)</code></td>
                    <td>true</td>
                  </tr>
                  <tr>
                    <td><code>isNumeric("12")</code></td>
                    <td>false</td>
                  </tr>
                  <tr>
                    <td><code>isNumeric("12"^^xsd:nonNegativeInteger)</code></td>
                    <td>true</td>
                  </tr>
                  <tr>
                    <td><code>isNumeric("1200"^^xsd:byte)</code></td>
                    <td>false</td>
                  </tr>
                  <tr>
                    <td><code>isNumeric(&lt;http://example/&gt;)</code></td>
                    <td>false</td>
                  </tr>
                </tbody>
              </table>
            </div>

          </div4>

            <div4 id="func-str">
          <head class="SPARQLoperator">str</head>

  <pre class="prototype"> <span class="return"><span class="type">simple literal</span></span>  <span class="operator">STR</span> (<span class="type"><span class="type literal">literal</span></span> <span class="name">ltrl</span>)
 <span class="return"><span class="type">simple literal</span></span>  <span class="operator">STR</span> (<span class="type"><span class="type IRI">IRI</span></span> <span class="name">rsrc</span>)
</pre>

    <p>Returns the <span class="type lexicalForm">lexical form</span> of <code>ltrl</code> (a <span class="type literal">literal</span>); returns the codepoint representation of <code>rsrc</code> (an <span class="type IRI">IRI</span>). This is useful for examining parts of an IRI, for instance, the host-name.</p>

  <div class="exampleGroup">
  <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       "Alice".
_:a  foaf:mbox       &lt;mailto:alice@work.example&gt; .

_:b  foaf:name       "Bob" .
_:b  foaf:mbox       &lt;mailto:bob@home.example&gt; .
</pre>

  <div class="queryGroup">
  <p>This query selects the set of people who use their <code>work.example</code> address in their foaf profile:</p>
  <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
 WHERE { ?x foaf:name  ?name ;
            foaf:mbox  ?mbox .
         FILTER regex(str(?mbox), &quot;@work\\.example$&quot;) }
</pre>

  <p>Query result:</p>

  <div class="result">
      <table class="resultTable">
        <tbody>
          <tr>
            <th>name</th>
            <th>mbox</th>
          </tr>

          <tr>
            <td>"Alice"</td>
            <td>&lt;mailto:alice@work.example&gt;</td>
          </tr>
        </tbody>
      </table>
  </div></div></div>

        </div4>
            <div4 id="func-lang">
          <head class="SPARQLoperator">lang</head>

  <pre class="prototype"> <span class="return"><span class="type">simple literal</span></span>  <span class="operator">LANG</span> (<span class="type"><span class="type literal">literal</span></span> <span class="name">ltrl</span>)
</pre>

    <p>Returns the <span class="type langTag">language tag</span> of <code>ltrl</code>, if it has one. It returns <code>""</code> if <code>ltrl</code> has no <span class="type langTag">language tag</span>. Note that the RDF data model does not include literals with an empty <span class="type langTag">language tag</span>.</p>

  <div class="exampleGroup">
  <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       "Robert"@en.
_:a  foaf:name       "Roberto"@es.
_:a  foaf:mbox       &lt;mailto:bob@work.example&gt; .
</pre>

  <div class="queryGroup">
  <p>This query finds the Spanish <code>foaf:name</code> and <code>foaf:mbox</code>:</p>
  <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name ?mbox
 WHERE { ?x foaf:name  ?name ;
            foaf:mbox  ?mbox .
         FILTER ( lang(?name) = "es" ) }</pre>

  <p>Query result:</p>

  <div class="result">
      <table class="resultTable">
        <tbody>
          <tr>
            <th>name</th>
            <th>mbox</th>
          </tr>

          <tr>
            <td>"Roberto"@es</td>
            <td>&lt;mailto:bob@work.example&gt;</td>
          </tr>
        </tbody>
      </table>
  </div></div></div>

        </div4>
            <div4 id="func-datatype">
          <head class="SPARQLoperator">datatype</head>

  <pre class="prototype"> <span class="return"><span class="type IRI">iri</span></span>  <span class="operator">DATATYPE</span> (<span class="type"><span class="type">literal</span></span> <span class="name">literal</span>)
</pre>

    <p>Returns the <span class="type datatypeIRI">datatype IRI</span> of a <code>literal</code>. </p>
    <ul>
      <li>If the literal is a typed literal, return the datatype IRI.</li>
      <li>If the literal is a simple literal, return <code>xsd:string</code></li>
      <li>If the literal is literal with a language tag, return <code>rdf:langString</code></li>
    </ul>

  <div class="exampleGroup">
  <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix eg:         &lt;http://biometrics.example/ns#&gt; .
@prefix xsd:        &lt;http://www.w3.org/2001/XMLSchema#&gt; .

_:a  foaf:name       "Alice".
_:a  eg:shoeSize     "9.5"^^xsd:float .

_:b  foaf:name       "Bob".
_:b  eg:shoeSize     "42"^^xsd:integer .
</pre>

  <div class="queryGroup">
  <p>This query finds the <code>foaf:name</code> and <code>foaf:shoeSize</code> of everyone with a shoeSize that is an integer:</p>
  <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX xsd:  &lt;http://www.w3.org/2001/XMLSchema#&gt;
PREFIX eg:   &lt;http://biometrics.example/ns#&gt;
SELECT ?name ?shoeSize
 WHERE { ?x foaf:name  ?name ; eg:shoeSize  ?shoeSize .
         FILTER ( datatype(?shoeSize) = xsd:integer ) }</pre>

  <p>Query result:</p>

  <div class="result">
      <table class="resultTable">
        <tbody>
          <tr>
            <th>name</th>
            <th>shoeSize</th>
          </tr>

          <tr>
            <td>"Bob"</td>
            <td>42</td>
          </tr>
        </tbody>
      </table>
    </div></div></div>

    <div class="note">
      <p>In <a href="http://www.w3.org/TR/rdf-sparql-query/">SPARQL 1.0</a>, the 
      <code>DATATYPE</code> function was not defined for literals with a language tag.
      Therefore, an unextended implementation would raise an error when <code>DATATYPE</code>
      was called with a literal with a language tag.  <a 
      href="#operatorExtensibility">Operator extensibility</a> allows implementations to
      return a result rather than raise an error.  SPARQL 1.1 defines the result of
      <code>DATATYPE</code> applied to a literal with a language tag to be 
      <code>rdf:langString</code>.
      </p>
    </div>

    <div class="wgNote">
      The SPARQL Working Group is using <code>rdf:langString</code> based on the latest Working Drafts of the RDF Working Group.   This usage should be considered experimental (and non-normative) until/unless <code>rdf:langString</code> becomes part of an updated RDF Recommendation.
    </div>


        </div4>
        <div4 id="func-iri">
          <head class="SPARQLoperator">IRI</head>
          <pre class="prototype"> <span class="return">iri</span>  <span class="operator">IRI</span>(<code>simple literal</code>)
 <span class="return">iri</span>  <span class="operator">IRI</span>(<span class="type">xsd:string</span>)
 <span class="return">iri</span>  <span class="operator">IRI</span>(<span class="type">iri</span>)
 <span class="return">iri</span>  <span class="operator">URI</span>(<code>simple literal</code>)
 <span class="return">iri</span>  <span class="operator">URI</span>(<span class="type">xsd:string</span>)
 <span class="return">iri</span>  <span class="operator">URI</span>(<span class="type">iri</span>)</pre>

          <p>The <code>IRI</code> function constructs an IRI by resolving the string argument
          (see <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>
	  and <a href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>
          or any later RFC that superceeds RFC 3986 or RFC 3987).
	  The IRI is resolved against the base IRI of the query and must result 
          in an absolute IRI.
          </p>

	  <p>The <code>URI</code> function is a synonym for <a href="#func-iri"><code>IRI</code></a>.</p>

          <p>If the function is passed an IRI, it returns the IRI unchanged. </p>

          <p>Passing any RDF term other than a simple literal, xsd:string or an IRI is an error.</p>

          <p>An implementation &MAY; normalize the IRI.</p>

          <p>Examples:</p>
          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>IRI("http://example/")</code></td>
                  <td>&lt;http://example/&gt;</td>
                </tr>
                <tr>
                  <td><code>IRI(&lt;http://example/&gt;)</code></td>
                  <td>&lt;http://example/&gt;</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div4>

        <div4 id="func-bnode">
          <head class="SPARQLoperator">BNODE</head>

          <pre class="prototype"><span class="return">blank node</span>  <span class="operator">BNODE</span>()</pre>
          <pre class="prototype"><span class="return">blank node</span>  <span class="operator">BNODE</span>(<span class="type">simple literal</span>)</pre>
          <pre class="prototype"><span class="return">blank node</span>  <span class="operator">BNODE</span>(<span class="type">xsd:string</span>)</pre>

          <p>The <code>BNODE</code> function constructs a blank node that is distinct
          from all blank nodes in the dataset being queried and distinct
          from all blank nodes created by calls to this constructor
          for other query solutions. If the no argument form is used,
          every call results in a distinct blank node. If the form with
          a simple literal is used, every call results in distinct blank nodes
          for different simple literals, and the same blank node
          for calls with the same simple literal within expressions for
          one <a href="#defn_sparqlSolutionMapping">solution mapping</a>.</p>

          <p>This functionality is compatible with the <a href="#tempatesWithBNodes">treatment 
          of blank nodes in SPARQL CONSTRUCT templates</a>.</p>

        </div4>

        <div4 id="func-strdt">
          <head class="SPARQLoperator">STRDT</head>

          <pre class="prototype"><span class="return">literal</span>  <span class="operator">STRDT</span>(<span class="type">simple literal</span> lexicalForm, <span class="type">IRI</span> datatypeIRI)</pre>

          <p>The <code>STRDT</code> function constructs a literal with lexical 
          form and type as specified by the arguments.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>STRDT("123", xsd:integer)</code></td>
                  <td>"123"^^&lt;http://www.w3.org/2001/XMLSchema#integer&gt;</td>
                </tr>
                <tr>
                  <td><code>STRDT("iiii", &lt;http://example/romanNumeral&gt;)</code></td>
                  <td>"iiii"^^&lt;http://example/romanNumeral&gt;</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div4>

        <div4 id="func-strlang">
          <head class="SPARQLoperator">STRLANG</head>
          <pre class="prototype"><span class="return">literal</span>  <span class="operator">STRLANG</span>(<span class="type">simple literal</span> lexicalForm, <span class="type">simple literal</span> langTag)</pre>

          <p>The <code>STRLANG</code> function constructs a literal with
          lexical form and language tag as specified by the arguments.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>STRLANG("chat", "en")</code></td>
                  <td>"chat"@en</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div4>

	<div4 id="func-uuid">
	   <head class="SPARQLoperator">UUID</head>
	   <pre class="prototype"><span class="return">iri</span>  <span class="operator">UUID</span>()</pre>
	   <p>Return a fresh IRI from the 
	   <a href="http://www.ietf.org/rfc/rfc4122.txt">UUID URN scheme</a>. 
	   Each call of <code>UUID()</code>
	   returns a different UUID. It must not be the "nil" UUID (all zeroes).
	   The variant and version of the UUID is 
	   implementation dependent.</p>
	   <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>UUID()</code></td>
		    <td><code>&lt;urn:uuid:b9302fb5-642e-4d3b-af19-29a8f6d894c9&gt;</code></td>
		  </tr>
		</tbody>
	     </table>
	   </div>
	</div4>
	<div4 id="func-struuid">
	  <head class="SPARQLoperator">STRUUID</head>
	  <pre class="prototype"><span class="return">simple literal</span>  <span class="operator">STRUUID</span>()</pre>
	  <p>Return a string that is the scheme specific part of UUID.  
	  That is, as a simple literal, the result of generating a UUID, converting to a
	  simple literal and removing the initial <code>urn:uuid:</code>.
	  </p>
	   <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>STRUUID()</code></td>
		    <td><code>"73cd4307-8a99-4691-a608-b5bda64fb6c1"</code></td>
		  </tr>
		</tbody>
	     </table>
	   </div>

	</div4>
        </div3>

	<div3 id="func-strings">
	  <head>Functions on Strings</head>

	  <div4>
	    <head>Strings in SPARQL Functions</head>
	    <div5 id="func-string">
	      <head>String arguments</head>
	      <p>Certain functions (e.g.  <a href="#func-regex">REGEX</a>,
	      <a href="#func-strlen">STRLEN</a>, <a href="#func-contains">CONTAINS</a>)
	      take a <code>string literal</code> as an argument and accept a simple literal,
	      a plain literal with language tag, or a literal with datatype xsd:string.
	      They then act on the lexcial form of the literal.</p>

	      <p>The term <code>string literal</code> is used in the function descriptions for this.
	      Use of any other RDF term will cause a call to the function to raise an error.</p>
	    </div5>
	    <div5 id="func-arg-compatibility">
	      <head>Argument Compatibility Rules</head>
	      <p>The functions
	      <a href="#func-strstarts">STRSTARTS</a>,
	      <a href="#func-strends">STRENDS</a>,
	      <a href="#func-contains">CONTAINS</a>,
	      <a href="#func-strbefore">STRBEFORE</a> and 
	      <a href="#func-strafter">STRAFTER</a> take two arguments. 
	      These arguments must be compatible otherwise invocation of
	      one of these functions raises an error.
	      </p>

	      <p>Compatibility of two arguments is defined as:
	      </p>
	      <ul>
		<li>The arguments are simple literals or literals typed as xsd:string</li>
		<li>The arguments are plain literals with identical language tags</li>
		<li>The first argument is a plain literal with language tag
		and the second argument is a simple literal or literal typed as xsd:string</li>
	      </ul>

	      <div class="result">
		<table>
		  <tbody>
		    <tr>
		      <th>Argument1</th>
		      <th>Argument2</th>
		      <th>Compatible?</th>
		    </tr>
		    <tr>  <td>"abc"</td>      <td>"b"</td>              <td>yes</td> </tr>
		    <tr>  <td>"abc"</td>      <td>"b"^^xsd:string</td>  <td>yes</td> </tr>
		    <tr>  <td>"abc"^^xsd:string</td>  <td>"b"</td>      <td>yes</td> </tr>
		    <tr>  <td>"abc"^^xsd:string</td>  <td>"b"^^xsd:string</td>      <td>yes</td> </tr>

		    <tr>  <td>"abc"@en</td>  <td>"b"</td>               <td>yes</td> </tr>
		    <tr>  <td>"abc"@en</td>  <td>"b"^^xsd:string</td>   <td>yes</td> </tr>
		    <tr>  <td>"abc"@en</td>  <td>"b"@en</td>            <td>yes</td> </tr>
		    <tr>  <td>"abc"@fr</td>  <td>"b"@ja</td>            <td>no</td>  </tr>
		    <tr>  <td>"abc"</td>     <td>"b"@ja</td>            <td>no</td>  </tr>
		    <tr>  <td>"abc"</td>     <td>"b"@en</td>            <td>no</td>  </tr>
		    <tr>  <td>"abc"^^xsd:string</td>  <td>"b"@en</td>   <td>no</td>  </tr>
		  </tbody>
		</table>
	      </div>
	    </div5>

	    <div5>
	      <head>String Literal Return Type</head>
	      <p>Functions that return a string literal do so with the string literal 
	      of the same kind as the first argument (simple literal, plain literal 
	      with same language tag, xsd:string).  This includes <a href="#func-substr">SUBSTR</a>,
	      <a href="#func-strbefore">STRBEFORE</a> and 
	      <a href="#func-strafter">STRAFTER</a>.</p>
	      <p>The function <a href="#func-concat">CONCAT</a> returns a string literal
	      based on the details of all its arguments.</p>
	    </div5>
	  </div4>
	  
	  <div4 id="func-strlen">
	    <head class="SPARQLoperator">STRLEN</head>
	    <pre class="prototype"><span class="return">xsd:integer</span>  <span class="operator">STRLEN</span>(<span class="type">string literal</span> str)</pre>

	    <p>The <code>strlen</code> function corresponds to the 
	    XPath <a href="http://www.w3.org/TR/xpath-functions/#func-string-length">fn:string-length</a> 
	    function and returns an <code>xsd:integer</code> equal to the length
	    in characters of the lexical form of the literal. </p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>strlen("chat")</code></td>
		    <td>4</td>
		  </tr>
		  <tr>
		    <td><code>strlen("chat"@en)</code></td>
		    <td>4</td>
		  </tr>
		  <tr>
		    <td><code>strlen("chat"^^xsd:string)</code></td>
		    <td>4</td>
		  </tr>
		</tbody>
	      </table>
	    </div>
	    
	  </div4>

	  <div4 id="func-substr">
	    <head class="SPARQLoperator">SUBSTR</head>
	    <pre class="prototype"><span class="return">string literal</span>  <span class="operator">SUBSTR</span>(<span class="type">string literal</span> source, <span class="type">xsd:integer</span> startingLoc)</pre>
	    <pre class="prototype"><span class="return">string literal</span>  <span class="operator">SUBSTR</span>(<span class="type">string literal</span> source, <span class="type">xsd:integer</span> startingLoc, <span class="type">xsd:integer</span> length)</pre>

	    <p>The <code>substr</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-substring">fn:substring</a> 
	    function and returns a literal of the same kind (simple literal, literal with language tag, 
	    <code>xsd:string</code> typed literal) as the <code>source</code> input parameter but
	    with a lexical form formed from the substring of the lexcial form of the source.</p>

	    <p>The arguments <code>startingLoc</code> and <code>length</code> may be derived types of xsd:integer.</p>

	    <p>The index of the first character in a strings is 1.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>substr("foobar", 4)</code></td>
		    <td>"bar"</td>
		  </tr>
		  <tr>
		    <td><code>substr("foobar"@en, 4)</code></td>
		    <td>"bar"@en</td>
		  </tr>
		  <tr>
		    <td><code>substr("foobar"^^xsd:string, 4)</code></td>
		    <td>"bar"^^xsd:string</td>
		  </tr>
		  <tr>
		    <td><code>substr("foobar", 4, 1)</code></td>
		    <td>"b"</td>
		  </tr>
		  <tr>
		    <td><code>substr("foobar"@en, 4, 1)</code></td>
		    <td>"b"@en</td>
		  </tr>
		  <tr>
		    <td><code>substr("foobar"^^xsd:string, 4, 1)</code></td>
		    <td>"b"^^xsd:string</td>
		  </tr>
		</tbody>
	      </table>
	    </div>
	  </div4>

	  <div4 id="func-ucase">
	    <head class="SPARQLoperator">UCASE</head>
	    <pre class="prototype"><span class="return">string literal</span>  <span class="operator">UCASE</span>(<span class="type">string literal</span> str)</pre>

	    <p>The <code>UCASE</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-upper-case">fn:upper-case</a> function. 
	    It returns a string literal whose lexical form is the upper case of the
	    lexcial form of the argument.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>ucase("foo")</code></td>
		    <td>"FOO"</td>
		  </tr>
		  <tr>
		    <td><code>ucase("foo"@en)</code></td>
		    <td>"FOO"@en</td>
		  </tr>
		  <tr>
		    <td><code>ucase("foo"^^xsd:string)</code></td>
		    <td>"FOO"^^xsd:string</td>
		  </tr>
		</tbody>
	      </table>
	    </div>
	  </div4>

	  <div4 id="func-lcase">
	    <head class="SPARQLoperator">LCASE</head>
	    <pre class="prototype"><span class="return">string literal</span>  <span class="operator">LCASE</span>(<span class="type">string literal</span> str)</pre>

	    <p>The <code>LCASE</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-lower-case">fn:lower-case</a> function. 
	    It returns a string literal whose lexical form is the lower case of the
	    lexcial form of the argument.</p>
	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>lcase("BAR")</code></td>
		    <td>"bar"</td>
		  </tr>
		  <tr>
		    <td><code>lcase("BAR"@en)</code></td>
		    <td>"bar"@en</td>
		  </tr>
		  <tr>
		    <td><code>lcase("BAR"^^xsd:string)</code></td>
		    <td>"bar"^^xsd:string</td>
		  </tr>
		</tbody>
	      </table>
	    </div>         
	  </div4>

	  <div4 id="func-strstarts">
	    <head class="SPARQLoperator">STRSTARTS</head>
	    <pre class="prototype"><span class="return">xsd:boolean</span>  <span class="operator">STRSTARTS</span>(<span class="type">string literal</span> arg1, <span class="type">string literal</span> arg2)</pre>

	    <p>The <code>STRSTARTS</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-starts-with">fn:starts-with</a> function.  
	    The arguments must be <a href="#func-arg-compatibility">argument compatible</a>
	    otherwise an error is raised.</p>

	    <p>For such input pairs, the function returns true if the lexical form of <code>arg1</code> 
	    starts with the lexical form of <code>arg2</code>, otherwise it returns false.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>strStarts("foobar", "foo")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strStarts("foobar"@en, "foo"@en)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strStarts("foobar"^^xsd:string, "foo"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strStarts("foobar"^^xsd:string, "foo")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strStarts("foobar", "foo"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strStarts("foobar"@en, "foo")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strStarts("foobar"@en, "foo"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		</tbody>
	      </table>
	    </div>           
	  </div4>

          <div4 id="func-strends">
            <head class="SPARQLoperator">STRENDS</head>

	    <pre class="prototype"><span class="return">xsd:boolean</span>  <span class="operator">STRENDS</span>(<span class="type">string literal</span> arg1, <span class="type">string literal</span> arg2)</pre>

	    <p>The <code>STRENDS</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-ends-with">fn:ends-with</a> function.  
	    The arguments must be <a href="#func-arg-compatibility">argument compatible</a>
	    otherwise an error is raised.</p>

	    <p>For such input pairs, the function returns true if the lexical form of <code>arg1</code> 
	    ends with the lexical form of <code>arg2</code>, otherwise it returns false.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>strEnds("foobar", "bar")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strEnds("foobar"@en, "bar"@en)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strEnds("foobar"^^xsd:string, "bar"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strEnds("foobar"^^xsd:string, "bar")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strEnds("foobar", "bar"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strEnds("foobar"@en, "bar")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>strEnds("foobar"@en, "bar"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		</tbody>
	      </table>
	    </div>         
	  </div4>


	  <div4 id="func-contains">
	    <head class="SPARQLoperator">CONTAINS</head>
	    <pre class="prototype"><span class="return">xsd:boolean</span>  <span class="operator">CONTAINS</span>(<span class="type">string literal</span> arg1, <span class="type">string literal</span> arg2)</pre>

	    <p>The <code>CONTAINS</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-contains">fn:contains</a>. 
	    The arguments must be <a href="#func-arg-compatibility">argument compatible</a>
	    otherwise an error is raised.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>contains("foobar", "bar")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>contains("foobar"@en, "foo"@en)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>contains("foobar"^^xsd:string, "bar"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>contains("foobar"^^xsd:string, "foo")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>contains("foobar", "bar"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>contains("foobar"@en, "foo")</code></td>
		    <td>true</td>
		  </tr>
		  <tr>
		    <td><code>contains("foobar"@en, "bar"^^xsd:string)</code></td>
		    <td>true</td>
		  </tr>
		</tbody>
	      </table>
	    </div> 
	  </div4>

          <div4 id="func-strbefore">
	    <head class="SPARQLoperator">STRBEFORE</head>
	    <pre class="prototype"><span class="return">literal</span>  <span class="operator">STRBEFORE</span>(<span class="type">string literal</span> arg1, <span class="type">string literal</span> arg2)</pre>

	    <p>The <code>STRBEFORE</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-substring-before">fn:substring-before</a> function.  
	    The arguments must be <a href="#func-arg-compatibility">argument compatible</a>
	    otherwise an error is raised.</p>

	    <p>
	      For compatible arguments, if the lexical part of the second argument 
	      occurs as a substring of the lexical part of the first argument, the 
	      function returns a literal of the same kind as the first argument 
	      <code>arg1</code> (simple literal, plain literal same language tag, xsd:string).
	      The lexical form of
	      the result is the substring of the lexical form of <code>arg1</code>
	      that precedes the first occurrence of
	      the lexical form of <code>arg2</code>.  
	      If the lexical form of <code>arg2</code>
	      is the empty string, this is considered to be a match and the lexical 
	      form of the result is the empty string.
	    </p>
	    <p>
	      If there is no such occurrence, an empty simple literal is returned.
	    </p>

	    <div class="result">
            <table>
              <tbody>
                <tr>
		  <td>strbefore("abc","b")</td>  <td>"a"</td>
		</tr>
		<tr>
		  <td>strbefore("abc"@en,"bc")</td>  <td>"a"@en</td>
		</tr>
		<tr>
		  <td>strbefore("abc"@en,"b"@cy)</td>  <td>error</td>
		</tr>
		<tr>
		  <td>strbefore("abc"^^xsd:string,"")</td>  <td>""^^xsd:string</td>
		</tr>
		<tr>
		  <td>strbefore("abc","xyz")</td>  <td>""</td>
		</tr>
		  <tr>
		    <td>strbefore("abc"@en, "z"@en)</td> <td>""</td>
		  </tr>
		  <tr>
		    <td>strbefore("abc"@en, "z")</td> <td>""</td>
		  </tr>
		  <tr>
		    <td>strbefore("abc"@en, ""@en)</td> <td>""@en</td>
		  </tr>
		  <tr>
		    <td>strbefore("abc"@en, "")</td> <td>""@en</td>
		  </tr>
	      </tbody>
	      </table>
	    </div>  	
	  </div4>

          <div4 id="func-strafter">
	    <head class="SPARQLoperator">STRAFTER</head>
	    <pre class="prototype"><span class="return">literal</span>  <span class="operator">STRAFTER</span>(<span class="type">string literal</span> arg1, <span class="type">string literal</span> arg2)</pre>

	    <p>The <code>STRAFTER</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-substring-after">fn:substring-after</a> function.  
	    The arguments must be <a href="#func-arg-compatibility">argument compatible</a>
	    otherwise an error is raised.</p>

	    <p>
	      For compatible arguments, if the lexical part of the second argument 
	      occurs as a substring of the lexical part of the first argument, the 
	      function returns a literal of the same kind as the first argument 
	      <code>arg1</code> (simple literal, plain literal same language tag, xsd:string).

	      The lexical form of
	      the result is the substring of the lexcial form of <code>arg1</code>
	      that follows the first occurrence of
	      the lexical form of <code>arg2</code>.  
	      If the lexical form of <code>arg2</code>
	      is the empty string, this is considered to be a match and the lexical 
	      form of the result is the lexical form of <code>arg1</code>.

	    </p>
	    <p>
	      If there is no such occurrence, an empty simple literal is returned.
	    </p>
	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td>strafter("abc","b")</td>  <td>"c"</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"@en,"ab")</td>  <td>"c"@en</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"@en,"b"@cy)</td>  <td>error</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"^^xsd:string,"")</td>  <td>"abc"^^xsd:string</td>
		  </tr>
		  <tr>
		    <td>strafter("abc","xyz")</td>  <td>""</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"@en, "z"@en)</td> <td>""</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"@en, "z")</td> <td>""</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"@en, ""@en)</td> <td>"abc"@en</td>
		  </tr>
		  <tr>
		    <td>strafter("abc"@en, "")</td> <td>"abc"@en </td>
		  </tr>
		</tbody>
	      </table>
	    </div>  	
	  </div4>

	  <div4 id="func-encode">
	    <head class="SPARQLoperator">ENCODE_FOR_URI</head>
	    <pre class="prototype"><span class="return">simple literal</span>  <span class="operator">ENCODE_FOR_URI</span>(<span class="type">string literal</span> ltrl)</pre>

	    <p>The <code>ENCODE_FOR_URI</code> function corresponds to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-encode-for-uri">fn:encode-for-uri</a> function. 
	    It returns a simple literal with the lexical form obtained from the lexical
	    form of its input after translating reserved characters according to the 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-encode-for-uri">fn:encode-for-uri</a> function.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>encode_for_uri("Los Angeles")</code></td>
		    <td><code>"Los%20Angeles"</code></td>
		  </tr>
		  <tr>
		    <td><code>encode_for_uri("Los Angeles"@en)</code></td>
		    <td><code>"Los%20Angeles"</code></td>
		  </tr>
		  <tr>
		    <td><code>encode_for_uri("Los Angeles"^^xsd:string)</code></td>
		    <td><code>"Los%20Angeles"</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
	  </div4>
	  
	  <div4 id="func-concat">
	    <head class="SPARQLoperator">CONCAT</head>
	    <pre class="prototype"><span class="return">string literal</span>  <span class="operator">CONCAT</span>(<span class="type">string literal</span> <span>ltrl<sub>1</sub></span> ... <span class="type">string literal</span> <span>ltrl<sub>n</sub></span>)</pre>
	    <p>The <code>CONCAT</code> function corresponds to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-concat">fn:concat</a> function. The function accepts string literals as arguments.</p>

	    <p>The lexical form of the returned literal is obtained by concatenating the lexical forms of its inputs.
	    If all input literals are typed literals of type <code>xsd:string</code>, then the returned literal is also of type <code>xsd:string</code>, if all input literals are plain literals with identical language tag, then the returned literal is a plain literal with the same language tag, in all other cases, the returned literal is a simple literal.</p>
	    
          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>concat("foo", "bar")</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo"@en, "bar"@en)</code></td>
                  <td>"foobar"@en</td>
                </tr>
                <tr>
                  <td><code>concat("foo"^^xsd:string, "bar"^^xsd:string)</code></td>
                  <td>"foobar"^^xsd:string</td>
                </tr>
                <tr>
                  <td><code>concat("foo", "bar"^^xsd:string)</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo"@en, "bar")</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo"@en, "bar"^^xsd:string)</code></td>
                  <td>"foobar"</td>
                </tr>
	      </tbody>
	    </table>
	    </div>  
          </div4>
	  
          <div4 id="func-langMatches">
          <head class="SPARQLoperator">langMatches</head>

  <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">langMatches</span> (<span class="type"><span class="type">simple literal</span></span> <span class="name">language-tag</span>, <span class="type"><span class="type">simple literal</span></span> <span class="name">language-range</span>)
</pre>

    <p>Returns <code>true</code> if <code>language-tag</code> (first argument) matches <code>language-range</code> (second argument) per the basic filtering scheme defined in  [<a href="#rfc4647">RFC4647</a>] section 3.3.1. <code>language-range</code> is a basic language range  per <a class="norm" href="http://www.ietf.org/rfc/rfc4647.txt">Matching of Language Tags</a> [<a href="#rfc4647">RFC4647</a>] section 2.1. A <code>language-range</code> of "*" matches any non-empty <code>language-tag</code> string.</p>

  <div class="exampleGroup">
  <pre class="data">@prefix dc:       &lt;http://purl.org/dc/elements/1.1/&gt; .

_:a  dc:title         "That Seventies Show"@en .
_:a  dc:title         "Cette S&eacute;rie des Ann&eacute;es Soixante-dix"@fr .
_:a  dc:title         "Cette S&eacute;rie des Ann&eacute;es Septante"@fr-BE .
_:b  dc:title         "Il Buono, il Bruto, il Cattivo" .
</pre>

  <div class="queryGroup">
  <p>This query uses 
  <a href="#func-langMatches"><code>langMatches</code></a> and 
  <a href="#func-lang"><code>lang</code></a>
    to find the French titles for the show known in English as "That Seventies Show":</p>
  <pre class="query">PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
SELECT ?title
 WHERE { ?x dc:title  "That Seventies Show"@en ;
            dc:title  ?title .
         FILTER langMatches( lang(?title), "FR" ) }</pre>

  <p>Query result:</p>

  <div class="result">
      <table class="resultTable">
        <tbody>
          <tr>
            <th>title</th>
          </tr>
          <tr> <td>"Cette S&eacute;rie des Ann&eacute;es Soixante-dix"@fr</td> </tr>
          <tr> <td>"Cette S&eacute;rie des Ann&eacute;es Septante"@fr-BE</td> </tr>
        </tbody>
      </table>
  </div></div>

  <div class="queryGroup">
  <p>The idiom <code>langMatches( lang( ?v ), "*" )</code> will not match literals without a language tag as <code>lang( ?v )</code> will return an empty string, so</p>

  <pre class="query add">PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
SELECT ?title
 WHERE { ?x dc:title  ?title .
         FILTER langMatches( lang(?title), "*" ) }</pre>

  <p>will report all of the titles with a language tag:</p>

  <div class="result add">
      <table class="resultTable">
        <tbody>
          <tr>
            <th>title</th>
          </tr>
          <tr> <td>"That Seventies Show"@en</td> </tr>
          <tr> <td>"Cette S&eacute;rie des Ann&eacute;es Soixante-dix"@fr</td> </tr>
          <tr> <td>"Cette S&eacute;rie des Ann&eacute;es Septante"@fr-BE</td> </tr>
        </tbody>
      </table>
  </div></div></div>

        </div4>
            <div4 id="func-regex">
          <head class="SPARQLoperator">REGEX</head>

  <pre class="prototype"> <span class="return">xsd:boolean</span>  <span class="operator">REGEX</span> (<span class="type"><span class="type">string literal</span></span> <span class="name">text</span>, <span class="type"><span class="type">simple literal</span></span> <span class="name">pattern</span>)
 <span class="return">xsd:boolean</span>  <span class="operator">REGEX</span> (<span class="type"><span class="type">string literal</span></span> <span class="name">text</span>, <span class="type"><span class="type">simple literal</span></span> <span class="name">pattern</span>, <span class="type"><span class="type">simple literal</span></span> <span class="name">flags</span>)
</pre>

    <p>Invokes the XPath <a class="norm" href="http://www.w3.org/TR/xpath-functions/#func-matches">fn:matches</a> function to match <code>text</code> against a regular expression <code>pattern</code>. The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators section <a class="norm" href="http://www.w3.org/TR/xpath-functions/#regex-syntax">7.6.1 Regular Expression Syntax</a> [<a href="#FUNCOP">FUNCOP</a>].</p>


  <div class="exampleGroup">
  <pre class="data">@prefix foaf:       &lt;http://xmlns.com/foaf/0.1/&gt; .

_:a  foaf:name       "Alice".
_:b  foaf:name       "Bob" .
</pre>

  <div class="queryGroup">
  <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
SELECT ?name
 WHERE { ?x foaf:name  ?name
         FILTER regex(?name, "^ali", "i") }
</pre>

  <p>Query result:</p>

  <div class="result">
      <table class="resultTable">
        <tbody>
          <tr>
            <th>name</th>
          </tr>

          <tr>
            <td>"Alice"</td>
          </tr>
        </tbody>
      </table>
  </div>
</div>
    </div>
      
        </div4>

	  <div4 id="func-replace">
	    <head class="SPARQLoperator">REPLACE</head>

	     <pre class="prototype"> <span class="return"><span class="type">string literal</span></span>  <span class="operator">REPLACE</span> (<span class="type"><span class="type">string literal</span></span> arg, <span class="type"><span class="type">simple literal</span></span> pattern, <span class="type"><span class="type">simple literal</span></span> replacement )
 <span class="return"><span class="type">string literal</span></span>  <span class="operator">REPLACE</span> (<span class="type"><span class="type">string literal</span></span> arg, <span class="type"><span class="type">simple literal</span></span> pattern, <span class="type"><span class="type">simple literal</span></span> replacement,  <span class="type"><span class="type">simple literal</span></span> flags)</pre>

	     <p>The <code>REPLACE</code> function corresponds to the XPath 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-replace">fn:replace</a> function.  
	    It replaces each non-overlapping occurrence of the regular expression <tt>pattern</tt> with the replacement string.
	    Regular expession matching may involve modifier flags. See <a href="#func-regex">REGEX</a>.
	     </p>

	     <div class="result">
	       <table class="resultTable">
		 <tbody>
		   <tr> <td>replace("abcd", "b", "Z")</td>  <td>"aZcd"</td> </tr>
		   <tr> <td>replace("abab", "B", "Z","i")</td>  <td>"aZaZ"</td> </tr>
		   <tr> <td>replace("abab", "B.", "Z","i")</td>  <td>"aZb"</td> </tr>
		 </tbody>
	       </table>
	     </div>
	     

	  </div4>


        </div3>

        <div3 id="func-numerics">
          <head>Functions on Numerics</head>

          <div4 id="func-abs">
            <head class="SPARQLoperator">abs</head>

	    <pre class="prototype"> <span class="return">numeric</span>  <span class="operator">ABS</span> (<span class="type"><span class="type numeric">numeric</span></span> <span class="name">term</span>)</pre>

	    <p>Returns the absolute value of <code>arg</code>.
	    An error is raised if <code>arg</code> is not a numeric value.</p>

	    <p>This function is the same as 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-abs">fn:numeric-abs</a>
	    for terms with a datatype from <a href="http://www.w3.org/TR/xpath-datamodel/">XDM</a>.
	    </p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>abs(1)</code></td>
		    <td><code>1</code></td>
		  </tr>
		  <tr>
		    <td><code>abs(-1.5)</code></td>
		    <td><code>1.5</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>  

          </div4>

          <div4 id="func-round">
            <head class="SPARQLoperator">round</head>
	    <pre class="prototype"> <span class="return">numeric</span>  <span class="operator">ROUND</span> (<span class="type"><span class="type numeric">numeric</span></span> <span class="name">term</span>)</pre>

	    <p>Returns the number with no fractional part that is closest to the argument. 
	    If there are two such numbers, then the one that is closest to 
	    positive infinity is returned. 
	    An error is raised if <code>arg</code> is not a numeric value.</p>

	    <p>This function is the same as 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-round">fn:numeric-round</a>
	    for terms with a datatype from <a href="http://www.w3.org/TR/xpath-datamodel/">XDM</a>.
	    </p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>round(2.4999)</code></td>
		    <td><code>2.0</code></td>
		  </tr>
		  <tr>
		    <td><code>round(2.5)</code></td>
		    <td><code>3.0</code></td>
		  </tr>
		  <tr>
		    <td><code>round(-2.5)</code></td>
		    <td><code>-2.0</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 
	  </div4>

          <div4 id="func-ceil">
            <head class="SPARQLoperator">ceil</head>
	    <pre class="prototype"> <span class="return">numeric</span>  <span class="operator">CEIL</span> (<span class="type"><span class="type numeric">numeric</span></span> <span class="name">term</span>)</pre>

	    <p>Returns the smallest (closest to negative infinity) number 
	    with no fractional part that is not less than the value of <code>arg</code>.
	    An error is raised if <code>arg</code> is not a numeric value.</p>

	    <p>This function is the same as 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-ceiling">fn:numeric-ceil</a>
	    for terms with a datatype from <a href="http://www.w3.org/TR/xpath-datamodel/">XDM</a>.
	    </p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>ceil(10.5)</code></td>
		    <td><code>11.0</code></td>
		  </tr>
		  <tr>
		    <td><code>ceil(-10.5)</code></td>
		    <td><code>-10.0</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 
	  </div4>

          <div4 id="func-floor">
            <head class="SPARQLoperator">floor</head>
	    <pre class="prototype"> <span class="return">numeric</span>  <span class="operator">FLOOR</span> (<span class="type"><span class="type numeric">numeric</span></span> <span class="name">term</span>)</pre>

	    <p>Returns the largest (closest to positive infinity) number
	    with no fractional part that is not greater than the value of <code>arg</code>.
	    An error is raised if <code>arg</code> is not a numeric value.</p>

	    <p>This function is the same as 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-floor">fn:numeric-floor</a>
	    for terms with a datatype from <a href="http://www.w3.org/TR/xpath-datamodel/">XDM</a>.
	    </p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>floor(10.5)</code></td>
		    <td><code>10.0</code></td>
		  </tr>
		  <tr>
		    <td><code>floor(-10.5)</code></td>
		    <td><code>-11.0</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 
	  </div4>

	  <div4>
	     <head>RAND</head>
	     <pre class="prototype"> <span class="return">xsd:double</span>  <span class="operator">RAND</span> ( )</pre>
	     <p>Returns a pseudo-random number between 0 (inclusive) and 1.0e0 (exclusive). 
	     Different numbers can be produced every time this function is invoked.
	     Numbers should be produced with approximately equal probability.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>rand()</code></td>
		    <td><code>"0.31221030831984886"^^xsd:double</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 
	  </div4>

        </div3>

        <div3 id="func-date-time">
          <head>Functions on Dates and Times</head>
          <div4 id="func-now">
            <head class="SPARQLoperator">now</head>
	    
	    <pre class="prototype"> <span class="return">xsd:dateTime</span>  <span class="operator">NOW</span> ()</pre>

	    <p>Returns an XSD dateTime value for the current query execution.
	    All calls to this function in any one query execution must return the same
	    value. The exact moment returned is not specified.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>now()</code></td>
		    <td><code>"2011-01-10T14:45:13.815-05:00"^^xsd:dateTime</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-year">
            <head class="SPARQLoperator">year</head>
	    <pre class="prototype"> <span class="return">xsd:integer</span>  <span class="operator">YEAR</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the year part of <code>arg</code> as an integer.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-year-from-dateTime"
	    >fn:year-from-dateTime</a>.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>year("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>2011</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-month">
            <head class="SPARQLoperator">month</head>
	    <pre class="prototype"> <span class="return">xsd:integer</span>  <span class="operator">MONTH</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the month part of <code>arg</code> as an integer.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-month-from-dateTime"
	    >fn:month-from-dateTime</a>.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>month("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>1</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-day">
            <head class="SPARQLoperator">day</head>
	    <pre class="prototype"> <span class="return">xsd:integer</span>  <span class="operator">DAY</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the day part of <code>arg</code> as an integer.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-day-from-dateTime"
	    >fn:day-from-dateTime</a>.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>day("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>10</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-hours">
            <head class="SPARQLoperator">hours</head>
	    <pre class="prototype"> <span class="return">xsd:integer</span>  <span class="operator">HOURS</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the hours part of <code>arg</code> as an integer.
	    The value is as given in the lexical form of the XSD dateTime.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-hours-from-dateTime"
	    >fn:hours-from-dateTime</a>.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>hours("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>14</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-minutes">
            <head class="SPARQLoperator">minutes</head>
	    <pre class="prototype"> <span class="return">xsd:integer</span>  <span class="operator">MINUTES</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the minutes part of the lexical form of <code>arg</code>.
	    The value is as given in the lexical form of the XSD dateTime.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-minutes-from-dateTime"
	    >fn:minutes-from-dateTime</a>.</p>

	     <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>minutes("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>45</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-seconds">
            <head class="SPARQLoperator">seconds</head>
	    <pre class="prototype"> <span class="return">xsd:decimal</span>  <span class="operator">SECONDS</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the seconds part of the lexical form of <code>arg</code>.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-seconds-from-dateTime"
	    >fn:seconds-from-dateTime</a>.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>seconds("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>13.815</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>


          </div4>

          <div4 id="func-timezone">
            <head class="SPARQLoperator">timezone</head>
	    <pre class="prototype"> <span class="return">xsd:dayTimeDuration</span>  <span class="operator">TIMEZONE</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the timezone part of <code>arg</code> as an xsd:dayTimeDuration.
	    Raises an error if there is no timezone.</p>

	    <p>This function corresponds to 
	    <a href="http://www.w3.org/TR/xpath-functions/#func-timezone-from-dateTime"
	    >fn:timezone-from-dateTime</a> except for the treatment of literals
	    with no timezone.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>timezone("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>"-PT5H"^^xsd:dayTimeDuration</code></td>
		  </tr>
		  <tr>
		    <td><code>timezone("2011-01-10T14:45:13.815Z"^^xsd:dateTime)</code></td>
		    <td><code>"PT0S"^^xsd:dayTimeDuration</code></td>
		  </tr>
		  <tr>
		    <td><code>timezone("2011-01-10T14:45:13.815"^^xsd:dateTime)</code></td>
		    <td>error</td>
		  </tr>
		</tbody>
	      </table>
	    </div>
          </div4>

          <div4 id="func-tz">
            <head class="SPARQLoperator">tz</head>
<pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">TZ</span> (<span class="type"><span class="type">xsd:dateTime</span></span> <span class="parm">arg</span>)</pre>

	    <p>Returns the timezone part of <code>arg</code> as a simple literal.
	    Returns the empty string if there is no timezone.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>tz("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)</code></td>
		    <td><code>"-05:00"</code></td>
		  </tr>
		  <tr>
		    <td><code>tz("2011-01-10T14:45:13.815Z"^^xsd:dateTime)</code></td>
		    <td><code>"Z"</code></td>
		  </tr>
		  <tr>
		    <td><code>tz("2011-01-10T14:45:13.815"^^xsd:dateTime)</code></td>
		    <td><code>""</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div>

          </div4>
        </div3>

        <div3 id="func-hash">
          <head>Hash Functions</head>

	  <div4 id="func-md5">
	    <head class="SPARQLoperator">MD5</head>
	    
	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">MD5</span> (<span class="type"><span class="type simple literal">simple literal</span></span> <span class="name">arg</span>)</pre>

	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">MD5</span> (<span class="type"><span class="type simple literal">xsd:string</span></span> <span class="name">arg</span>)</pre>

	    <p>Returns the MD5 checksum, as a hex digit string, calculated on the 
	    UTF-8 representation of the simple literal or lexical form of the 
	    <code>xsd:string</code>. Hex digits &SHOULD; be in lower case.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>MD5("abc")</code></td>
		    <td><code>"900150983cd24fb0d6963f7d28e17f72"</code></td>
		  </tr>
		  <tr>
		    <td><code>MD5("abc"^^xsd:string)</code></td>
		    <td><code>"900150983cd24fb0d6963f7d28e17f72"</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 	    
          </div4>

	  <div4 id="func-sha1">
	    <head class="SPARQLoperator">SHA1</head>

	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA1</span> (<span class="type"><span class="type simple literal">simple literal</span></span> <span class="name">arg</span>)</pre>

	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA1</span> (<span class="type"><span class="type simple literal">xsd:string</span></span> <span class="name">arg</span>)</pre>

	    <p>Returns the SHA1 checksum, as a hex digit string, calculated on the 
	    UTF-8 representation of the simple literal or lexical form of the 
	    <code>xsd:string</code>. Hex digits &SHOULD; be in lower case.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>SHA1("abc")</code></td>
		    <td><code>"a9993e364706816aba3e25717850c26c9cd0d89d"</code></td>
		  </tr>
		  <tr>
		    <td><code>SHA1("abc"^^xsd:string)</code></td>
		    <td><code>"a9993e364706816aba3e25717850c26c9cd0d89d"</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 	  
          </div4>       

          <div4 id="func-sha256">
            <head class="SPARQLoperator">SHA256</head>
	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA256</span> (<span class="type"><span class="type simple literal">simple literal</span></span> <span class="name">arg</span>)</pre>

	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA256</span> (<span class="type"><span class="type simple literal">xsd:string</span></span> <span class="name">arg</span>)</pre>

	    <p>Returns the SHA256 checksum, as a hex digit string, calculated on the 
	    UTF-8 representation of the simple literal or lexical form of the 
	    <code>xsd:string</code>. Hex digits &SHOULD; be in lower case.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>SHA256("abc")</code></td>
		    <td><code>"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"</code></td>
		  </tr>
		  <tr>
		    <td><code>SHA256("abc"^^xsd:string)</code></td>
		    <td><code>"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 	
          </div4>

          <div4 id="func-sha384">
            <head class="SPARQLoperator">SHA384</head>
	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA384</span> (<span class="type"><span class="type simple literal">simple literal</span></span> <span class="name">arg</span>)</pre>

	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA384</span> (<span class="type"><span class="type simple literal">xsd:string</span></span> <span class="name">arg</span>)</pre>

	    <p>Returns the SHA384 checksum, as a hex digit string, calculated on the 
	    UTF-8 representation of the simple literal or lexical form of the 
	    <code>xsd:string</code>. Hex digits &SHOULD; be in lower case.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>SHA384("abc")</code></td>
		    <td><code>"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"</code></td>
		  </tr>
		  <tr>
		    <td><code>SHA384("abc"^^xsd:string)</code></td>
		    <td><code>"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 	
          </div4>

          <div4 id="func-sha512">
            <head class="SPARQLoperator">SHA512</head>
	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA512</span> (<span class="type"><span class="type simple literal">simple literal</span></span> <span class="name">arg</span>)</pre>

	    <pre class="prototype"> <span class="return">simple literal</span>  <span class="operator">SHA512</span> (<span class="type"><span class="type simple literal">xsd:string</span></span> <span class="name">arg</span>)</pre>

	    <p>Returns the SHA512 checksum, as a hex digit string, calculated on the 
	    UTF-8 representation of the simple literal or lexical form of the 
	    <code>xsd:string</code>. Hex digits &SHOULD; be in lower case.</p>

	    <div class="result">
	      <table>
		<tbody>
		  <tr>
		    <td><code>SHA512("abc")</code></td>
		    <td><code>"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"</code></td>
		  </tr>
		  <tr>
		    <td><code>SHA512("abc"^^xsd:string)</code></td>
		    <td><code>"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"</code></td>
		  </tr>
		</tbody>
	      </table>
	    </div> 	
          </div4>
        </div3>
      </div2>

      <!-- F_DEFS -->

      <div2 id="FunctionMapping" class="FAndOTable">
        <head>XPath Constructor Functions</head>
    <p>SPARQL imports a subset of the XPath constructor functions defined in <a class="norm" href="http://www.w3.org/TR/xpath-functions/">XQuery 1.0 and XPath 2.0 Functions and Operators</a> [<a href="#FUNCOP">FUNCOP</a>] in section <a class="norm" href="http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive">17.1 Casting from primitive types to primitive types</a>. SPARQL constructors include all of the XPath constructors for the <a href="#operandDataTypes">SPARQL operand datatypes</a> plus the <a href="#operandDataTypes">additional datatypes</a> imposed by the RDF data model. Casting in SPARQL is performed by calling a constructor function for the target type on an operand of the source type.</p>

    <p>XPath defines only the casts from one XML Schema datatype to another. The remaining casts are defined as follows:</p>
    <ul>
      <li>Casting an <span class="IRI type">IRI</span> to an <code>xsd:string</code> produces a <span class="IRI typedLiteral">typed literal</span> with a lexical value of the codepoints comprising the IRI, and a datatype of <code>xsd:string</code>.</li>
      <li>Casting a <span class="simpleLiteral type">simple literal</span> to any XML Schema datatype is defined as the product of casting an <code>xsd:string</code> with the <a href="http://www.w3.org/TR/xpath20/#dt-string-value">string value</a> equal to the lexical value of the literal to the target datatype.</li>
    </ul>

    <p>The table below summarizes the casting operations that are always allowed (<span class="castY">Y</span>), never allowed (<span class="castN">N</span>) and dependent on the lexical value (<span class="castM">M</span>). For example, a casting operation from an <code>xsd:string</code> (the first row) to an <code>xsd:float</code> (the second column) is dependent on the lexical value (<span class="castM">M</span>).</p>

<blockquote>
<p>bool = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#boolean">xsd:boolean</a><br />
dbl = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#double">xsd:double</a><br />
flt = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#float">xsd:float</a><br />
dec = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#decimal">xsd:decimal</a><br />
int = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#integer">xsd:integer</a><br />
dT = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#dateTime">xsd:dateTime</a><br />
str = <a class="norm" href="http://www.w3.org/TR/xmlschema-2/#string">xsd:string</a><br />
<span class="rdfDM">IRI</span> = <span class="type IRI">IRI</span><br />
<span class="rdfDM">ltrl</span> = <code class="type simpleLiteral">simple literal</code></p>
</blockquote>

<table class="casting" summary="Casting table" border="1" cellpadding="1">
<col width="13%" span="1" />
<col width="11%" span="1" />
<col width="11%" span="1" />
<col width="11%" span="1" />
<col width="11%" span="1" />
<col width="11%" span="1" />
<col width="11%" span="1" />
<col width="11%" span="1" />
<!-- col width="3%" span="1" / -->
<!-- col width="3%" span="1" / -->
<!-- col width="3%" span="1" / -->
<thead>
<tr>
<th><span class="cancast" title="From\To">From \ To</span></th>
<th><span class="cancast" title="string">str</span></th>
<th><span class="cancast" title="float">flt</span></th>
<th><span class="cancast" title="double">dbl</span></th>
<th><span class="cancast" title="decimal">dec</span></th>
<th><span class="cancast" title="integer">int</span></th>
<th><span class="cancast" title="dateTime">dT</span></th>
<th><span class="cancast" title="boolean">bool</span></th>
<!-- th><span class="cancast rdfDM" title="IRI">IRI</span></th -->
<!-- th><span class="cancast rdfDM" title="Literal">ltrl</span></th -->
<!-- th><span class="cancast rdfDM" title="bNode">BN</span></th -->
</tr>
</thead>
<tbody>
<tr>
<th><span class="cancast" title="string">str</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast string to string? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast string to float? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast string to double? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast string to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast string to integer? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast string to dateTime? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast string to boolean? Maybe">M</span></td>
<!-- td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast string to IRI? Yes">Y</span></td -->
<!-- td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast string to Literal? Yes">Y</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast string to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast" title="float">flt</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast float to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast float to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast float to double? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast float to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast float to integer? Maybe">M</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast float to dateTime? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast float to boolean? Yes">Y</span></td>
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast float to IRI? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast float to Literal? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast float to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast" title="double">dbl</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast double to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast double to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast double to double? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast double to decimal? Maybe">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast" title="Cast double to integer? Maybe">M</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast double to dateTime? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast double to boolean? Yes">Y</span></td>
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast double to IRI? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast double to Literal? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast double to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast" title="decimal">dec</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast decimal to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast decimal to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast decimal to double? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast decimal to decimal? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast decimal to integer? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast decimal to dateTime? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast decimal to boolean? Yes">Y</span></td>
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast decimal to IRI? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast decimal to Literal? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast decimal to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast" title="integer">int</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast integer to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast integer to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast integer to double? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast integer to decimal? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast integer to integer? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast integer to dateTime? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast integer to boolean? Yes">Y</span></td>
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast integer to IRI? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast integer to Literal? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast integer to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast" title="dateTime">dT</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast dateTime to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast dateTime to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast dateTime to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast dateTime to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast dateTime to integer? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast dateTime to dateTime? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast dateTime to boolean? No">N</span></td>
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast dateTime to IRI? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast dateTime to Literal? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast dateTime to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast" title="boolean">bool</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast boolean to string? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast boolean to float? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast boolean to double? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast boolean to decimal? Yes">Y</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast boolean to integer? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast" title="Cast boolean to dateTime? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast" title="Cast boolean to boolean? Yes">Y</span></td>
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast boolean to IRI? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast boolean to Literal? No">N</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast boolean to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast rdfDM" title="IRI">IRI</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to boolean? No">N</span></td>
<!-- td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to IRI? Yes">Y</span></td -->
<!-- td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to Literal? Yes">Y</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast IRI to bNode? No">N</span></td -->
</tr>
<tr>
<th><span class="cancast rdfDM" title="Literal">ltrl</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to string? Yes">Y</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to float? No">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to double? No">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to decimal? No">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to integer? No">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to dateTime? No">M</span></td>
<td class="castM" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to boolean? No">M</span></td>
<!-- td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to IRI? Yes">Y</span></td -->
<!-- td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to Literal? Yes">Y</span></td -->
<!-- td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast Literal to bNode? No">N</span></td -->
</tr>
<!-- tr>
<th><span class="cancast rdfDM" title="bNode">BN</span></th>
<td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to string? Yes">Y</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to float? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to double? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to decimal? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to integer? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to dateTime? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to boolean? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to IRI? No">N</span></td>
<td class="castN" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to Literal? No">N</span></td>
<td class="castY" align="center" valign="middle"><span class="cancast rdfDM" title="Cast bNode to bNode? Yes">Y</span></td>
</tr -->
</tbody>
</table>

      </div2>
        <div2 id="extensionFunctions">
        <head>Extensible Value Testing</head>

    <p>It should be noted that any function or operator that is specified
to return an error under some conditions is a valid extension point.
That is, an implementation may return a non-error value in these
error cases, and still be conformant with this recommendation.</p>

    <p>A <a href="#rPrimaryExpression">PrimaryExpression</a> grammar rule can be a call to an extension function named by an IRI. An extension function takes some number of RDF terms as arguments and returns an RDF term. The semantics of these functions are identified by the IRI that identifies the function.</p>

    <p>SPARQL queries using extension functions are likely to have limited interoperability.</p>

  <p>As an example, consider a function called <code class="function">func:even</code>:</p>

  <pre class="prototype"> <code class="return">xsd:boolean</code>&nbsp;&nbsp;&nbsp;<code class="function">func:even</code> (<code class="type"><span class="type numeric">numeric</span></code> <code class="name">value</code>)
</pre>

  <div class="exampleGroup">
  <div class="queryGroup">
  <p>This function would be invoked in a FILTER as such:</p>

  <pre class="query">PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX func: &lt;http://example.org/functions#&gt;
SELECT ?name ?id
WHERE { ?x foaf:name  ?name ;
           func:empId   ?id .
        FILTER (func:even(?id)) }</pre></div></div>

    <p>For a second example, consider a function <code>aGeo:distance</code> that calculates the distance between two points, which is used here to find the places near Grenoble:</p>

  <pre class="prototype"> <code class="return">xsd:double</code>&nbsp;&nbsp;&nbsp;<code class="function">aGeo:distance</code> (<code class="type"><span class="type numeric">numeric</span></code> <code class="name">x1</code>, <code class="type"><span class="type numeric">numeric</span></code> <code class="name">y1</code>, <code class="type"><span class="type numeric">numeric</span></code> <code class="name">x2</code>, <code class="type"><span class="type numeric">numeric</span></code> <code class="name">y2</code>)
</pre>

  <div class="exampleGroup">
  <div class="queryGroup">
  <pre class="query">PREFIX aGeo: &lt;http://example.org/geo#&gt;

SELECT ?neighbor
WHERE { ?a aGeo:placeName &quot;Grenoble&quot; .
        ?a aGeo:locationX ?axLoc .
        ?a aGeo:locationY ?ayLoc .

        ?b aGeo:placeName ?neighbor .
        ?b aGeo:locationX ?bxLoc .
        ?b aGeo:locationY ?byLoc .

        FILTER ( aGeo:distance(?axLoc, ?ayLoc, ?bxLoc, ?byLoc) &lt; 10 ) .
      }
</pre></div></div>

  <p>An extension function might be used to test some
  application datatype not supported by the core SPARQL specification, it might
  be a transformation between datatype formats, for example into an XSD dateTime
  RDF term from another date format. </p>

      </div2>
    </div1>

    <div1 id="sparqlDefinition">
      <head>Definition of SPARQL</head>

      <p>This section defines the correct behavior for evaluation of graph patterns 
      and solution modifiers, given a query string and an RDF 
      dataset. It does not imply a SPARQL implementation must use the process defined 
      here. </p>

      <p>The outcome of executing a SPARQL query is defined by a series of steps, 
      starting from the SPARQL query as a string, turning that string into an
      abstract syntax form, then turning the abstract syntax into a SPARQL
      abstract query comprising operators from the SPARQL algebra. 
      This abstract query is then evaluated on an RDF dataset.</p>
      <div2 id="initDefinitions">
        <head>Initial Definitions</head>
        
        <div3 id="sparqlBasicTerms">
          <head>RDF Terms</head>

          <p>SPARQL is defined in terms of IRIs [<a href="#rfc3987">RFC3987</a>].
          IRIs are a subset of RDF URI References that omits the use of spaces.</p>

          <div class="defn">
            <b>Definition: <a id="defn_RDFTerm" name="defn_RDFTerm">RDF Term</a></b>

            <p>Let I be the set of all IRIs.<br />
            Let RDF-L be the set of all <a class="norm" href=
            "http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-literal">RDF Literals</a><br />
            Let RDF-B be the set of all <a class="norm" href=
            "http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-blank-node">blank nodes</a> in RDF graphs</p>
            <p>The set of <span class="definedTerm">RDF Terms</span>, RDF-T, is I &cup; RDF-L &cup; RDF-B.</p>
          </div>

          <p>This definition of <span class="definedTerm">RDF Term</span> collects together 
          several basic notions from the 
          <a class="norm" href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#section-data-model">RDF data model</a>,
          but <a href="http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref">updated</a> to refer to IRIs
          rather than RDF URI references.</p>
        </div3>

	

        <div3 id="simple_literal">
	  <head>Simple Literal</head>
	  <div class="defn">
            <p><b>Definition: <a id="defn_SimpleLiteral" name="defn_SimpleLiteral">Simple Literal</a></b></p>
	    <p>The set of <b>Simple Literals</b> is the set of all <a class="norm"
	    href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-literal"
	    >RDF Literals</a> with no language tag or datatype IRI.</p>
	  </div>
	</div3>
        
	<div3 id="sparqlDataset">
          <head>RDF Dataset</head>
          <div class="defn">
            <b>Definition: <a id="defn_RDFDataset" name="defn_RDFDataset">RDF Dataset</a></b><p>
            An RDF dataset is a set:<br />
            { G, (&lt;u<sub>1</sub>&gt;, G<sub>1</sub>), (&lt;u<sub>2</sub>&gt;, G<sub>2</sub>), . . .
            (&lt;u<sub>n</sub>&gt;, G<sub>n</sub>) }<br />
            where G and each G<sub>i</sub> are graphs, and each &lt;u<sub>i</sub>&gt; is
            an IRI.
            Each &lt;u<sub>i</sub>&gt; is distinct.</p>
            <p>G is called the default graph. (&lt;u<sub>i</sub>&gt;, G<sub>i</sub>) are called
            named graphs.</p>
          </div>

          <div class="defn">
            <b>Definition: <a id="defn_ActiveGraph" name="defn_ActiveGraph">Active Graph</a></b>
            <p>The <b>active graph</b> is the graph from the dataset used for basic 
            graph pattern matching.</p>
          </div>

	   <div class="defn">
	     <p><b><a  id="defn_RDFDatasetMerge" name="defn_RDFDatasetMerge">Definition: RDF Dataset Merge</a></b></p>

	     <p>Let DS1 = 
	     { G1, (&lt;u1<sub>1</sub>&gt;, G1<sub>1</sub>), (&lt;u1<sub>2</sub>&gt;, G1<sub>2</sub>), . . .
	     (&lt;u1<sub>n</sub>&gt;, G1<sub>n</sub>) },<br/>
	     and DS2 = 
	     { G2, (&lt;u2<sub>1</sub>&gt;, G2<sub>1</sub>), (&lt;u2<sub>2</sub>&gt;, G2<sub>2</sub>), . . .
	     (&lt;u2<sub>m</sub>&gt;, G2<sub>m</sub>) }</p>
	     <p>
	     then we define the RDF Dataset Merge of DS1 and DS2 to be:<br/>
	     DS={ G, (&lt;u<sub>1</sub>&gt;, G<sub>1</sub>), (&lt;u<sub>2</sub>&gt;, G<sub>2</sub>), . . .
	     (&lt;u<sub>k</sub>&gt;, G<sub>k</sub>) }<br/>
	     where:</p>
	     <p>Write N1 for { &lt;u1<sub>j</sub>&gt; j = 1 to n }<br/>
	     Write N2 for { &lt;u2<sub>j</sub>&gt; j = 1 to m }<br/>
	     </p>
	     <ul>
	       <li>G is the <a href="http://www.w3.org/TR/rdf-mt/#defmerge">merge</a> of G1 and G2</li>
	       <li>(&lt;u<sub>i</sub>&gt;, G<sub>i</sub>) where &lt;u<sub>i</sub>&gt; is in N1 but not in N2</li>
	       <li>(&lt;u<sub>i</sub>&gt;, G<sub>i</sub>) where &lt;u<sub>i</sub>&gt; is in N2 but not in N1 </li>
	       <li>(&lt;u<sub>i</sub>&gt;, G<sub>i</sub>) where &lt;u<sub>i</sub>&gt; is equal to &lt;u<sub>j</sub>&gt; in N1 and equal to &lt;u<sub>k</sub>&gt; in N2 and G<sub>i</sub> is the <a href="http://www.w3.org/TR/rdf-mt/#defmerge">merge</a> of G1<sub>j</sub> and G2<sub>k</sub></li>
	     </ul>
	  </div>

        </div3>
        <div3 id="sparqlQueryVariables">
          <head>Query Variables</head>
          
          <div class="defn">
            <b>Definition: <a id="defn_QueryVariable" name="defn_QueryVariable">Query Variable</a></b>
            <p>A <span class="definedTerm">query variable</span> is a member of the set V 
            where V is infinite and disjoint from RDF-T.</p>
          </div>

        </div3>
        <div3 id="sparqlTriplePatterns">
          <head>Triple Patterns</head>

          <div class="defn">
            <b>Definition: <a id="defn_TriplePattern" name="defn_TriplePattern">Triple Pattern</a></b>
            
            <p>A <span class="definedTerm">triple pattern</span> is member of the set:<br />
            (RDF-T &cup; V) x (I &cup; V) x (RDF-T &cup; V)</p>
          </div>
          
          <p>This definition of Triple Pattern includes literal subjects. <a href=
          "http://www.w3.org/2000/03/rdf-tracking/#rdfms-literalsubjects">This has been noted by RDF-core</a>.</p>

	  <pre>"[The RDF core Working Group] noted that it is aware of no reason why literals should
not be subjects and a future WG with a less restrictive charter may
extend the syntaxes to allow literals as the subjects of statements."</pre>
          
          <p>Because RDF graphs may not contain literal subjects, any SPARQL triple pattern with a literal as subject will fail
          to match on any RDF graph.</p>
          
        </div3>
        <div3 id="sparqlBasicGraphPatterns">
          <head>Basic Graph Patterns</head>
          
          <div class="defn">
            <b>Definition: <a id="defn_BasicGraphPattern" name="defn_BasicGraphPattern">Basic Graph Pattern</a></b>

            <p>A <span class="definedTerm">Basic Graph Pattern</span> is a
            set of <a href="#defn_TriplePattern">Triple Patterns</a>.</p>
          </div>

          <p>The empty graph pattern is a basic graph pattern which is the empty set.</p>
        </div3>

        <div3 id="sparqlPropertyPaths">
          <head>Property Path Patterns</head>

          <div class="defn">
            <b>Definition: <a id="defn_PropertyPath" name="defn_PropertyPath">Property Path</a></b>
            <p>A Property Path is a sequence of triples, t<sub>i</sub> in sequence ST, with n = length(ST)-1, such that, for i=0 to n, 
            the object of t<sub>i</sub> is the same term as the subject of t<sub>i+1</sub>.</p>
            <p>We call the subject of t<sub>0</sub> the start of the path.</p>
            <p>We call the object of t<sub>n</sub> the end of the path.</p>
            <p>A Property Path is a path in graph G if each t<sub>i</sub> is a triple of G.</p>
          </div>

          <p>A property path does not span multiple graphs in a dataset.</p>

          <div class="defn">
            <b>Definition: <a id="defn_PropertyPathExpr" name="defn_PropertyPathExpr">Property Path Expression</a></b>
            <p>A property path expression is an expression using the property path forms <a href="">described above</a>.</p>
          </div>

          <div class="defn">
            <b>Definition: <a id="defn_PropertyPathPattern" name="defn_PropertyPathPattern">Property Path Pattern</a></b>
            <p>Let PP be the set of all property path expressions. 
            A property path pattern is a member of the set:<br/>
            (RDF-T &cup; V) x PP x (RDF-T &cup; V)</p>
          </div>

          <p>A Property Path Pattern is a generalization of a 
          <a href="#defn_TriplePattern">Triple Pattern</a> 
          to include a property path expression 
          in the property position.</p>
        </div3>

        <div3 id="sparqlSolutions">
          <head>Solution Mapping</head>

          <p>A solution mapping is a mapping from a set of variables to a set of RDF terms. 
          We use the term 'solution' where it is clear.</p>

          <div class="defn">
            <b>Definition: <a id="defn_sparqlSolutionMapping" name="defn_sparqlSolutionMapping">Solution Mapping</a></b>

            <p>A <b>solution mapping</b>, &mu;, is a partial function &mu; : V -&gt; RDF-T.</p>

            <p>The domain of &mu;, dom(&mu;), is the subset of V where &mu; is defined.</p>
          </div>
          <div class="defn">
            <b>Definition: <a id="defn_sparqlSolutionSequence" name="defn_sparqlSolutionSequence">Solution Sequence</a></b>
            
            <p>A <b>solution sequence</b> is a list of solutions, possibly unordered.</p>
          </div>

	  <p>Write expr(&mu;) for the value of the expression expr, 
	  using the terms for variables given by &mu;. 
	  Evaluation may result in an error.</p>

        </div3>
        <div3 id="sparqlSolMod">
          <head>Solution Sequence Modifiers</head>

          <div class="defn">
            <b>Definition: <a id="defn_SolutionModifier" name="defn_SolutionModifier">Solution Sequence Modifier</a></b>

            <p>A <span class="definedTerm">solution sequence modifier</span> is one of:</p>
            <ul>
              <li>
                <a href="#defn_algOrdered">
              Order By</a> modifier: put the solutions in order</li>
              <li>
                <a href="#defn_algProjection">
              Projection</a> modifier: choose certain variables</li>
              <li>
                <a href="#defn_algDistinct">
              Distinct</a> modifier: ensure solutions in the sequence are unique</li>
              <li>
                <a href="#defn_algReduced">
              Reduced</a> modifier: permit any non-distinct solutions to be eliminated</li>
              <li>
                <a href="#defn_algSlice">
                  Offset</a> modifier: control where the solutions start from in 
              the overall sequence of solutions</li>
              <li>
                <a href="#defn_algSlice">
              Limit</a> modifier: restrict the number of solutions</li>
            </ul>
          </div>
        </div3>

        <div3>
          <head>SPARQL Query</head>
          <div class="defn">
            <b>Definition: <a id="defn_SPARQLQuery" name="defn_SPARQLQuery">SPARQL Query</a></b>
            <p>A <span class="definedTerm">SPARQL Abstract Query</span> is a tuple (E, DS, QF) where:</p>
            <ul>
              <li>E is a <a href="#sparqlAlgebra">SPARQL algebra</a> expression</li>
              <li>DS is an <a href="#defn_RDFDataset">RDF Dataset</a></li>
              <li>QF is a <a href="#QueryForms">query form</a></li>
            </ul>
          </div>

          <div class="defn" >
            <b>Definition: <a id="defn_QueryUnit" name="defn_QueryUnit">Query Level</a></b>
            <p>A query level is a graph pattern, a set of group and aggregation, and a set of solution modifiers.</p>
          </div>
	  <p>A query is a tree of "query levels", where each <a href="#subqueries">subquery</a>
	  forms one query level in the tree.</p>
        </div3>
      </div2>
      
      <div2 id="sparqlQuery">
        <head>Translation to the SPARQL Algebra</head>
        <p>This section defines the process of converting graph patterns and solution 
        modifiers in a SPARQL query string into a SPARQL algebra expression.  The process described
        converts one level of query nesting, as formed by subqueries using the nested
        <tt>SELECT</tt> syntax and is applied recursively on subqueries. Each level consists of graph
        pattern matching and filtering, followed by the application of solution modifiers.</p>

        <p>The SPARQL query string is parsed and the abbreviations for IRIs and triple patterns given in 
        <a href="#sparqlSyntax">section 4</a> are applied.
        At this point the abstract syntax tree is composed of:</p>

        <table class="plain">
          <tbody>
            <tr>
              <th>Patterns</th>
              <th>Modifiers</th>
              <th>Query Forms</th>
              <th>Other</th>
            </tr>
            <tr>
              <td>RDF terms</td>
              <td>DISTINCT</td>
              <td>SELECT</td>
	      <td>VALUES</td>
            </tr>
            <tr>
              <td>Property path expression</td>
              <td>REDUCED</td>
              <td>CONSTRUCT</td>
	      <td>SERVICE</td>
            </tr>
            <tr>
              <td>Property path patterns</td>
              <td>Projection</td>
              <td>DESCRIBE</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>Groups</td>
              <td>ORDER BY</td>
              <td>ASK</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>OPTIONAL</td>
              <td>LIMIT</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>UNION</td>
              <td>OFFSET</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>GRAPH</td>
              <td>Select expressions</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>BIND</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>GROUP BY</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>HAVING</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
            <tr>
              <td>MINUS</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>

            <tr>
              <td>FILTER</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
          </tbody>
        </table>

        <p>The result of converting such an abstract syntax tree is a SPARQL query that 
        uses the following symbols in the SPARQL algebra:</p>

        <table class="plain">
          <tbody>
            <tr>
              <th>Graph Pattern</th>
              <th>Solution Modifiers</th>
              <th>Property Path</th>
            </tr>
            <tr>
              <td>BGP </td>
              <td>ToList</td>
	      <td>PredicatePath</td>
            </tr>
            <tr>
              <td>Join</td>
              <td>OrderBy</td>
	      <td>InversePath</td>
            </tr>
            <tr>
              <td>LeftJoin</td>
              <td>Project</td>
	      <td>SequencePath</td>
            </tr>
            <tr>
              <td>Filter</td>
              <td>Distinct</td>
	      <td>AlernativePath</td>
            </tr>
            <tr>
              <td>Union</td>
              <td>Reduced</td>
	      <td>ZeroOrMorePath</td>
            </tr>
            <tr>
              <td>Graph</td>
              <td>Slice</td>
	      <td>OneOrMorePath</td>
            </tr>
            <tr>
              <td>Extend</td>
              <td>ToMultiSet</td>
	      <td>ZeroOrOnePath</td>
            </tr>

            <tr>
              <td>Minus</td>
              <td>&nbsp;</td>
	      <td>NegatedPropertySet</td>
            </tr>

            <tr>
              <td>Group</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>

            <tr>
              <td>Aggregation</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>

            <tr>
              <td>AggregateJoin</td>
              <td>&nbsp;</td>
	      <td>&nbsp;</td>
            </tr>
          </tbody>
        </table>

        <p><i>Slice</i> is the combination of OFFSET and LIMIT.</p>
        <p><i>ToList</i> is used where conversion from the results of graph pattern 
        matching to sequences occurs.</p>
        <p><i>ToMultiSet</i> is used where conversion from a solution sequence
        to a multiset occurs.</p>

        <div3 id="variableScope">
          <head>Variable Scope</head>

          <p>We define a variable to be <i>in-scope</i> if there is a way for
          a variable to be in the domain of a solution mapping at that point
          in the execution of the SPARQL algebra for the query.
          The definition below provides a way of determing this from the
          abstract syntax of a query.</p>

          <p>Note that a subquery with a projection can hide variables; 
          use of a variable in <code>FILTER</code>, or in <code>MINUS</code> does not cause a variable
          to be in-scope outside of those forms.</p>

          <p>Let <b>P</b>, <b>P1</b>, <b>P2</b> be graph patterns and <b>E</b>, <b>E1</b>,...<b>En</b> be expressions. 
          A variable <code>v</code> is in-scope if:</p>

          <table  style="border-collapse: collapse; border-color: #000000" border="1" cellpadding="5">
            <tbody>
              <tr>
                <th>Syntax Form</th>
                <th>In-scope variables</th>
              </tr>
              <tr>
                <td>Basic Graph Pattern (BGP)</td>
                <td><code>v</code> occurs in the BGP</td>
              </tr>
              <tr>
                <td>Path </td>
                <td><code>v</code> occurs in the path</td>
              </tr>
              <tr>
                <td>Group <code>{ P1 P2 ... }</code></td>
                <td><code>v</code> is in-scope if it is in-scope in one or more of P1, P2, ...</td>
              </tr>
              <tr>
                <td><code>GRAPH term { P }</code></td>
                <td><code>v</code> is <code>term</code> or <code>v</code> is in-scope in P</td>
              </tr>
              <tr>
                <td><code>{ P1 } UNION { P2 }</code></td>
                <td><code>v</code> is in-scope in P1 or in-scope in P2</td>
              </tr>
              <tr>
                <td><code>OPTIONAL {P}</code></td>
                <td><code>v</code> is in-scope in P</td>
              </tr>
              <tr>
                <td><code>SERVICE term {P}</code></td>
                <td><code>v</code> is <code>term</code> or <code>v</code> is in-scope in P</td>
              </tr>

              <tr>
                <td><code>BIND (expr AS v)</code></td>
                <td><code>v</code> is in-scope</td>
              </tr>
              <tr>
                <td><code>SELECT .. v .. { P }</code></td>
                <td><code>v</code> is in-scope</td>
              </tr>
              <tr>
                <td><code>SELECT ... (expr AS v)</code></td>
                <td><code>v</code> is in-scope</td>
              </tr>
              <tr>
                <td><code>GROUP BY (expr AS v)</code></td>
                <td><code>v</code> is in-scope</td>
              </tr>
              <tr>
                <td><code>SELECT * { P }</code></td>
                <td><code>v</code> is in-scope in <code>P</code></td>
              </tr>
              <tr>
                <td><code>VALUES v { values }</code></td>
                <td><code>v</code> is in-scope</td>
              </tr>
              <tr>
                <td><code>VALUES varlist { values }</code></td>
                <td><code>v</code> is in-scope if <code>v</code> is in <code>varlist</code></td>
              </tr>
            </tbody>
          </table>
          <p>The variable <tt>v</tt> must not be in-scope at the point of the <code>(expr AS v)</code>
	  form.  The scoping for <code>(expr AS v)</code> applies immediately in
          <code>SELECT</code> expressions.</p>

	  <p>In <code>BIND (expr AS v)</code> requires that the variable <code>v</code> is
	  not in-scope from the preceeding elements in the group graph pattern in which it is used.</p>

	  <p>In <code>SELECT</code>, the variable <code>v</code> must not be in-scope
	  in the graph pattern of the <code>SELECT</code> clause, nor used in another
	  select expression earlier in the clause.</p>

        </div3>
        
	<div3 id="convertGraphPattern">
          <head>Converting Graph Patterns</head>
          <p>This section describes the process for translating a SPARQL graph 
          pattern into a SPARQL algebra expression. This process is applied to
	  the group graph pattern  (the unit between <code>{...}</code> delimiters) 
	  forming the <code>WHERE</code> clause of a query, and recursively
	  to each syntactic element within the group graph pattern.  The result of
	  the translation is a SPARQL algebra expression.
	  </p>

	  <p>In summary, the steps are applied as follows:</p>
	  <ul>
	    <li>
	      <a href="#sparqlExpandForms">Expand syntax forms</a> 
	      for IRIs, literals and triple patterns.
	    </li>
	    <li><a href="#sparqlTranslatePathExpressions">Translate property path expressions</a></li>
	    <li><a href="#sparqlTranslatePathPatterns">Convert some property path patterns to triples</a></li>
	    <li><a href="#sparqlCollectFilters">Collect the <code>FILTER</code>s in the group</a></li>
	    <li><a href="#sparqlTranslateBasicGraphPatterns">Translate Basic Graph Patterns</a></li>
	    <li><a href="#sparqlTranslateGraphPatterns">Translate the remaining graph patterns in the group</a></li>
	    <li><a href="#sparqlAddFilters">Add in Filters</a></li>
	    <li><a href="#sparqlSimplification">Simplify the algebra expression</a></li>
	  </ul>

	  <p>We write</p>
	  <blockquote>
	    translate(graph pattern)
	  </blockquote>
	  <p>for the algorthm described here to translate graph patterns.
	  </p>

          <div class="wgNote">
            The working group notes that in SPARQL 1.0, the point at which the simplification step is 
	    applied leads to ambiguous transformation 
            of queries involving a doubly nested filter and pattern in an optional:
	    <pre><code>OPTIONAL { { ... FILTER ( ... ?x ... ) } }.</code>.</pre>
            <p>This is illustrated by two non-normative test cases:</p>
            <ul>
              <li><a href="http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-005-not-simplified">
              Simplification applied after all transformations</a> or not at all.</li>

              <li><a href="http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-005-simplified">
              Simplification applied during transformation</a>.</li>
            </ul>
          </div>

	  <p>Applying the simpification step after all the translation of graph patterns
	  is the preferred reading.</p>

          <div4 id="sparqlExpandForms">
            <head>Expand Syntax Forms </head>

            <p>Expand abbreviations for IRIs and triple patterns given in 
            <a href="#sparqlSyntax">section 4</a>.</p>
          
          </div4>

          <div4 id="sparqlCollectFilters">
	    <head>Collect <code>FILTER</code> Elements</head>
	    <p>
	      <code>FILTER</code> expressions apply to the whole group graph pattern 
	      in which they appear.  The algebra operators to perform filtering are
	      added to the group after translation of each group element. We collect
	      the filters together here and remove them from group, then
	      <a href="#sparqlAddFilters">apply
	      them to the whole translated group graph pattern</a>.
	    </p>
	    <p>In this step, we also translate graph patterns within <code>FILTER</code>
	    expressions <a href="#func-filter-exists"><code>EXISTS</code> and
	    <code>NOT EXISTS</code></a>.
	    </p>

	    <pre class="codeBlock">Let FS := empty set

For each form FILTER(expr) in the group graph pattern:
    In expr, replace NOT EXISTS{P} with fn:not(<a href="#defn_evalExists">exists(translate(P)))</a> 
    In expr, replace EXISTS{P} with <a href="#defn_evalExists">exists(translate(P))</a>
    FS := FS ∪ {expr}
    End</pre>

          <p>The set of filter expressions <code>FS</code> is <a href="#sparqlAddFilters">used later</a>.</p>

	  </div4>

          <div4 id="sparqlTranslatePathExpressions">
            <head>Translate Property Path Expressions</head>
            
            <p>The following table gives the translation of property paths
	    expressions from SPARQL syntax to terms in the SPARQL algebra.
	    This applies to all elements of a property path expression recursively.</p>

	    <p>The <a href="#sparqlTranslatePathPatterns">next step after this one</a>
	    translates certain forms to triple patterns,
	    and these are converted later to basic graph patterns by adjacency
	    (without intervening group pattern delimiters <tt>{</tt> and <tt>})</tt> 
	    or other syntax forms. Overall, SPARQL syntax property paths of just
	    an IRI become triple patterns and these are aggregated into basic graph patterns.</p>
            
            <p>Notes:</p>
            <ul>
              <li>The order of forms IRI and ^IRI in negated property sets is not relevant.</li>
            </ul>

            <p>We introduce the following symbols:</p>
            <ul>
	      <li>link</li>
	      <li>inv</li>
	      <li>alt</li>
	      <li>seq</li>
              <li>ZeroOrMorePath</li>
              <li>OneOrMorePath</li>
              <li>ZeroOrOnePath</li>
              <li>NPS (for NegatedPropertySet)</li>
            </ul>

            <table style="border-collapse: collapse; border-color: #000000" border="1" cellpadding="5">
              <tbody>
                <tr>
                  <th>Syntax Form (path)</th>
		  <th>Algebra (path)</th>
                </tr>
                <tr>
                  <td><code>iri</code></td>
		  <td><code>link(iri)</code></td>
                </tr>

                <tr>
                  <td><code>^path</code></td>
                  <td><code>inv(path)</code></td>
                </tr>

                <tr>
                  <td><code>!(:iri<sub>1</sub>|...|:iri<sub>n</sub>)</code></td>
                  <td><code>NPS({:iri<sub>1</sub> ... :iri<sub>n</sub>})</code></td>
                </tr>
                <tr>
                  <td><code>!(^:iri<sub>1</sub>|...|^:iri<sub>n</sub>)</code></td>
                  <td><code>inv(NPS({:iri<sub>1</sub> ... :iri<sub>n</sub>}))</code></td>
                </tr>

                <tr>
                  <td><code>!(:iri<sub>1</sub>|...|:iri<sub>i</sub>|^:iri<sub>i+1</sub>|...|^:iri<sub>m</sub>)</code>&nbsp;</td>
		  <td><code>alt(NPS({:iri<sub>1</sub> ...:iri<sub>i</sub>}),<br/>
		            &nbsp;&nbsp;&nbsp;&nbsp;inv(NPS({:iri<sub>i+1</sub>, ..., :iri<sub>m</sub>})) )</code>
		  </td>
                </tr>
                <tr>
                  <td><code>path1 / path2</code></td>
                  <td><code>seq(path1, path2)</code></td>
                </tr>
                <tr>
                  <td><code>path1 | path2</code></td>
                  <td><code>alt(path1, path2)</code> </td>
                </tr>
                <tr>
                  <td><code>path*</code></td>
                  <td><code>ZeroOrMorePath(path)</code></td>
                </tr>
                <tr>
                  <td><code>path+</code></td>
                  <td><code>OneOrMorePath(path)</code></td>
                </tr>
                <tr>
                  <td><code>path?</code></td>
                  <td><code>ZeroOrOnePath(path)</code></td>
                </tr>
              </tbody>
            </table>
	  </div4>

	  <div4 id="sparqlTranslatePathPatterns">
	    <head>Translate Property Path Patterns</head>
	    <p>
	      The previous step translated <a href="#defn_PropertyPathExpr">property path expressions</a>.
	      This step translates <a href="#defn_PropertyPathPattern">property path patterns</a>,
	      which are a subject end point, property path expression and object end point,
	      into triple patterns or wraps in a general algebra operation for path evaluation.
	    </p>

	    <p>Notes:</p>
	    <ul>
	      <li>X and Y are RDF terms or variables.</li>
	      <li>?V is a fresh variable.</li>
	      <li>P and Q are path expressions.</li>
	      <li>These are only applied to property path patterns, not within property path expressions.</li>
	      <li>Translations earlier in the table are applied in preference to the last translation.</li>
	      <li>
		The final translation simply wraps any remaining property path expression to
		use a common form <code>Path(...)</code>.
	      </li>
	    </ul>
	    
	    <table style="border-collapse: collapse; border-color: #000000" border="1" cellpadding="5">
	      <tbody>
		<tr>
                  <th>Algebra (path)</th>
		  <th>Translation</th>
                </tr>
                <tr>
                  <td><code>X link(iri) Y</code></td>
                  <td><code>X iri Y</code></td>
		</tr>
                <tr>
                  <td><code>X inv(iri) Y</code></td>
                  <td><code>Y iri X</code></td>
		</tr>
		<tr>
		  <td><code>X seq(P, Q) Y</code></td>
		  <td><code>X P ?V . ?V Q P</code></td>
		</tr>
		<tr>
		  <td><code>X P Y</code></td>
		  <td><code>Path(X, P, Y)</code></td>
		</tr>
	      </tbody>
	    </table>

	    <p>Examples of the whole path translation process 
	    (<code>?_V</code> is a fresh variable):</p>

	    <div class="algExample">
	      <div class="algExample1">
		?s :p/:q ?o
	      </div>
	      <div class="algExample2">
		 ?s :p ?_V . <br/>
                 ?_V :q ?o
	      </div>
	    </div>

	    <div class="algExample">
	      <div class="algExample1">
		?s :p* ?o
	      </div>
	      <div class="algExample2">
		Path(?s, ZeroOrMorePath(link(:p)), ?o)
	      </div>
	    </div>

	    <div class="algExample">
	      <div class="algExample1">
		:list rdf:rest*/rdf:first ?member
	      </div>
	      <div class="algExample2">
		Path(:list, ZeroOrMorePath(link(rdf:rest)), ?_V) .<br/>
		?_V rdf:first ?member
	      </div>
	    </div>

	    <!--
	    <p>Other translations are possible. (omit)</p>
	    <table style="border-collapse: collapse; border-color: #000000" border="1" cellpadding="5">
	      <tbody>
		<tr>
		  <th>Algebra (path)</th>
		  <th>Translation</th>
                </tr>
		<tr>
		  <td><code>X alt(P, Q) Y</code></td>
		  <td><code>{ X P Y } UNION { X Q Y }</code></td>
		</tr>
	      </tbody>
	    </table>	
	    -->
          </div4>
        
          <div4 id="sparqlTranslateBasicGraphPatterns">
            <head>Translate Basic Graph Patterns</head>
	    <p>After translating property paths, any adjacent triple patterns are collected together
	    to form a basic graph pattern <code>BGP(triples)</code>.</p>

          </div4>

          <div4 id="sparqlTranslateGraphPatterns">
            <head>Translate Graph Patterns</head>
	    <p>Next, we translate each remaining graph pattern form, recursively applying the translation process.</p>

            <blockquote>
              <p>If the form is <code class="gRuleBody">
              <a href="#rGroupOrUnionGraphPattern">GroupOrUnionGraphPattern</a></code></p>
            </blockquote>

            <pre class="codeBlock">Let A := undefined
          
For each element G in the GroupOrUnionGraphPattern
    If A is undefined
        A := Translate(G)
    Else
        A := Union(A, Translate(G))
    End

The result is A
            </pre>

            <blockquote>
              <p>If the form is <code class="gRuleBody"><a href="#rGraphGraphPattern">GraphGraphPattern</a></code></p>
            </blockquote>

            <pre class="codeBlock">If the form is GRAPH IRI GroupGraphPattern
    The result is Graph(IRI, Translate(GroupGraphPattern))</pre>
           <pre class="codeBlock">If the form is GRAPH Var GroupGraphPattern
    The result is Graph(Var, Translate(GroupGraphPattern))</pre>

            <blockquote>
	      <p>If the form is <code class="gRuleBody"><a href="#rGroupGraphPattern">GroupGraphPattern</a></code>:</p>
    </blockquote>

            <pre class="codeBlock">Let FS := the empty set
Let G := the empty pattern, a basic graph pattern which is the empty set.

For each element E in the GroupGraphPattern

    If E is of the form OPTIONAL{P} 
        Let A := Translate(P)
        If A is of the form Filter(F, A2)
            G := LeftJoin(G, A2, F)
        Else 
            G := LeftJoin(G, A, true)
            End
        End

    If E is of the form MINUS{P}
        G := Minus(G, Translate(P))
        End

    If E is of the form BIND(expr AS var)
        G := Extend(G, var, expr)
        End

    If E is any other form 
        Let A := Translate(E)
        G := Join(G, A)
        End

   End
   
The result is G.
            </pre>

	    <blockquote>
	      <p>If the form is <a href="#rInlineData">InlineData</a></p>
	    </blockquote>

	    <pre class="codeBlock">The result is a multiset of solution mappings 'data'.</pre>

	    <div id="data-block">
	      <blockquote>

		<i>data</i> is formed by forming a solution mapping 
		from the variable in the corresponding position in list of variables 
		(or single variable), 
		omitting a binding if the <code>BindingValue</code> is the word <code>UNDEF</code>.
	      </blockquote>

	    </div>
	    <blockquote>
	      <p>If the form is <a href="#rSubSelect">SubSelect</a></p>
	    </blockquote>
	    <pre class="codeBlock">The result is ToMultiset(Translate(SubSelect))</pre>


          </div4>

	  <div4 id="sparqlAddFilters">
	    <head>Filters of Group</head>
	    <p>After the group has been translated, the filter expressions are
	    added so they wil apply to the whole of the rest of the group:</p>
	    <pre class="codeBlock">If FS is not empty
    Let G := output of preceding step
    Let X := Conjunction of expressions in FS
    G := Filter(X, G)
    End</pre>

	  </div4>


          <div4 id="sparqlSimplification">
            <head>Simplification step</head>
            <p>Some groups of one graph pattern become <code>join(Z, A)</code>, 
	    where Z is the empty basic graph pattern 
	    (which is the empty set).  These can be replaced by A. 
	    The empty graph pattern Z is the identity for join:</p>
            <pre class="codeBlock">Replace join(Z, A) by A
Replace join(A, Z) by A</pre>
          </div4>
        </div3>
        
        <div3 id="sparqlAlgebraExamples">
          <head>Examples of Mapped Graph Patterns</head>

          <p>The second form of a rewrite example is the first with empty group joins removed by 
          the simplification step.</p>
          <p>Example: group with a basic graph pattern consisting of a single triple 
          pattern:</p>

          <div class="algExample">
            <div class="algExample1">
              { ?s ?p ?o }
            </div>

            <div class="algExample2">
              Join(Z,
            BGP(?s ?p ?o) )</div>
            <div class="algExample2">
            BGP(?s ?p ?o)</div>
          </div>

          <p>Example: group with a basic graph pattern consisting of two triple patterns:</p>

          <div class="algExample">
            <div class="algExample1">
              { ?s :p1 ?v1 ; :p2 ?v2 }
            </div>

            <div class="algExample2">
              BGP( ?s :p1 ?v1 . ?s :p2 ?v2 )
            </div>
          </div>

          <p>Example: group consisting of a union of two basic graph patterns:</p>

          <div class="algExample">
            <div class="algExample1">
              { { ?s :p1 ?v1 } UNION {?s :p2 ?v2 } }
            </div>

            <div class="algExample2">
              Union(Join(Z, BGP(?s :p1 ?v1)),<br/>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p2 ?v2)) )
            </div>

            <div class="algExample2">
              Union( BGP(?s :p1 ?v1) , BGP(?s :p2 ?v2) )
            </div>
          </div>

          <p>Example: group consisting of a union of a union and a basic graph pattern:</p>

          <div class="algExample">
            <div class="algExample1">
              { { ?s :p1 ?v1 } UNION {?s :p2 ?v2 } UNION {?s :p3 ?v3 } }
            </div>

            <div class="algExample2">
              Union(<br/>
              &nbsp;&nbsp;&nbsp; Union( Join(Z, BGP(?s :p1 ?v1)),<br/>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p2 ?v2))) 
              ,<br/>
            &nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p3 ?v3)) )</div>

            <div class="algExample2">
              Union( <br/>
              &nbsp;&nbsp;&nbsp; Union( BGP(?s :p1 ?v1) ,<br/>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BGP(?s :p2 ?v2),<br/>
            &nbsp;&nbsp;&nbsp; BGP(?s :p3 ?v3))</div>
          </div>

          <p>Example: group consisting of a basic graph pattern and an optional graph 
          pattern:</p>

          <div class="algExample">
            <div class="algExample1">
              { ?s :p1 ?v1 OPTIONAL {?s :p2 ?v2 } }
            </div>

            <div class="algExample2">
              LeftJoin(<br/>
              &nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p1 ?v1)),<br/>
              &nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p2 ?v2)),<br/>
              &nbsp;&nbsp;&nbsp; true)
            </div>

            <div class="algExample2">
              LeftJoin(BGP(?s :p1 ?v1), BGP(?s :p2 ?v2), true)
            </div>
          </div>

          <p>Example: group consisting of a basic graph pattern and two optional graph 
          patterns:</p>

          <div class="algExample">
            <div class="algExample1">
              { ?s :p1 ?v1 OPTIONAL {?s :p2 ?v2 } OPTIONAL { ?s :p3 ?v3 } }
            </div>

            <div class="algExample2">
              LeftJoin(<br />
              &nbsp;&nbsp;&nbsp; LeftJoin(<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BGP(?s :p1 ?v1),<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BGP(?s :p2 ?v2),<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              true) ,<br />
              &nbsp;&nbsp;&nbsp; BGP(?s :p3 ?v3),<br />
              &nbsp;&nbsp;&nbsp; true)
            </div>
          </div>

          <p>Example: group consisting of a basic graph pattern and an optional graph 
          pattern with a filter:</p>

          <div class="algExample">
            <div class="algExample1">
              { ?s :p1 ?v1 OPTIONAL {?s :p2 ?v2 FILTER(?v1&lt;3) } }
            </div>

            <div class="algExample2">
              LeftJoin(<br/>
              &nbsp;&nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p1 ?v1)),<br/>
              &nbsp;&nbsp;&nbsp;&nbsp; Join(Z, BGP(?s :p2 ?v2)),<br/>
              &nbsp;&nbsp;&nbsp;&nbsp; (?v1&lt;3) )
            </div>

            <div class="algExample2">
              LeftJoin(<br/>
              &nbsp;&nbsp;&nbsp; BGP(?s :p1 ?v1) ,<br/>
              &nbsp;&nbsp;&nbsp; BGP(?s :p2 ?v2) ,<br/>
              &nbsp;&nbsp; (?v1&lt;3) )
            </div>
          </div>

          <p>Example: group consisting of a union graph pattern and an optional graph 
          pattern:</p>

          <div class="algExample">
            <div class="algExample1">
              { {?s :p1 ?v1} UNION {?s :p2 ?v2} OPTIONAL {?s :p3 ?v3} }
            </div>

            <div class="algExample2">
              LeftJoin(<br />
              &nbsp;
              Union(BGP(?s :p1 ?v1),<br/>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BGP(?s :p2 ?v2)) ,<br />
              &nbsp;
              BGP(?s :p3 ?v3) ,<br />
              &nbsp;
              true )
            </div>
          </div>

          <p>Example: group consisting of a basic graph pattern, a filter and an optional 
          graph pattern:</p>

          <div class="algExample">
            <div class="algExample1">
            { ?s :p1 ?v1 FILTER (?v1 &lt; 3 ) OPTIONAL {?s :p2 ?v2} }</div>

            <div class="algExample2">
              Filter( ?v1 &lt; 3 ,<br />
              &nbsp;
              LeftJoin( BGP(?s :p1 ?v1), BGP(?s :p2 ?v2), true) ,<br />
              &nbsp;
              )
            </div>
          </div>

	  <p>Example: Pattern involving BIND:</p>
          <div class="algExample">
            <div class="algExample1">
            { ?s :p ?v . BIND (2*?v AS ?v2) ?s :p1 ?v2 }
	    </div>
            <div class="algExample2">
	      Join(<br/>
	      &nbsp;&nbsp;
	      Extend( BGP(?s :p ?v), ?v2, 2*?v) , <br/>
	      &nbsp;&nbsp;
	      BGP(?s :p1 ?v2)
              )
            </div>
          </div>

	  <p>Example: Pattern involving BIND:</p>
          <div class="algExample">
            <div class="algExample1">
            { ?s :p ?v . {} BIND (2*?v AS ?v2) }
	    </div>
            <div class="algExample2">
	      Join(<br/>
	      &nbsp;&nbsp; BGP(?s :p ?v), ?v2, 2*?v) , <br/>
	      &nbsp;&nbsp; Extend({}, ?v2, 2*?v) <br/>
              )
            </div>
          </div>

	  <p>Example: Pattern involving MINUS:</p>
          <div class="algExample">
            <div class="algExample1">
	      { ?s :p ?v . MINUS {?s :p1 ?v2 } }
	    </div>
            <div class="algExample2">
	      Minus(<br/>
	      &nbsp;&nbsp;
	      BGP(?s :p ?v)<br/>
	      &nbsp;&nbsp;
	      BGP(?s :p1 ?v2))
            </div>
          </div>

	  <p>Example: Pattern involving a subquery:</p>
          <div class="algExample">
            <div class="algExample1">
	      { ?s :p ?o . {SELECT DISTINCT ?o {?o ?p ?z} } }
	    </div>
            <div class="algExample2">
	      Join(<br/>
	      &nbsp;&nbsp;
	      BGP(?s :p ?o) ,<br/>
	      &nbsp;&nbsp;
	      ToMultiSet(<br/>
	      &nbsp;&nbsp;&nbsp;&nbsp;
	      Distinct(Project(BGP(?o ?p ?z), {?o})) )<br/>
	      &nbsp;&nbsp;
	      )
            </div>
          </div>

        </div3>

        <div3 id="convertGroupAggSelectExpressions">
          <head>Converting Groups, Aggregates, HAVING, final VALUES clause and SELECT Expressions</head>
          <p>In this step, we process clauses on the query level in the following order:</p>

          <ul>
            <li>Grouping</li>
            <li>Aggregates</li>
            <li>HAVING</li>
            <li>VALUES</li>
            <li>Select expressions</li>
          </ul>
          
          <div4 id="sparqlGroupAggregate">
            <head>Grouping and Aggregation</head>

            <p>Step: GROUP BY</p>
            <p>If the <code>GROUP BY</code> keyword is used, or there is implicit grouping due to the use of aggregates in the projection, then grouping is performed by the <a href="#defn_algGroup">Group</a> function. It divides the solution set into groups of one or more solutions, with the same overall cardinality. In case of implicit grouping, a fixed constant (1) is used to group all solutions into a single group.</p>

            <p>Step: Aggregates</p>
	    <p>The aggregation step is applied as a transformation on the query level, replacing aggregate expressions in the query level with Aggregation() algebraic expressions.</p>

            <p>The transformation for query levels that use any aggregates is given below:</p>
	    <pre class="codeBlock">Let A := the empty sequence
Let Q := the query level being evaluated
Let P := the algebra translation of the GroupGraphPattern of the query level
Let E := [], a list of pairs of the form (variable, expression)

If Q contains GROUP BY exprlist
   Let G := Group(exprlist, P)
Else If Q contains an aggregate in SELECT, HAVING, ORDER BY
   Let G := Group((1), P)
Else
   skip the rest of the aggregate step
   End

Global i := 1   # Initially 1 for each query processed

For each (X AS Var) in SELECT, each HAVING(X), and each ORDER BY X in Q
  For each unaggregated variable V in X
      Replace V with Sample(V)
      End
  For each aggregate R(args ; scalarvals) now in X
      # note scalarvals may be omitted, then it's equivalent to the empty set
      A<span><sub>i</sub></span> := Aggregation(args, R, scalarvals, G)
      Replace R(...) with agg<span><sub>i</sub></span> in Q
      i := i + 1
      End
  End

For each variable V appearing outside of an aggregate
   A<span><sub>i</sub></span> := Aggregation(V, Sample, {}, G)
   E := E append (V, agg<span><sub>i</sub></span>)
   i := i + 1
   End

A := A<span><sub>i</sub></span>, ..., A<span><sub>i-1</sub></span>
P := AggregateJoin(A)
</pre>

    <p>Note: agg<sub>i</sub> is a temporary variable. E is then used in 18.2.4.4 for the processing of select
expressions.</p>

    <p>Example:</p>

    <pre class="query">PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
SELECT (SUM(?val) AS ?sum) (COUNT(?a) AS ?count)
WHERE {
  ?a rdf:value ?val .
} GROUP BY ?a</pre>

    <p>The SUM expression becomes agg<sub>1</sub>, and the COUNT expression becomes agg<sub>2</sub>.</p>

      <pre class="code">Let G := Group((?a), BGP(?a rdf:value ?val))
<span>A<sub>1</sub></span> = Aggregation((?val), Sum, {}, G)
<span>A<sub>2</sub></span> = Aggregation((?a), Count, {}, G)
A := (<span>A<sub>1</sub>, A<sub>2</sub></span>)
Let P := AggregateJoin(A)</pre>
</div4>

          <div4 id="sparqlHavingClause">
            <head>HAVING</head>

            <p>The HAVING expression is evaluated using the same rules as FILTER(). Note that, 
	    due to the logic position in which the HAVING clause is evaluated, expressions projected
	    by the SELECT clause are not visible to the HAVING clause.</p>
	    <pre class="codeBlock">Let Q := the query level being evaluated
Let P := the algebra translation of the query level so far

For each HAVING(E) in Q
    P := Filter(E, P)
    End</pre>

          </div4>

          
	  <div4 id="sparqlAlgebraFinalValues">
            <head>VALUES</head>
	    <p>If the query has a trailing VALUES clause:</p>
            <pre class="codeBlock">Let P := the algebra translation of the query level so far
P := Join(P, ToMultiSet(data))
  where <i>data</i> is a solution sequence formed from the VALUES clause</pre>
  <p>The translatation of the data is the same as for <a href="#data-block">inline data</a>.</p>

	  </div4>

          <div4 id="sparqlSelectExpressions">
            <head>SELECT Expressions</head>
            <p>Step: Select expressions</p>
            
	    <p>We have two forms of the abstract syntax to consider:</p>
	    <pre class="codeBlock">SELECT selItem ... { pattern }
SELECT * { pattern }</pre>
            <pre class="codeBlock">Let X := algebra from earlier steps
Let VS := list of all variables visible in the pattern,
           so restricted by sub-SELECT projected variables and GROUP BY variables.
           Not visible: only in filter, exists/not exists, masked by a subselect, 
                        non-projected GROUP variables, only in the right hand side of MINUS

Let PV := {}, a set of variable names
Note, E is a list of pairs of the form (variable, expression), defined in <a href="#convertGroupAggSelectExpressions">section 18.2.4</a>
  
If &quot;SELECT *&quot;
    PV := VS

If  &quot;SELECT <code>selItem ...</code>:&quot;  
    For each selItem:
        If selItem is a variable
            PV := PV &cup; { variable }
        End
        If selItem is (expr AS variable)
            variable must not appear in VS nor in PV; if it does then generate a syntax error and stop
            PV := PV &cup; { variable }
            E := E append (variable, expr) 
        End
    End

For each pair (var, expr) in E
    X := Extend(X, var, expr)
    End
  
Result is X  
The set PV is used later for projection.
            </pre>

            <p>The syntax error arises for use of a variable as the named target of AS (e.g. 
            ... AS ?x) when the variable is used inside the WHERE clause of the SELECT or
	    if already used as the traget of AS in this SELECT expression.</p>
          </div4>

        </div3>

        <div3 id="convertSolMod">
          <head>Converting Solution Modifiers</head>
          
          <p>Solutions modifiers apply to the processing of a SPARQL query after pattern matching.
          The solution modifiers are applied to a query in the following order:</p>
          <ul>
            <li>Order by</li>
            <li>Projection</li>
            <li>Distinct</li>
            <li>Reduced</li>
            <li>Offset</li>
            <li>Limit</li>
          </ul>

          <p>Step: ToList</p>

          <p>ToList turns a multiset into a sequence with the same elements and cardinality. There is no implied ordering to
          the sequence; duplicates need not be adjacent.</p>

          <blockquote>
            <p>Let M := ToList(Pattern)</p>
          </blockquote>

          <div4 id="sparqlOrderBy">
            <head>ORDER BY</head>
        
          <p>If the query string has an ORDER BY clause</p>
        
          <blockquote>
            <p>M := OrderBy(M, list of order comparators)</p>
          </blockquote>

          </div4>

          <div4 id="sparqlProjection" >
            <head>Projection</head>

            <p>The set of projection variables, <code>PV</code>, was calculated in the 
	    <a href="#sparqlSelectExpressions">processing of SELECT expressions</a>.</p>

            <blockquote>
              <p>M := Project(M, PV)</p>
            </blockquote>

            <p>where vars is the set of variables mentioned in the SELECT 
            clause or all named variables that are <a href="#variableScope">in-scope</a>
	    in the query if SELECT * used.
            </p>
          </div4>

          <div4 id="sparqlDistinct">
            <head>DISTINCT</head>

            <p>If the query contains DISTINCT,</p>

            <blockquote>
              <p>M := Distinct(M)</p>
            </blockquote>
          </div4>

          <div4 id="sparqlReduced">
            <head>REDUCED</head>

            <p>If the query contains REDUCED,</p>

            <blockquote>
              <p>M := Reduced(M)</p>
            </blockquote>
          </div4>

          <div4 id="sparqlOffsetLimit">
            <head>OFFSET and LIMIT</head>

            <p>If the query contains "OFFSET start" or "LIMIT length"</p>

            <blockquote>
              <p>M := Slice(M, start, length)</p>
              <blockquote>
                <p>start defaults to 0</p>
                <p>length defaults to (size(M)-start).</p>
              </blockquote>
            </blockquote>
          </div4>
          
          <div4 id="sparqlAlgebraOutcome">
            <head>Final Algebra Expression</head>
            <blockquote>The overall abstract query is M.</blockquote>
          </div4>
        </div3>
      </div2>
      
      <div2 id="BasicGraphPattern">
        <head>Basic Graph Patterns</head>
        <p>When matching graph patterns, the possible solutions form a <i>
        <a href="http://en.wikipedia.org/w/index.php?title=Multiset&amp;oldid=163605900">multiset</a></i> [<a href="#multiset">multiset</a>], also known as 
        a <i>bag</i>. A multiset is an unordered collection of elements in which each 
        element may appear more than once. It is described by a set of elements and a
        cardinality function giving the number of occurrences of each element from the 
        set in the multiset.</p>
        
        <p>Write &mu; for solution mappings.</p>
        <p>Write &mu;<sub>0</sub> for the mapping such that dom(&mu;<sub>0</sub>) is the empty set.</p>
      
        <p>Write &Omega;<sub>0</sub> for the multiset consisting of exactly the empty mapping &mu;<sub>0,</sub> with
        cardinality 1. This is the join identity.</p>
        
        <p>Write &mu;(x) for the solution mapping variable x to RDF term t : { (x, t) }</p>

        <p>Write &Omega;(x) for the multiset consisting of exactly &mu;(?x-&gt;t), that is, { { (x, t) } } with
        cardinality 1.</p>

        <div class="defn">
          <b>Definition: <a id="defn_algCompatibleMapping" name="defn_algCompatibleMapping">Compatible Mappings</a></b>

          <p>Two solution mappings &mu;<sub>1</sub> and &mu;<sub>2</sub> are compatible if, for every variable v in
        dom(&mu;<sub>1</sub>) and in dom(&mu;<sub>2</sub>), &mu;<sub>1</sub>(v) = &mu;<sub>2</sub>(v).</p>
        </div>

	<p>Here, &mu;<sub>1</sub>(v) = &mu;<sub>2</sub>(v) means that &mu;<sub>1</sub>(v) and &mu;<sub>2</sub>(v) are the same RDF term.</p>

        <p>If &mu;<sub>1</sub> and &mu;<sub>2</sub> are compatible then &mu;<sub>1</sub> &cup; &mu;<sub>2</sub>
        is also a mapping. Write merge(&mu;<sub>1</sub>, &mu;<sub>2</sub>) for &mu;<sub>1</sub> &cup; &mu;<sub>2</sub></p>

        <p>Write card[&Omega;](&mu;) for the cardinality of solution mapping &mu; in a multiset 
        of mappings &Omega;.</p>

        <div3 id="BGPsparql">
          <head>SPARQL Basic Graph Pattern Matching</head>

          <p>A basic 
          graph pattern is matched against the active graph for that part of the query. 
          Basic graph patterns can be instantiated by 
          replacing both variables and blank nodes by terms, giving two notions 
          of instance. Blank nodes are replaced using an
          <a href="http://www.w3.org/TR/rdf-mt#definst">RDF 
          instance mapping</a>, &nbsp;&#963;, from blank nodes to RDF terms; variables are 
          replaced by a solution mapping from query variables to RDF terms.</p>
          
          <div class="defn">
            <b>Definition: <a id="defn_PatternInstanceMapping" name="defn_PatternInstanceMapping">Pattern Instance Mapping</a></b>
            
            <p>A <b>Pattern Instance Mapping</b>, P, is the combination of an RDF 
            instance mapping, &#963;, and solution mapping, &#956;. P(x) = &#956;(&#963;(x))</p>
          </div>
          
          <p>For a BGP 'x', P(x) denotes the result of replacing blank
          nodes b in x for which &#963; is defined with &#963;(b) and all
          variables v in x for which &#956; is defined with &#956;(v).</p>
          
          <p>Any pattern instance mapping defines a unique solution mapping
          and a unique RDF instance mapping obtained by restricting it to query 
          variables and blank nodes respectively.</p>
          
          <div class="defn">
            <b>Definition: Basic Graph Pattern Matching</b>
            <p>Let BGP be a basic graph pattern and let G be an RDF graph.</p>
            <p>&mu; is a <b>solution</b> for BGP from G when there is a pattern instance 
            mapping P such that P(BGP) is a subgraph of G and &#956; is the restriction of P to 
            the query variables in BGP.</p>
            <p>card[&Omega;](&mu;) = card[&Omega;](number of distinct RDF instance mappings, &#963;, 
            such that P = &#956;(&#963;) is a pattern instance mapping and P(BGP) is a subgraph of G).</p>
          </div>    
          <p>If a basic graph pattern is the empty set, then the solution is &Omega;<sub>0</sub>.</p>
        </div3>
        <div3 id="BGPsparqlBNodes">
          <head>Treatment of Blank Nodes</head>

          <p>This definition allows the solution mapping to bind a variable in a 
          basic graph pattern, BGP, to a blank node in G. Since SPARQL treats 
          blank node identifiers in a results format document 

(<a href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query Results XML Format</a>,
<a href="http://www.w3.org/TR/sparql11-results-json/">SPARQL 1.1 Query Results JSON Format</a> and
<a href="http://www.w3.org/TR/sparql11-results-csv-tsv/">SPARQL 1.1 Query Results CSV and TSV Formats</a>)

          as scoped to the document, they 
          cannot be understood as identifying nodes in the active graph of the dataset. If DS is 
          the dataset of a query, pattern solutions are therefore understood to 
          be not from the active graph of DS itself, but from an RDF graph, called the <i>scoping 
          graph,</i> which is graph-equivalent to the active graph of DS but shares no blank nodes 
          with DS or with BGP. The same scoping graph is used for all solutions 
          to a single query. The scoping graph is purely a theoretical 
          construct; in practice, the effect is obtained simply by the document 
          scope conventions for blank node identifiers. </p>

          <!--
            <div class="defn">
            <b>Definition:</b> <a id="defn_ScopingGraph" name="defn_GraphSet">Scoping Graph</a>

            <p>The <span class="definedTerm">Scoping Graph</span> G' for
            RDF graph G, is an RDF Graph that is <a href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#section-graph-equality">

            graph-equivalent</a> to G</p>
            </div>
          -->
          <p>Since RDF blank nodes allow infinitely many redundant solutions for 
          many patterns, there can be infinitely many pattern solutions (obtained 
          by replacing blank nodes by different blank nodes). It is necessary, 
          therefore, to somehow delimit the solutions for a basic graph pattern. SPARQL uses the 
          subgraph match criterion to determine the solutions of a basic graph 
          pattern. There is 
          one solution for each distinct pattern instance mapping from the basic 
          graph pattern to a subset of the active graph.</p>
          <p>This is optimized for ease of computation rather 
          than redundancy elimination. It allows query results to contain 
          redundancies even when the active graph of the dataset is 
          <a href="http://www.w3.org/TR/rdf-mt/#deflean">lean</a>, and it allows logically 
          equivalent datasets to yield different query results. </p>

        </div3>
      </div2>

    <div2 id="PropertyPathPatterns">
      <head>Property Path Patterns</head>

      <p>This section defines the evaluation of 
      <a href="#defn_PropertyPathPattern">property path patterns</a>.
      A property path pattern is a subject endpoint (an RDF term or a variable),
      a property path express and an object endpoint. 
      The <a href="#sparqlTranslatePathExpressions">translation of property path expressions</a>
      converts some forms to other SPARQL expressions, such as converting property
      paths of length one to triple patterns, which in turn are combined into basic
      graph patterns.  This leaves property path operators ZeroOrOnePath, ZeroOrMorePath,
      OneOrMorePath and NegatedPropertySets and also path expressions contained within these
      operators.
      </p>
      <p>All remaining property path expressions are present in the algebra in the form
      <code>Path(X, path, Y)</code> for endpoints X and Y.
      For example: syntax<code>(:p/:q)*</code> is a ZeroOrMorePath expression involving
      a sequence property path becoming the algebra expession <code>ZeroOrMorePath(seq(link(:p), link(:q)))</code>.
      </p>

      <div class="defn">
	<p><b><a name="pp-eval-notation">Notation</a></b></p>
	<p>Write</p>
	<pre>eval(Path(X, PP, Y))</pre>
	<p>
	  for the evaluation of the property path patterns.
	  This produces a multiset of solution mappings  &mu;, each solution mapping having
	  a binding for variables used (each of X and Y can be a variable).
	  Some operators only produce a set of solution mappings.
	</p>
	<p>Write</p>
	<div class="pre">Var(x<sub>1</sub>, x<sub>2</sub>, ..., x<sub>n</sub>) = { x<sub>i</sub> | i in 1...n and x<sub>i</sub> is a variable }</div>
	<p>for the variables in <code>x<sub>1</sub>, x<sub>2</sub>, ..., x<sub>n</sub></code>.</p>
	<p>Write</p>

	<table style="border-collapse: collapse; border-color: #000000" border="1" cellpadding="10">
	  <tbody>
	    <tr>
	      <td><code>x:term</code></td>
	      <td>when <code>x</code> is an RDF term</td>
	    </tr>
	    <tr>
	      <td><code>x:var</code></td>
	      <td>when <code>x</code> is a variable</td>
	    </tr>
	    <tr>
	      <td><code>x:path</code></td>
	      <td>when <code>x</code> is a path expression</td>
	    </tr>
	  </tbody>
	</table>
	</div>

      <p>
	All evaluation is carried out by matching the 
	<a href="#defn_ActiveGraph">active graph</a> at that point in the
	overall query evaluation.  We omit explicitly including the active
	graph in each definition for clarity.</p>

      <div class="defn">
	<p><b>Definition: <a name="defn_evalPP_predicate">Evaluation of Predicate Property Path</a></b></p>
	<p>Let Path(X, link(iri), Y) be an predicate inverse property path pattern,
	using some IRI iri.</p>
	<blockquote>
	  <div class="pre">eval(Path(X, link(iri), Y)) = <a href="#BasicGraphPattern">evaluation of basic graph pattern</a> {X iri Y}</div>
	</blockquote>
      </div>

      <p>If both X and Y are variables, this is the same as:</p>
      <div class="pre">eval(Path(X:var, link(iri), Y:var)) = 
    { (X, xn) (Y, yn) | xn and yn are RDF terms and triple (xn iri yn) is in the active graph }</div>

      <p>If X is a variable and Y an RDF term:</p>
      <div class="pre">eval(Path(X:var, link(iri), Y:term)) = 
    { (X, xn) | xn is an RDF term and triple (xn iri Y) is in the active graph }</div>

      <p>If X is an RDF term and Y is a variable:</p>
      <div class="pre">eval(Path(X:term, link(iri), Y:var)) =
    { (Y, yn) | yn is an RDF term and triple (X iri yn) is in the active graph }</div>

      <p>If both X and Y are RDF terms:</p>
      <div class="pre">eval(Path(X:term, link(iri), Y:term)) = 
    { μ<sub>0</sub> } if triple (X iri Y) is in the active graph
    = { { } }
    = Ω<sub>0</sub>

eval(Path(X:term, link(iri), Y:term)) = 
    { } if triple (X iri Y) is not in the active graph</div>

      <p>Informally, evaluating a Predicate Property Path is the same as executing a subquery 
      <code>SELECT * { <i>X P Y</i> }</code> at that point in the query evaluation.
      </p>
      
      <div class="defn">
	<p><b>Definition: <a name="defn_evalPP_inverse">Evaluation of Inverse Property Path</a></b></p>
	<p>Let P be a property path expression, then:</p>
	<blockquote>
	  <pre>eval(Path(X, inv(P), Y)) = eval(Path(Y, P, X))</pre>
	</blockquote>
      </div>
      
      <div class="defn">
	<p><b>Definition: <a name="defn_evalPP_sequence">Evaluation of Sequence Property Path</a></b></p>
	<p>
	  Let P and Q be property path expressions.
	  Let V be a fresh variable.
	</p>
	<blockquote>
	  <pre>A = Join( eval(Path(X, P, V)), eval(Path(V, Q, Y)) )</pre>
	  <pre>eval(Path(X, seq(P,Q), Y)) = Project(A, Var(X,Y))</pre>
	</blockquote>
      </div>

      <p>Informally, this is the same as:</p>
      <pre>SELECT * { X P _:a . _:a Q Y }</pre>
      <p>using the fact that a blank node <code>_:a</code> acts like a variable (under simple entailment)
      except it does not appear in the results from <code>SELECT *</code>.</p>

      <div class="defn">
	<p><b>Definition: <a name="defn_evalPP_alternative">Evaluation of Alternative Property Path</a></b></p>
	<p>
	  Let P and Q be property path expressions.
	</p>
	<blockquote>
	  <pre>eval(Path(X, alt(P,Q), Y)) = Union(eval(Path(X, P, Y)), eval(Path(X, Q, Y)))</pre>
	</blockquote>
      </div>

      <p>Informally, this is the same as:</p>
      <pre>SELECT * { { X P Y } UNION { X Q Y } }</pre>

      <div class="defn">
	<p><b>Definition: <a id="defn_nodeSet" name="defn_nodeSet">Node set of a graph</a></b></p>
	<p>The node set of a graph G, nodes(G), is:</p>
	<p>nodes(G) = { n | n is an RDF term that is used as a subject or object of a triple of G}</p>
      </div>

      <div class="defn">
	<p><b>Definition: <a id="defn_evalPP_ZeroOrOnePath">Evaluation of ZeroOrOnePath</a></b></p>
	<pre>eval(Path(X:term, ZeroOrOnePath(P), Y:var)) = { (Y, yn) | yn = X or {(Y, yn)} in eval(Path(X,P,Y)) }</pre>
	<pre>eval(Path(X:var, ZeroOrOnePath(P), Y:term)) = { (X, xn) | xn = Y or {(X, xn)} in eval(Path(X,P,Y)) }</pre>
	<pre>eval(Path(X:term, ZeroOrOnePath(P), Y:term)) = 
    { {} } if X = Y or eval(Path(X,P,Y)) is not empty
    { } othewise</pre>
	<pre>eval(Path(X:var, ZeroOrOnePath(P), Y:var)) = 
    { (X, xn) (Y, yn) | either (yn in nodes(G) and xn = yn) or {(X,xn), (Y,yn)} in eval(Path(X,P,Y)) }</pre>
      </div>

      <p>
	We define an auxillary function, ALP, used in the definitions of 
	ZeroOrMorePath and OneOrMorePath.
	Note that the algorithm given here serves to specify the feature. 
	An implementation is free to implement evaluation by any method that 
	produces the same results for the query overall.
	The ZeroOrMorePath and OneOrMorePath forms return matches based 
	on distinct nodes connected by the path.
      </p>

      <p>The matching algorithm is based on following all paths, and detecting
      when a graph node (subject or object), has been already visited on the path.
      </p>
      <p>Informally, this algorithm attempts to extend the multiset of results by one 
      application of 
      <tt>path</tt> at each step, noting which nodes it has visited 
      for this particular path. If a node has been visited for the path 
      under consideration, it is not a candidate for another step.</p>

      <div class="defn">
	<p><b>Definition: <a name="defn_evalALP_1">Function ALP</a></b></p>
	<pre>Let eval(x:term, path) be the evaluation of 'path', starting at RDF term x, 
                       and returning a multiset of RDF terms reached 
                       by repeated matches of path.

ALP(x:term, path) = 
    Let V = empty multiset
    ALP(x:term, path, V)
    return is V

# V is the set of nodes visited

ALP(x:term, path, V:set of RDF terms) =
    if ( x in V ) return 
    add x to V
    X = eval(x,path) 
    For n:term in X
        ALP(n, path, V)
        End
</pre>
      </div>

      <div class="defn">
	<p><b>Definition: Evaluation of <a name="defn_evalZeroOrMorePath">ZeroOrMorePath</a></b></p>

	<pre>eval(Path(X:term, ZeroOrMorePath(path), vy:var)) =
    { { (vy, n) } | n in ALP(X, path) }

eval(Path(vx:var, ZeroOrMorePath(path), vy:var)) =
    { { (vx, t), (vy, n) } |  t in nodes(G), (vy, n) in eval(Path(t, ZeroOrMorePath(path), vy)) }

eval(Path(vx:var, ZeroOrMorePath(path), y:term)) = 
    eval(Path(y:term, ZeroOrMorePath(inv(path)), vx:var))

eval(Path(x:term, ZeroOrMorePath(path), y:term)) = 
    { { } } if { (vy:var,y) } in eval(Path(x, ZeroOrMorePath(path) vy)
    { } otherwise
	</pre>
      </div>

      <div class="defn">
	<p><b>Definition: Evaluation of <a name="defn_evalOneOrMorePath">OneOrMorePath</a></b></p>
	<p>eval(Path(X, OneOrMorePath(path), Y))</p>
	<pre># For OneOrMorePath, we take one step of the path then start
# recording nodes for results.

eval(Path(x:term, OneOrMorePath(path), vy:var)) =
    Let X = eval(x, path)
    Let V = the empty multiset
    For n in X
        ALP(n, path, V)
        End
    result is V

eval(Path(vx:var, OneOrMorePath(path), vy:var)) =
   { { (vx, t), (vy, n) } |  t in nodes(G), (vy, n) in eval(Path(t, OneOrMorePath(path), vy)) }

eval(Path(vx:var, OneOrMorePath(path), y:term)) =
   eval(Path(y:term, OneOrMorePath(inv(path)), vx))

eval(Path(x:term, OneOrMorePath(path), y:term)) =
    { { } } if { (vy:var, y) } in eval(Path(x, OneOrMorePath(path), vy))
    { } otherwise
	</pre>
      </div>

      <div class="defn">
	<p><b>Definition: <a id="eval_negatedPropertySet" name="eval_negatedPropertySet">Evaluation of NegatedPropertySet</a></b></p>
	<pre class="code">Write μ' as the extension of a solution mapping:
μ'(μ,x) = μ(x)   if x is a variable
μ'(μ,t) = t   if t is a RDF term
	</pre>
	<pre class="code">Let x and y be variables or RDF terms, and S a set of IRIs:

eval(Path(x, NPS(S), y)) = { μ | &exists; triple(μ'(μ,x), p, μ'(μ,y)) in G, such that the IRI of p &notmember; S }
	</pre> 
      </div>

    </div2>

      <div2 id="sparqlAlgebra">
        <head>SPARQL Algebra</head>
        <p>
	  For each remaining symbol in a SPARQL abstract query, we define an operator for 
	  evaluation. The SPARQL algebra operators of the same name are
	  used to evaluate SPARQL abstract query nodes as described in the section 
	  "<a href="#sparqlAlgebraEval">Evaluation Semantics</a>".
	  Evaluation of basic graph patterns and property path patterns
	  has been described above.
	</p>

        <div class="defn">
          <p><b>Definition: <a id="defn_algFilter" name="defn_algFilter">Filter</a></b></p>

          <p>Let &Omega; be a multiset of solution mappings and expr be an expression. We define:</p>

          <p>Filter(expr, &Omega;, D(G)) = { &mu; | &mu; in &Omega; and expr(&mu;) is an expression that has an 
          effective boolean value of true }</p>

          <p>card[Filter(expr, &Omega;, D(G))](&mu;) = card[&Omega;](&mu;)</p>
	  <blockquote>
	    Note that evaluating an <code>exists(pattern)</code> expression uses the dataset and active graph, D(G).
	    See the <a href="#defn_evalFilter">evaluation of filter</a>.
	  </blockquote>
        </div>

        <div class="defn">
          <p><b>Definition: <a id="defn_algJoin" name="defn_algJoin">Join</a></b></p>

          <p>Let &Omega;<sub>1</sub> and &Omega;<sub>2</sub> be multisets of solution mappings. We define:</p>

          <p>Join(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>) = { merge(&mu;<sub>1</sub>, &mu;<sub>2</sub>) | &mu;<sub>1</sub>
          in &Omega;<sub>1</sub>and &mu;<sub>2</sub> in &Omega;<sub>2</sub>, and &mu;<sub>1</sub> and &mu;<sub>2</sub> are
          compatible }</p>

          <p>card[Join(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>)](&mu;) = <br/>
          &nbsp;&nbsp;&nbsp; for each merge(&mu;<sub>1</sub>, &mu;<sub>2</sub>), &mu;<sub>1</sub>
          in &Omega;<sub>1</sub>and &mu;<sub>2</sub> in &Omega;<sub>2</sub> such that &mu; = merge(&mu;<sub>1</sub>, &mu;<sub>2</sub>),<br/>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum over (&mu;<sub>1</sub>, &mu;<sub>2</sub>), card[&Omega;<sub>1</sub>](&mu;<sub>1</sub>)*card[&Omega;<sub>2</sub>](&mu;<sub>2</sub>)</p>
        </div>

        <p>It is possible that a solution mapping &mu; in a Join can arise in different 
        solution mappings, &mu;<sub>1</sub>and &mu;<sub>2</sub> in the multisets being 
        joined. The cardinality of&nbsp; &mu; is the sum of the cardinalities from all 
        possibilities.</p>

        <div class="defn">
          <p><b>Definition: <a id="defn_algDiff" name="defn_algDiff">Diff</a></b></p>

          <p>Let &Omega;<sub>1</sub> and &Omega;<sub>2</sub> be multisets of solution mappings
	  and expr be an expression. We define:</p>

          <p>Diff(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>, expr) =
          { &mu; | &mu; in &Omega;<sub>1</sub> such that &forall; &mu;&prime; in &Omega;<sub>2</sub>, 
          either &mu; and &mu;&#8242; are not compatible or &mu; and &mu;'
          are compatible and expr(merge(&mu;, &mu;')) has an effective boolean value 
          of false }</p>

          <p>card[Diff(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>, expr)](&mu;) = card[&Omega;<sub>1</sub>](&mu;)</p>
        </div>

        <p>Diff is used internally for the definition of LeftJoin.</p>

        <div class="defn">
          <p><b>Definition: <a id="defn_algLeftJoin" name="defn_algLeftJoin">LeftJoin</a></b></p>

          <p>Let &Omega;<sub>1</sub> and &Omega;<sub>2</sub> be multisets of solution mappings and 
          expr be an expression. We define:</p>

          <p>LeftJoin(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>, expr) = Filter(expr, Join(&Omega;<sub>1</sub>,
          &Omega;<sub>2</sub>)) &cup; Diff(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>, expr)</p>

          <p>card[LeftJoin(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>, expr)](&mu;) = card[Filter(expr,
          Join(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>))](&mu;) + card[Diff(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>,
          expr)](&mu;)</p>
        </div>

        <p>Written in full that is:</p>

        <p>LeftJoin(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>, expr) =<br />
        &nbsp;&nbsp;&nbsp;
        { merge(&mu;<sub>1,</sub> &mu;<sub>2</sub>) | &mu;<sub>1</sub> in &Omega;<sub>1</sub> and &mu;<sub>2</sub> in
        &Omega;<sub>2</sub>, &mu;<sub>1</sub> and &mu;<sub>2</sub> are compatible and expr(merge(&mu;<sub>1</sub>,
        &mu;<sub>2</sub>)) is true }<br />
        &cup;<br />
        &nbsp;&nbsp;&nbsp;
        { &mu;<sub>1</sub> | &mu;<sub>1</sub> in &Omega;<sub>1</sub>, &forall; &mu;<sub>2</sub> in &Omega;<sub>2</sub>, 
        &mu;<sub>1</sub> and &mu;<sub>2</sub> are not compatible, or &Omega;<sub>2</sub> is empty }<br />
        &cup;<br />
        &nbsp;&nbsp;&nbsp;
        { &mu;<sub>1</sub> | &mu;<sub>1</sub> in &Omega;<sub>1</sub>, &exists; &mu;<sub>2</sub> in &Omega;<sub>2</sub>, 
        &mu;<sub>1</sub> and &mu;<sub>2</sub> are compatible and expr(merge(&mu;<sub>1</sub>, &mu;<sub>2</sub>)) is false. }</p>

        <p>As these are distinct, the cardinality of LeftJoin is cardinality of these individual
        components of the definition.</p>

        <div class="defn">
          <p><b>Definition: <a id="defn_algUnion" name="defn_algUnion">Union</a></b></p>

          <p>Let &Omega;<sub>1</sub> and &Omega;<sub>2</sub> be multisets of solution mappings. We define:</p>

          <p>Union(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>) = { &mu; | &mu; in &Omega;<sub>1</sub> or &mu; in
          &Omega;<sub>2</sub> }</p>

          <p>card[Union(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>)](&mu;) = card[&Omega;<sub>1</sub>](&mu;) + card[&Omega;<sub>2</sub>](&mu;)</p>
        </div>

        <div class="defn">
          <p><b>Definition: <a id="defn_algMinus" name="defn_algMinus">Minus</a></b></p>
          <p>Let &Omega;<sub>1</sub> and &Omega;<sub>2</sub> be multisets of solution mappings. We define:</p>

          <p>Minus(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>) =
          { &mu; | &mu; in &Omega;<sub>1</sub> . &forall; &mu;' in &Omega;<sub>2</sub>, 
          either &mu; and &mu;' are not compatible or dom(&mu;) and dom(&mu;') are disjoint }</p>
          <p>card[Minus(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>)](&mu;) = card[&Omega;<sub>1</sub>](&mu;)</p>

        </div>

        <p>The additional restriction on dom(&mu;) and dom(&mu;') is added because otherwise
        if there is a solution mapping in &Omega;<sub>2</sub> that has no variables in 
        common with the solution mappings of &Omega;<sub>1</sub>, then
        Minus(&Omega;<sub>1</sub>, &Omega;<sub>2</sub>) would be empty, regardless of 
        the rest of &Omega;<sub>2</sub>. The empty solution mapping is compatible 
        with every other solution mapping so <code>P MINUS {}</code> would otherwise
	be empty for any pattern <code>P</code>.</p>

        <div class="defn">
          <b>Definition: <a name="defn_extend">Extend</a></b>

          <p>Let &mu; be a 
          solution mapping, &Omega; a multiset of solution mappings, <i>var</i> a variable 
          and <i>expr</i> be an <a href="#expressions">expression</a>, then we define:</p>

	  <p>Extend(&mu;, var, expr) = &mu; &cup; { (var,value) | var not in dom(&mu;) and value 
	  = expr(&mu;) }</p>
	  <p>Extend(&mu;, var, expr) = &mu; if var not in dom(&mu;) and expr(&mu;) is an 
	  error</p>
	  <!--<p>Extend(&mu;, var, expr) = ??? if var in dom(&mu;)</p>-->
	  <p>Extend is undefined when var in dom(&mu;).</p>
	  <p>Extend(&Omega;, var, expr) = { Extend(&mu;, var, expr) | &mu; in &Omega; }</p>
        </div>

        <p>Write [ x | C ] for a sequence of elements where C is a condition on x.</p>

        <p>Write card[L](x) to be the cardinality of x in L.</p>

        <div class="defn">
          <b>Definition: <a id="defn_algToList" name="defn_algToList">ToList</a></b>

          <p>Let &Omega; be a multiset of solution mappings.  We define:</p>

          <p>ToList(&Omega;) = a sequence of mappings &mu; in &Omega; in any order, with card[&Omega;](&mu;) occurrences of
          &mu;</p>
          <p>card[ToList(&Omega;)](&mu;) = card[&Omega;](&mu;)</p>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_algOrdered" name="defn_algOrdered">OrderBy</a></b>
          <p>Let &Psi; be a sequence of solution mappings.  We define:</p>

          <p><a id="defn_algOrderBy" name="defn_algOrderBy">OrderBy</a>(&Psi;, condition) = [ &mu; | &mu; in &Psi; and the
          sequence satisfies the ordering condition]</p>

          <p>card[OrderBy(&Psi;, condition)](&mu;) =
          card[&Psi;](&mu;)</p>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_algProjection" name="defn_algProjection">Project</a></b>

          <p>Let &Psi; be a sequence of solution mappings and PV a set of variables.</p>

          <p>For mapping &mu;, write Proj(&mu;, PV) to be the restriction of &mu; to variables in 
          PV.</p>
          
          <p>Project(&Psi;, PV)  = [ Proj(&Psi;[&mu;], PV) | &mu; in &Psi; ]</p>
          <p>card[Project(&Psi;, PV)](&mu;) = card[&Psi;](&mu;)</p>
          <p>The order of Project(&Psi;, PV) must preserve any ordering given by OrderBy.</p>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_algDistinct" name="defn_algDistinct">Distinct</a></b>

          <p>Let &Psi; be a sequence of solution mappings.  We define:</p>

          <p>Distinct(&Psi;) = [ &mu; | &mu; in &Psi; ]</p>
          <p>card[Distinct(&Psi;)](&mu;) = 1</p>

          <p>The order of Distinct(&Psi;) must preserve any ordering given by OrderBy.</p>
        </div>
        
        <div class="defn">
          <b>Definition: <a id="defn_algReduced" name="defn_algReduced">Reduced</a></b>

          <p>Let &Psi; be a sequence of solution mappings.  We define:</p>

          <p>Reduced(&Psi;) = [ &mu; | &mu; in &Psi; ]</p>
          <p>card[Reduced(&Psi;)](&mu;) is between 1 and card[&Psi;](&mu;)</p>

          <p>The order of Reduced(&Psi;) must preserve any ordering given by OrderBy.</p>
        </div>

        <p>The Reduced solution sequence modifier does not guarantee a defined cardinality.</p>

        <div class="defn">
          <b>Definition: <a id="defn_algSlice" name="defn_algSlice">Slice</a></b>

          <p>Let &Psi; be a sequence of solution mappings.  We define:</p>

          <p><a name="defn_algOrderBy2" id="defn_algOrderBy2">Slice</a>(&Psi;, start, length)[i] = &Psi;[start+i] for i = 0
          to (length-1)</p>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_algToMultiSet" name="defn_algToMultiSet">ToMultiSet</a></b>

          <p>Let &Psi; be a solution sequence.  We define:</p>

          <p>ToMultiSet(&Psi;) = { &mu; | &mu; in &Psi; }</p>
          <p>card[ToMultiSet(&Psi;)](&mu;) = card[&Psi;](&mu;)</p>
        </div>

    <p>ListEval is a function which is used to evaluate a list of expressions against a solution and return a list of the resulting values.</p>

    <div class="defn">
    <p><b><a name="defn_algToMultiset">Definition: ToMultiset</a></b></p>
    <p>ToMultiset turns a sequence into a multiset with the same elements and cardinality as the sequence. The order of the sequence has no effect on the resulting multiset, and duplicates are preserved.</p>
    </div>

    <div class="defn">
      <p><b>Definition: <a name="defn_exists">Exists</a></b></p>
      <p>exists(pattern) is a function that returns true if the pattern
      <a href="#defn_evalExists">evaluates</a>
      to a non-empty solution sequence, given the current solution mapping and active graph
	  at the time of evaluation; otherwise it returns false.</p>
    </div>

    <div3 id="aggregateAlgebra">
    <head>Aggregate Algebra</head>
    <p>Group is a function which groups a solution sequence into multiple solutions, based on some attribute of the solutions.</p>
    <div class="defn">
    <p><b><a name="defn_algGroup">Definition: Group</a></b></p>

    <p>Group evaluates a list of expressions against a solution sequence, producing a set of partial functions from keys to solution sequences.</p>

    <p>Group(exprlist, &Omega;) = { ListEval(exprlist, &mu;) &rarr; { &mu;' | &mu;' in &Omega;, ListEval(exprlist, &mu;) = ListEval(exprlist, &mu;') } | &mu; in &Omega; }</p>
    </div>

    <div class="defn">
    <p><b>Definition: ListEval</b></p>

    <p>ListEval((expr<sub>1</sub>, ..., expr<sub>n</sub>), &mu;) returns a list (e<sub>1</sub>, ..., e<sub>n</sub>), where e<sub>i</sub> = expr<sub>i</sub>(&mu;) or error.</p>
    <p>ListEval retains errors resulting from the evaluation of the list elements.</p>
    </div>

    <p>Note that, although the result of a ListEval can be an error, and errors may be used to group, solutions containing error values are removed at projection time.</p>
    <p>ListEval((unbound), &mu;) = (error), as the evaluation of an unbound expression is an error.</p>

    <p>Aggregation, a function which calculates a scalar value as an output of the aggregate expression. It is used  in the SELECT clause, the HAVING evaluation process, and in ORDER BY (where required). Aggregation calculates aggregated values over groups of solutions, using set functions.</p>

    <div class="defn">
    <p><b><a name="defn_algAggregation">Definition: Aggregation</a></b></p>
    <p>Let <i>exprlist</i> be a list of expressions or *, <i>func</i> a set function,
<i>scalarvals</i> a set of partial functions (possibly empty) passed from the
aggregate in the query, and let { key<sub>1</sub>&rarr;&Omega;<sub>1</sub>, ..., key<sub>m</sub>&rarr;&Omega;<sub>m</sub>
} be a multiset of partial functions from keys to solution sequences
as produced by the grouping step.</p>

    <p>Aggregation applies the set function func to the given multiset and produces a single value for each key and partition of solutions for that key.</p>

    <p>Aggregation(exprlist, func, scalarvals, { key<sub>1</sub>&rarr;&Omega;<sub>1</sub>, ..., key<sub>m</sub>&rarr;&Omega;<sub>m</sub> } )<br/>
&nbsp;&nbsp;&nbsp;= { (key, F(&Omega;)) | key &rarr; &Omega; in { key<sub>1</sub>&rarr;&Omega;<sub>1</sub>, ..., key<sub>m</sub>&rarr;&Omega;<sub>m</sub> } }</p>
<p>where<br/>
&nbsp;&nbsp;M(&Omega;) = { ListEval(exprlist, &mu;) | &mu; in &Omega; }<br/>
&nbsp;&nbsp;F(&Omega;) = func(M(&Omega;), scalarvals), for non-DISTINCT<br/>
&nbsp;&nbsp;F(&Omega;) = func(Distinct(M(&Omega;)), scalarvals), for DISTINCT</p>

<p><b>Special Case:</b> when <code>COUNT</code> is used with the expression <code>*</code> the value of F
will be the cardinality of the group solution sequence,
<code>card[&Omega;]</code>, or <code>card[Distinct(&Omega;)]</code> if the <code>DISTINCT</code> keyword is
present.</p>
    </div>

    <p><i>scalarvals</i> are used to pass values to the underlying set function,
bypassing the mechanics of the grouping. For example, the aggregate
expression <code>GROUP_CONCAT(?x ; separator="|")</code> has a scalarvals argument
of { "separator" &rarr; "|" }.</p>

    <p>All aggregates may have the <code>DISTINCT</code>
keyword as the first token in their argument list. If this keyword is
present then first argument to func is Distinct(M).</p>

    <p>Example</p>

    <p>Given a solution multiset (&Omega;) with the following values:</p>
      <table>
        <tr><td>solution</td><td>?x</td><td>?y</td><td>?z</td></tr>
        <tr><td>&mu;<sub>1</sub></td><td>1</td><td>2</td><td>3</td></tr>
        <tr><td>&mu;<sub>2</sub></td><td>1</td><td>3</td><td>4</td></tr>
        <tr><td>&mu;<sub>3</sub></td><td>2</td><td>5</td><td>6</td></tr>
      </table>

      <p>And the query expression SELECT (ex:agg(?y, ?z) AS ?agg) WHERE { ?x ?y ?z } GROUP BY ?x.</p>
      <p>We produce G = Group((?x), &Omega;) = { ( (1), { &mu;<sub>1</sub>, &mu;<sub>2</sub> } ), ( (2), { &mu;<sub>3</sub> } ) }</p>
      <p>And so Aggregation((?y, ?z), ex:agg, {}, G) =<br/>
      { ((1), eg:agg({(2, 3), (3, 4)}, {})), ((2), eg:agg({(5, 6)}, {})) }.</p>

    <div class="defn">
    <p><b>Definition: AggregateJoin</b></p>
    <p>Let S<sub>1</sub>, ..., S<sub>n</sub> be a list of sets, where each set S<sub>i</sub> contains key
to (aggregated) value maps as produced by Aggregate.</p>
    <p>Let K = { key | key in dom(S<sub>j</sub>) for some 1 &lt;= j &lt;= n } be the set of keys, then<br/>AggregateJoin(S<sub>1</sub>, ..., S<sub>n</sub>) = { agg<sub>1</sub>&rarr;val<sub>1</sub>, ..., agg<sub>n</sub>&rarr;val<sub>n</sub> | key in K and key&rarr;val<sub>i</sub> in S<sub>i</sub> for each 1 &lt;= i &lt;= n }</p>
    </div>

    <p>Flatten is a function which is used to collapse multisets of lists into a multiset, so for example { (1, 2), (3, 4) } becomes { 1, 2, 3, 4 }.</p>

    <div class="defn">
    <p><b>Definition: Flatten</b></p>
    <p>The Flatten(M) function takes a multiset of lists, M {(L<sub>1</sub>, L<sub>2</sub>, ...), ...}, and returns the multiset { x | L in M and x in L }.</p>
    </div>

    <div4 id="setFunctions"><head>Set Functions</head>
    <p>The set functions which underlie SPARQL aggregates all have a common
signature: SetFunc(M), or SetFunc(M, scalarvals) where M is a multiset
of lists, and scalarvals is one or more scalar values that are passed to the
set function indirectly via the ( ... ; key=value ) syntax for aggregates in the SPARQL grammar. The only use of this that is supported by the built-in aggregates in SPARQL Query 1.1 is <code>GROUP_CONCAT</code>, as in <code>GROUP_CONCAT(?x ; separator=", ")</code>.</p>

    <p>Note that the name "Set Function" is somewhat historical — the arguments to set functions are in fact multisets. The name is retained due to the commonality with SQL Set Functions, which also operate over multisets.</p>

    <p>The set functions defined in this document are Count, Sum, Min, Max, Avg, GroupConcat, and Sample — corresponding to the aggregates <code>COUNT</code>, <code>SUM</code>, <code>MIN</code>, <code>MAX</code>, <code>AVG</code>, <code>GROUP_CONCAT</code>, and <code>SAMPLE</code>. Definitions may be found in the following sections. Systems may choose to expand this set using local extensions, using the same notation as for functions and casts. Note that, unless the ; separator is used this requires the parser to know whether some IRI refers to a function, cast, or aggregate before it can determine if there are any errors in a query where aggregates are used.</p>
  </div4>

    <div4 id="defn_aggCount">
    <head>Count</head>
    <p>Count is a SPARQL set function which counts the number of times a given expression has a bound, and non-error value within the aggregate group.</p>

    <div class="defn">
    <p><b>Definition: Count</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">xsd:integer   Count(multiset M)</code></pre>
    <p>N = Flatten(M)</p>
    <p>remove error elements from N</p>
    <p>Count(M) = card[N]</p>
    </div>
    </div4>

    <div4 id="defn_aggSum">
    <head>Sum</head>
    <p>Sum is a SPARQL set function that will return the numeric value obtained
by summing the values within the aggregate group. Type promotion happens as per
the op:numeric-add function, applied transitively, (see definition below) so the
value of SUM(?x), in an aggregate group where ?x has values 1 (integer), 2.0e0
(float), and 3.0 (decimal) will be 6.0 (float).</p>

    <div class="defn">
    <p><b>Definition: Sum</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">numeric   Sum(multiset M)</code></pre>
    <p>The Sum set function is used by the <code>SUM</code> aggregate in the syntax.</p>
    <p>Sum(M) = Sum(ToList(Flatten(M))).</p>
    <p>Sum(S) = op:numeric-add(S<sub>1</sub>, Sum(S<sub>2..n</sub>)) when card[S] &gt; 1<br/>
    Sum(S) = op:numeric-add(S<sub>1</sub>, 0) when card[S] = 1<br/>
    Sum(S) = "0"^^xsd:integer when card[S] = 0</p>
    
    <p>In this way, Sum({1, 2, 3}) = op:numeric-add(1, op:numeric-add(2, op:numeric-add(3, 0))).</p>
    </div>
    </div4>

    <div4 id="defn_aggAvg">
    <head>Avg</head>
    <p><a name="defn_algAvg"></a>The Avg set function calculates the average value for an expression over
a group. It is defined in terms of Sum and Count.</p>

    <div class="defn">
    <p><b>Definition: Avg</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">numeric   Avg(multiset M)</code></pre>
    <p>Avg(M) = "0"^^xsd:integer, where Count(M) = 0</p>
    <p>Avg(M) = Sum(M) / Count(M), where Count(M) > 0</p>
    </div>

    <p>For example, Avg({1, 2, 3}) = Sum({1, 2, 3})/Count({1, 2, 3}) = 6/3 = 2.</p>

    </div4>

    <div4 id="defn_aggMin">
    <head>Min</head>

    <p>Min is a SPARQL set functions that returns the minimum value from a group respectively.</p>
    <p>It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.</p>

    <div class="defn">
    <p><b>Definition: Min</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">term   Min(multiset M)</code></pre>
    <p>Min(M) = Min(ToList(Flatten(M)))</p>
    <p>Min({}) = error.</p>
    <p>The flattened multiset of values passed as an argument is converted to a sequence S, this sequence is ordered as per the <code>ORDER BY ASC</code> clause.</p>
    <p>Min(S) = S<sub>0</sub></p>
    </div>
    </div4>

    <div4 id="defn_aggMax">
    <head>Max</head>

    <p>Max is a SPARQL set function that return the maximum value from a group respectively.</p>
    <p>It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.</p>

    <div class="defn">
    <p><b>Definition: Max</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">term   Max(multiset M)</code></pre>
    <p>Max(M) = Max(ToList(Flatten(M)))</p>
    <p>Max({}) = error.</p>
    <p>The multiset of values passed as an argument is converted to a sequence S, this sequence is ordered as per the <code>ORDER BY DESC</code> clause.</p>
    <p>Max(S) = S<sub>0</sub></p>
    </div>
    </div4>

    <div4 id="defn_aggGroupConcat">
    <head>GroupConcat</head>
    <p>GroupConcat is a set function which performs a string concatenation
across the values of an expression with a group. The order of the strings is
not specified. The separator character used in the concatenation may be given
with the scalar argument SEPARATOR.</p>

    <div class="defn">
    <p><b>Definition: GroupConcat</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">literal   GroupConcat(multiset M)</code></pre>
    <p>If the "separator" scalar argument is absent from GROUP_CONCAT then it is taken to be the "space" character, unicode codepoint U+0020.</p>
    <p>The multiset of values, M passed as an argument is converted to a sequence S.</p>
    <p>GroupConcat(M, scalarvals) = GroupConcat(Flatten(M), scalarvals("separator"))</p>
    <p>GroupConcat(S, sep) = "", where <span style="font-size: 140%">|</span>S<span style="font-size: 140%">|</span> = 0</p>
    <p>GroupConcat(S, sep) = CONCAT("", S<sub>0</sub>), where <span style="font-size: 140%">|</span>S<span style="font-size: 140%">|</span> = 1</p>
    <p>GroupConcat(S, sep) = CONCAT(S<sub>0</sub>, sep, GroupConcat(S<sub>1..n-1</sub>, sep)), where <span style="font-size: 140%">|</span>S<span style="font-size: 140%">|</span> > 1</p>
    </div>

    <p>For example, GroupConcat({"a", "b", "c"}, {"separator" &rarr; "."}) = "a.b.c".</p>

    </div4>

    <div4 id="defn_aggSample">
    <head>Sample</head>
    <p>Sample is a set function which returns an arbitrary value from the multiset passed to it.</p>
    <div class="defn">
    <p><b>Definition: Sample</b></p>
    <pre xmlns="http://www.w3.org/1999/xhtml" class="prototype"><code xmlns="http://www.w3.org/1999/xhtml">RDFTerm   Sample(multiset M)</code></pre>
    <p>Sample(M) = v, where v in Flatten(M)</p>
    <p>Sample({}) = error</p>
    </div>

    <p>For example, given Sample({"a", "b", "c"}), "a", "b", and "c" are all valid return values. Note that Sample() is not required to be deterministic for a given input, the only restriction is that the output value must be present in the input multiset.</p>
    </div4>
    </div3>

      </div2>

      <div2 id="sparqlAlgebraEval">
        <head>Evaluation Semantics</head>

        <p>We define eval(D(G), algebra expression) as the evaluation of an algebra expression
	with respect to a dataset D having active
        graph G. The active graph is initially the default graph.</p>

        <pre class="box">D : a dataset
D(G) : D a dataset with active graph G (the one patterns match against)
D[i] : The graph with IRI i in dataset D
P, P1, P2 : graph patterns
L : a solution sequence
F : an expression</pre>
        <div class="defn">
          <b>Definition: <a id="defn_evalBasicGraphPattern" name="defn_evalBasicGraphPattern">Evaluation of a Basic Graph Pattern</a></b>
          <pre class="code">eval(D(G), BGP) = multiset of solution mappings</pre>
          <p>See section <a href="#BasicGraphPattern">Basic Graph Patterns</a></p>
        </div>

	<div class="defn">
	  <b>Definition: <a id="defn_evalPropertyPathPattern" name="defn_evalPropertyPathPattern">Evaluation of a Property Path Pattern</a></b>
	  <pre class="code">eval(D(G), Path(X, path, Y)) = multiset of solution mappings</pre>
          <p>See section <a href="#defn_PropertyPathExpr">Property Path Expresions</a></p>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalFilter" name="defn_evalFilter">Evaluation of Filter</a></b>
          <pre class="code">eval(D(G), Filter(F, P)) = Filter(F, eval(D(G),P), D(G))</pre>
        </div>

	<p>'substitute' is a filter function in support of the evaluation of 
	  <a href="#func-filter-exists"><code>EXISTS</code> and <code>NOT EXISTS</code></a>
	  forms which were translated to <code>exists</code>.
	</p>

	<div class="defn">
	  <p><b>Definition: <a name="defn_substitute">Substitute</a></b></p>
	  <p>Let &mu; be a solution mapping.</p>
	  <blockquote>
	    <p>substitute(<i>pattern</i>, &mu;) = the pattern formed by replacing every 
	    occurrence of a variable v in <i>pattern</i> by &mu;(v) for each v in dom(&mu;)</p>
	  </blockquote>
	</div>

	<div class="defn">
	  <p><b>Definition: <a name="defn_evalExists">Evaluation of Exists</a></b></p>
	  <p>Let &mu; be the current solution mapping for a filter and P a graph pattern:</p>
	  <blockquote>
	    The value exists(P), given D(G) is true if and only if eval(D(G), substitute(P, &mu;)) is a non-empty sequence.
	  </blockquote>
	</div>

        <div class="defn">
          <b>Definition: <a id="defn_evalJoin" name="defn_evalJoin">Evaluation of Join</a></b>
          <pre class="code">eval(D(G), Join(P1, P2)) = Join(eval(D(G), P1), eval(D(G), P2))</pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalLeftJoin" name="defn_evalLeftJoin">Evaluation of LeftJoin</a></b>
          <pre class="code">eval(D(G), LeftJoin(P1, P2, F)) = LeftJoin(eval(D(G), P1), eval(D(G), P2), F)</pre>
        </div>

	<div class="defn">
          <b>Definition: <a id="defn_evalUnion" name="defn_evalUnion">Evaluation of Union</a></b>
          <pre class="code">eval(D(G), Union(P1,P2)) = Union(eval(D(G), P1), eval(D(G), P2))</pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalGraph" name="defn_evalGraph">Evaluation of Graph</a></b>
          <pre class="code">if IRI is a graph name in D
eval(D(G), Graph(IRI,P)) = eval(D(D[IRI]), P)</pre>
          <pre class="code">if IRI is not a graph name in D
eval(D(G), Graph(IRI,P)) = the empty multiset</pre>
          <pre class="code">eval(D(G), Graph(var,P)) =
     Let R be the empty multiset
     foreach IRI i in D
        R := Union(R, Join( eval(D(D[i]), P) , &Omega;(?var-&gt;i) )
     the result is R
          </pre>
        </div>
        <p>The evaluation of graph uses the SPARQL algebra union operator. The 
        cardinality of a solution mapping is the sum of the cardinalities of that 
        solution mapping in each join operation.</p>

    <div class="defn">
      <p><b><a name="defn_evalGroup">Definition: Evaluation of Group</a></b></p>

      <p>eval(D(G), Group(exprlist, P)) = Group(exprlist, eval(D(G), P))</p>
    </div>

    <div class="defn">
    <p><b><a name="defn_evalAggregation">Definition: Evaluation of Aggregation</a></b></p>

    <p>eval(D(G), Aggregation(exprlist, func, scalarvals, P)) = Aggregation(exprlist, func, scalarvals, eval(D(G), P))</p>
    </div>

    <div class="defn">
      <p><b><a name="defn_evalAggregateJoin">Definition: Evaluation of AggregateJoin</a></b></p>
      <p>eval(D(G), AggregateJoin(A<sub>1</sub>, ..., A<sub>n</sub>)) = AggregateJoin(eval(D(G), A<sub>1</sub>), ..., eval(D(G), A<sub>n</sub>))</p>
      </div>
      <p>Note that if eval(D(G), A<sub>i</sub>) is an error, it is ignored.</p>

        <div class="defn">
          <b>Definition: <a id="defn_evalExtend" name="defn_evalExtend">Evaluation of Extend</a></b>
          <pre class="code">eval(D(G), Extend(P, var, expr)) = Extend(eval(D(G), P), var, expr)</pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalList" name="defn_evalList">Evaluation of ToList</a></b>
          <pre class="code">eval(D(G), ToList(P)) = ToList(eval(D(G), P))</pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalDistinct" name="defn_evalDistinct">Evaluation of Distinct</a></b>
          <pre class="code">eval(D(G), Distinct(L)) = Distinct(eval(D(G), L))
          </pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalReduced" name="defn_evalReduced">Evaluation of Reduced</a></b>
          <pre class="code">eval(D(G), Reduced(L)) = Reduced(eval(D(G), L))
          </pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalProject" name="defn_evalProject">Evaluation of Project</a></b>
          <pre class="code">eval(D(G), Project(L, vars)) = Project(eval(D(G), L), vars)
          </pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalOrderBy" name="defn_evalOrderBy">Evaluation of OrderBy</a></b>
          <pre class="code">eval(D(G), OrderBy(L, condition)) = OrderBy(eval(D(G), L), condition)
          </pre>
        </div>
        
        <div class="defn">
          <b>Definition: <a id="defn_evalToMultiSet" name="defn_evalToMultiSet">Evaluation of ToMultiSet</a></b>
          <pre class="code">eval(D(G), ToMultiSet(L)) = ToMultiSet(eval(D), M))</pre>
        </div>

        <div class="defn">
          <b>Definition: <a id="defn_evalSlice" name="defn_evalSlice">Evaluation of Slice</a></b>
          <pre class="code">eval(D(G), Slice(L, start, length)) = Slice(eval(D(G), L), start, length)</pre>
        </div>

      </div2>

      <div2 id="sparqlBGPExtend">
        <head>Extending SPARQL Basic Graph Matching</head>
        
        <p>The overall SPARQL design can be used for queries 
        which assume a more elaborate form of entailment than simple 
        entailment, by re-writing the matching conditions for basic graph 
        patterns. Since it is an open research problem to state such 
        conditions in a single general form which applies to all forms of 
        entailment and optimally eliminates needless or inappropriate 
        redundancy, this document only gives necessary conditions which any 
        such solution should satisfy. These will need to be extended to full 
        definitions for each particular case. </p>

        <p>Basic graph patterns stand in the same relation to triple patterns 
        that RDF graphs do to RDF triples, and much of the same terminology 
        can be applied to them. In particular, two basic graph patterns are 
        said to be <i>equivalent</i> if there is a bijection M between the 
        terms of the triple patterns that maps blank nodes to blank nodes and 
        maps variables, literals and IRIs to themselves, such that a triple ( 
        s, p, o ) is in the first pattern if and only if the triple ( M(s), 
        M(p), M(o) ) is in the second. This definition extends that for RDF 
        graph equivalence to basic graph patterns by preserving variable 
        names across equivalent patterns. </p>

        <p>An <i>entailment regime</i> specifies </p>
        <ol>
          <li>a subset of RDF graphs called <i>well-formed</i> for the regime</li>
          <li>an <i>entailment</i> relation between subsets of well-formed graphs
          and well-formed graphs.</li>
        </ol>

	<p>Detailed definitions for querying various entailment regimes can be found in
	<a href="http://www.w3.org/TR/sparql11-entailment/">SPARQL 1.1 Entailment Regimes</a>.
	</p>

        <p>Some entailment regimes can categorize some RDF 
        graphs as inconsistent. For example, the RDF graph:</p>
        <pre class="data">_:x rdf:type xsd:string .
_:x rdf:type xsd:decimal .</pre>
        <p>is D-inconsistent when D contains the XSD datatypes. The effect of a query
        on an inconsistent graph is not 
        covered by this specification, but must be specified by the particular 
        SPARQL extension.</p>
        
        <p>An entailment regime E must provide conditions on basic graph pattern 
        evaluation such that for any basic graph pattern BGP, any RDF graph G,
        and any evaluation that satisfies the conditions, the resulting
        multiset of solutions is uniquely determined up to RDF graph
        equivalence. We denote the multiset of solutions from evaluating BGP
        over G using E with Eval-E(G, BGP).<br/>
        An entailment regime must further satisfy the following conditions:</p>
        <ol>
          <li>For any E-consistent active graph AG, the entailment regime E uniquely 
          specifies a <a href="#BGPsparqlBNodes">scoping graph</a> SG that is 
          E-equivalent to AG.</li>
          <li>A set of well-formed graphs for E is specified such that, for any
          basic graph pattern BGP, scoping graph SG, and solution mapping &mu; in
          Eval-E(SG, BGP), the graph &mu;(BGP) is well-formed for E. </li>
          <li>For any basic graph pattern BGP and scoping graph SG, if &mu;<sub>1</sub>, 
          ..., &mu;<sub>n</sub> in Eval-E(SG, BGP) and BGP<sub>1</sub>, ..., 
          BGP<sub>n</sub> are basic graph patterns all equivalent to BGP but not 
          sharing any blank nodes with each other or with SG, then
          <blockquote>
            <p>SG E-entails (SG union &mu;<sub>1</sub>(BGP<sub>1</sub>) union ... 
            union &mu;<sub>n</sub>(BGP<sub>n</sub>))</p>
          </blockquote>
         <p>These conditions do not fully determine the set of possible answers, since 
          RDF allows unlimited amounts of redundancy. In addition, therefore, the 
          following must hold.</p></li>
          <li> Entailment regimes should provide conditions to prevent trivial
          infinite solution multisets as appropriate to the regime.</li>
        </ol>

        <div3 id="sparqlBGPExtend-notes">
          <head>Notes</head>
          <p>(a) SG will often be graph equivalent to AG, but restricting this to 
          E-equivalence allows some forms of normalization, for example elimination of 
          semantic redundancies, to be applied to the source documents before querying.
          </p>
          <p>(b) The construction in condition 3 ensures that any blank nodes introduced 
          by the solution mapping are used in a way which is internally consistent with the 
          way that blank nodes occur in SG. This ensures that blank node identifiers occur 
          in more than one answer in an answer set only when the blank nodes so identified 
          are indeed identical in SG. If the extension does not allow bindings to 
          blank nodes, then this condition can be simplified to the condition:</p>
          <blockquote>
            <p>SG E-entails &mu;(BGP) for each solution mapping &mu;.</p>
          </blockquote>
          <p>(c) These conditions do not impose the SPARQL requirement that SG shares no 
          blank nodes with AG or BGP. In particular, it allows SG to actually be AG. This 
          allows query protocols in which blank node identifiers retain their meaning 
          between the query and the source document, or across multiple queries. Such 
          protocols are not supported by the current SPARQL protocol specification, 
          however. </p>
          <p>(d) Since conditions 1 to 3 are only necessary conditions on answers, 
          condition 4 allows cases where the set of legal answers can be restricted in 
          various ways. 
	  </p>
          <p>(e) None of these conditions refer explicitly to instance mappings on blank 
          nodes in BGP. For some entailment regimes, the existential interpretation of 
          blank nodes cannot be fully captured by the existence of a single instance 
          mapping. These conditions allow such regimes to give blank nodes in query 
          patterns a 'fully existential' reading. </p>
          <p>It is straightforward to show that SPARQL satisfies these conditions for the 
          case where E is simple entailment, given that the SPARQL condition on SG is that 
          it is graph-equivalent to AG but shares no blank nodes with AG or BGP (which 
          satisfies the first condition). The only condition which is nontrivial is (3).
          </p>
          <p>For every solution mapping &mu;<sub>i</sub>, there is, by definition of
          basic graph pattern matching, an RDF instance mapping &#963;<sub>i</sub> such 
          that P<sub>i</sub>(BGP<sub>i</sub>) is a subgraph of SG where P<sub>i</sub> is 
          the pattern instance mapping composed of &mu;<sub>i</sub> and &#963;<sub>i</sub>. 
          Since BGP<sub>i</sub> and SG have no blank nodes in common, the ranges of 
          &#963;<sub>i</sub> and &mu;<sub>i</sub> contain no blank nodes from BGP<sub>i</sub>; 
          therefore, the solution mapping &mu;<sub>i</sub> and the RDF instance mapping 
          &#963;<sub>i</sub> of P<sub>i</sub> commute, so P<sub>i</sub>(BGP<sub>i</sub>) 
          = &#963;<sub>i</sub>(&mu;<sub>i</sub>(BGP<sub>i</sub>)). So</p>
          <p>P<sub>1</sub>(BGP<sub>1</sub>) union ... union P<sub>n</sub>(BGP<sub>n</sub>)
          <br/>= &#963;<sub>1</sub>(&mu;<sub>1</sub>(BGP<sub>1</sub>)) union ... union 
          &#963;<sub>n</sub>(&mu;<sub>n</sub>(BGP<sub>n</sub>))
          <br/>= [ &#963;<sub>1</sub> + ... + &#963;<sub>n</sub>]( 
          &mu;<sub>1</sub>(BGP<sub>1</sub>) union ... union 
          &mu;<sub>n</sub>(BGP<sub>n</sub>) )</p>
          <p>since the domains of the &#963;<sub>i</sub> RDF instance mappings are all mutually
          exclusive. Since they are also exclusive from SG,</p>
          <p>SG union [ &#963;<sub>1</sub> + ... + &#963;<sub>n</sub>]( 
          &mu;<sub>1</sub>(BGP<sub>1</sub>) union ... union &mu;<sub>n</sub>(BGP<sub>n</sub>) )
          <br/>= [ &#963;<sub>1</sub> + ... + &#963;<sub>n</sub>](SG union 
          &mu;<sub>1</sub>(BGP<sub>1</sub>) union ... union &mu;<sub>n</sub>(BGP<sub>n</sub>) )</p>
          <p>i.e. </p>
          <p>SG union &mu;<sub>1</sub>(BGP<sub>1</sub>) union ... union 
          &mu;<sub>n</sub>(BGP<sub>n</sub>)</p>
          <p>has an instance which is a subgraph of SG, so is simply entailed by SG by the <a 
          href="http://www.w3.org/TR/rdf-mt/#interplemmaprf">RDF interpolation lemma</a> 
          [<a href="#RDF-MT">RDF-MT</a>].
          </p>
        </div3>
      </div2>

    </div1>


    <div1 id="grammar">
      <head>SPARQL Grammar</head>

      <p>The SPARQL grammar covers both SPARQL Query and 
      <a href="http://www.w3.org/TR/sparql11-update/">SPARQL Update</a>.</p>

      <div2 id="queryString">
	<head>SPARQL Request String</head>

	<p>A <a name="defn_SPARQLRequestString" id="defn_SPARQLRequestString">SPARQL Request String</a>
	is a SPARQL Query String or SPARQL Update String and it is a Unicode character string 
	(c.f. section 6.1 String concepts of [<a href="#CHARMOD">CHARMOD</a>]) 
	in the language defined by the following grammar.</p>

	<p>A <a name="defn_SPARQLQueryString" id="defn_SPARQLQueryString">SPARQL Query String</a> 
	start at the <a href="#rQueryUnit">QueryUnit</a> production.</p>

	<p>A <a name="defn_SPARQLUpdateString" id="defn_SPARQLUpdateString">SPARQL Update String</a> 
	start at the <a href="#rUpdateUnit">UpdateUnit</a> production.</p>

	<p>
	  For compatibility with future versions of 
	  Unicode, the characters in this string may
	  include Unicode codepoints that are unassigned 
	  as of the date of this publication (see
	  <a class="inform" href="http://www.unicode.org/reports/tr31/tr31-5.html">Identifier 
	  and Pattern Syntax</a> [<a href="#UNIID">UNIID</a>] section 4 Pattern Syntax).
	  For productions with excluded character classes 
	  (for example <code>[^&lt;&gt;&#39;{}|^`]</code>),
	  the characters are excluded from the range
	<code>#x0 - #x10FFFF</code>.</p>
	
      </div2>

        <div2 id="codepointEscape">
          <head>Codepoint Escape Sequences</head>
<p>A SPARQL Query String is processed for codepoint escape sequences before parsing 
by the grammar defined in EBNF below. The codepoint escape sequences for a SPARQL 
query string are:</p>
<table summary="Codepoint escapes" id="table68">
  <colgroup><col width="40%" />
  </colgroup>
  <tr>
    <th class="major">Escape</th>
    <th class="major">Unicode code point</th>
  </tr>
  <tr>
    <td><span class="token">&#39;\u&#39;</span> <a href="#HEX">HEX</a>
    <a href="#HEX">HEX</a> <a href="#HEX">HEX</a> <a href="#HEX">HEX</a></td>
    <td>A Unicode code point in the range U+0 to U+FFFF inclusive corresponding 
    to the encoded hexadecimal value.</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\U&#39;</span> <a href="#HEX">HEX</a>
    <a href="#HEX">HEX</a> <a href="#HEX">HEX</a> <a href="#HEX">HEX</a>
    <a href="#HEX">HEX</a> <a href="#HEX">HEX</a> <a href="#HEX">HEX</a>
    <a href="#HEX">HEX</a></td>
    <td>A Unicode code point in the range U+0 to U+10FFFF inclusive corresponding 
    to the encoded hexadecimal value.</td>
  </tr>
</table>
<p>where <a href="#HEX">HEX</a> is a hexadecimal character</p>
<blockquote>
  <p><code><a name="HEX" id="HEX">HEX</a> ::= [0-9] | [A-F] | [a-f]</code></p>
</blockquote>
<p>Examples:</p>
<pre class="query untested">&lt;ab\u00E9xy&gt;        # Codepoint 00E9 is Latin small e with acute - &eacute;
\u03B1:a            # Codepoint x03B1 is Greek small alpha - &#945;
a\u003Ab            # a:b -- codepoint x3A is colon</pre>
<p>Codepoint escape sequences can appear anywhere in the query string. They are 
processed before parsing based on the grammar rules and so may be replaced by codepoints 
with significance in the grammar, such as &quot;<code>:</code>&quot; marking a prefixed name.
</p>
<p>These escape sequences are not included in the grammar below. Only escape sequences 
for characters that would be legal at that point in the grammar may be given. For 
example, the variable &quot;<code>?x\u0020y</code>&quot; is not legal (<code>\u0020</code> 
is a space and is not permitted in a variable name).</p>
        </div2>
        <div2 id="whitespace">
          <head>White Space</head>
<p>White space (production <code class="gRuleBody"><a href="#rWS">WS</a></code>) 
is used to separate two terminals which would otherwise be (mis-)recognized as one 
terminal. Rule names below in capitals indicate where white space is significant; 
these form a possible choice of terminals for constructing a SPARQL parser. White 
space is significant in strings. Otherwise, white space is ignored between tokens.</p>
<p>For example:</p>
<blockquote>
  <p><code>?a&lt;?b&amp;&amp;?c&gt;?d</code></p>
</blockquote>
<p>is the token sequence variable '<code>?a</code>', an IRI '<code>&lt;?b&amp;&amp;?c&gt;</code>', 
and variable '<code>?d</code>', not a expression involving the operator '<code>&amp;&amp;</code>' 
connecting two expression using '<code>&lt;</code>' (less than) and '<code>&gt;</code>' (greater than).</p>
        </div2>
        <div2 id="grammarComments">
          <head>Comments</head>
<p>Comments in SPARQL queries take the form of &#39;<code>#</code>&#39;, outside an IRI 
or string, and continue to the end of line (marked by characters <code>0x0D</code> 
or <code>0x0A</code>) or end of file if there is no end of line after the comment 
marker. Comments are treated as white space.</p>
        </div2>
        <div2 id="iriRefs">
          <head>IRI References</head>
<p>Text matched by the <code class="gRuleBody"><a href="#rIRIREF">IRIREF</a></code> 
production and <code class="gRuleHead"><a href="#rPrefixedName">PrefixedName</a></code> (after 
prefix expansion) production, after escape processing, must conform to the generic 
syntax of IRI references in section 2.2 of RFC 3987 &quot;ABNF for IRI References and 
IRIs&quot; [<a href="#rfc3987">RFC3987</a>]. For example, the 
<code class="gRuleBody"><a href="#rIRIREF">IRIREF</a></code> <code>&lt;abc#def&gt;</code> may occur in a 
SPARQL query string, but the <code class="gRuleBody"><a href="#rIRIREF">IRIREF</a></code>
<code>&lt;abc##def&gt;</code> must not.</p>
<p>Base IRIs declared with the <span class="token">BASE</span> keyword must be absolute 
IRIs. A prefix declared with the <span class="token">PREFIX</span> keyword may not 
be re-declared in the same query. See section 4.1.1, <a href="#QSynIRI">Syntax 
of IRI Terms</a>, for a description of <span class="token">BASE</span> and
<span class="token">PREFIX</span>.</p>
        </div2>
        <div2 id="grammarBNodes">
          <head>Blank Nodes and Blank Node Labels</head>

	  <p>Blank nodes can not be used in:</p>
	  <ul>
	    <li><code><a href="#rDeleteWhere">DELETE WHERE</a></code></li>
	    <li><code><a href="#rDeleteWhere">DELETE DATA</a></code></li>
	    <li>a <code><a href="#rDeleteClause">DeleteClause</a></code></li>
	  </ul>
	  <p>in a 
	  <a href="http://www.w3.org/TR/sparql11-update/#terminology">SPARQL Update request</a>.
	  </p>

	  <p>Blank node labels are scoped to the 
	  <a href="#defn_SPARQLRequestString">SPARQL Request String</a>
	  in which they occur. Different uses of the same blank node label in a 
	  request string refer to the same blank node. Fresh blank nodes are generated for 
	  each request; blank nodes can not be referenced by label across requests.
	  </p>

	  <p>The same blank node label can not be used in:</p>
	  <ul>
	    <li>two basic graph patterns in a SPARQL Query</li>
	    <li>two <code><a href="#rModify">WHERE</a></code> clauses 
	    within a single SPARQL Update request</li>
	    <li>two <code><a href="#rInsertData">INSERT DATA</a></code>
	    operations within a single SPARQL Update request</li>
	  </ul>

	  <p>Note that the same blank node label can occur in different 
	  <a href="#rQuadPattern">QuadPattern</a> clauses
	  in a <a href="http://www.w3.org/TR/sparql11-update/">SPARQL Update</a> request.
	  </p>

        </div2>
        <div2 id="grammarEscapes">
          <head>Escape sequences in strings</head>
<p>In addition to the <a href="#codepointEscape">codepoint escape sequences</a>, the following escape sequences 
any <code><a href="#rString">string</a></code> production (e.g. <code>
<a href="#rSTRING_LITERAL1">STRING_LITERAL1</a></code>, <code>
<a href="#rSTRING_LITERAL2">STRING_LITERAL2</a></code>, <code>
<a href="#rSTRING_LITERAL_LONG1">STRING_LITERAL_LONG1</a></code>, <code>
<a href="#rSTRING_LITERAL_LONG2">STRING_LITERAL_LONG2</a></code>):</p>
<table summary="String escapes">
  <colgroup><col width="40%" />
  </colgroup>
  <tr>
    <th class="major">Escape</th>
    <th class="major">Unicode code point</th>
  </tr>
  <tr>
    <td><span class="token">&#39;\t&#39;</span></td>
    <td>U+0009 (tab)</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\n&#39;</span></td>
    <td>U+000A (line feed)</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\r&#39;</span></td>
    <td>U+000D (carriage return)</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\b&#39;</span></td>
    <td>U+0008 (backspace)</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\f&#39;</span></td>
    <td>U+000C (form feed)</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\&quot;&#39;</span></td>
    <td>U+0022 (quotation mark, double quote mark)</td>
  </tr>
  <tr>
    <td><span class="token">&quot;\&#39;&quot;</span></td>
    <td>U+0027 (apostrophe-quote, single quote mark)</td>
  </tr>
  <tr>
    <td><span class="token">&#39;\\&#39;</span></td>
    <td>U+005C (backslash)</td>
  </tr>
</table>
<p>Examples:</p>
<pre class="query untested">&quot;abc\n&quot;
&quot;xy\rz&quot;
&#39;xy\tz&#39;</pre>
        </div2>
        <div2 id="sparqlGrammar">
          <head>Grammar</head>
	  <p>The EBNF notation used in the grammar is defined in Extensible Markup Language 
	  (XML) 1.1 [<a href="#XML11">XML11</a>] section 6
	  <a class="norm" href="http://www.w3.org/TR/2004/REC-xml11-20040204/#sec-notation">Notation</a>.</p>

	  <p>Notes:</p>
 
	  <ol>
	    <li>Keywords are matched in a case-insensitive manner with the exception of the keyword 
	    &#39;<code>a</code>&#39; which, in line with Turtle and N3, is used in place of the IRI
	    <code>rdf:type</code> (in full, 
	    <code><a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
	    >http://www.w3.org/1999/02/22-rdf-syntax-ns#type</a></code>).</li>

	    <li>Escape sequences are case sensitive.</li>

	    <li>When tokenizing the input and choosing grammar rules, the longest match is chosen.</li>

	    <li>The SPARQL grammar is LL(1) when the rules with uppercased names are used as 
	    terminals.</li>

	    <li>There are two entry points into the grammar: <code>QueryUnit</code> for SPARQL queries,
	    and <code>UpdateUnit</code> for SPARQL Update requests.
	    </li>
	    
	    <li>In signed numbers, no white space is allowed between the sign and the 
	    number. The <code class="gRuleHead"><a href="#rAdditiveExpression">AdditiveExpression</a></code> grammar rule 
	    allows for this by covering the two cases of an expression followed by a 
	    signed number. These produce an addition or subtraction of the unsigned 
	    number as appropriate.</li>

	    <li>The tokens <code>INSERT DATA<code>, </code>DELETE DATA<code>, </code>DELETE WHERE</code> allow any amount of
	    white space between the words.  The single space version is used in the grammar for clarity.
	    </li>

	    <li>
	      The
	      <code class="gRuleHead"><a href="#rQuadData">QuadData</a></code> and 
	      <code class="gRuleHead"><a href="#rQuadPattern">QuadPattern</a></code>
	      rules both use rule <code class="gRuleHead"><a href="#rQuads">Quads</a></code>.
	      The rule <code class="gRuleHead"><a href="#rQuadData">QuadData</a></code>,
	      used in 
	      <a href="#rInsertData"><code>INSERT DATA</code></a>
	      and
	      <a href="#rDeleteData"><code>DELETE DATA</code></a>,
	      must not allow variables in the quad patterns.
	    </li>

	    <li>
	      Blank node syntax is not allowed in 
	      <code><a href="#rDeleteWhere">DELETE WHERE</a></code>,
	      the  <code><a href="#rDeleteClause">DeleteClause</a></code>
	      for <code>DELETE</code>, nor in
	      <a href="#rDeleteData"><code>DELETE DATA</code></a>.
	    </li>

	    <li>
	      Rules for limiting the use of blank node labels are given in <a href="#grammarBNodes"> section 19.6</a>.
	    </li>

	    <li>
	      The number of variables in the variable list of 
	      <code>VALUES</code> block
	      must be the same as the number of each list of associated values in the 
	      <code>DataBlock</code>.
	    </li>
	    <li>
	      Variables introduced by <code>AS</code> in a <code>SELECT</code> clause
	      must not already be <a href="#variableScope">in-scope</a>.
	    </li>
	    <li>
	      The variable assigned in a <code>BIND</code> clause must not be already 
	      in-use within the immediately preceding
	      <code><a href="#rTriplesBlock">TriplesBlock</a></code> within a 
	      <code><a href="#rGroupGraphPattern">GroupGraphPattern</a></code>.
	    </li>
	    <li>
	      Aggregate functions can be one of the
	      <a href="#rAggregate">built-in keywords for aggregates</a> or 
	      a custom aggregate, which is syntactically a
	      <a href="#rFunctionCall">function call</a>.
	      Aggregate functions may only be used in <a href="#rSelectClause">SELECT</a>,
	      <a href="#rHavingClause">HAVING</a> and 
	      <a href="#rOrderClause">ORDER BY</a> clauses.
	    </li>

	    <li>
	      Only custom aggregate functions use the <tt>DISTINCT</tt> keyword
	      in a <a href="#rFunctionCall">function call</a>.
	    </li>
	  </ol>

<!-- MARKER html GRAMMAR -->
<div class="grammarTable">
  <table><tbody>

<tr valign="baseline">
  <td><code class="gRuleLabel">[1]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rQueryUnit" name="rQueryUnit">QueryUnit</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rQuery">Query</a> <span class="token"></span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[2]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rQuery" name="rQuery">Query</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPrologue">Prologue</a><br/>( <a href="#rSelectQuery">SelectQuery</a> | <a href="#rConstructQuery">ConstructQuery</a> | <a href="#rDescribeQuery">DescribeQuery</a> | <a href="#rAskQuery">AskQuery</a> )<br/><a href="#rValuesClause">ValuesClause</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[3]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rUpdateUnit" name="rUpdateUnit">UpdateUnit</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rUpdate">Update</a> <span class="token"></span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[4]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPrologue" name="rPrologue">Prologue</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">( <a href="#rBaseDecl">BaseDecl</a> | <a href="#rPrefixDecl">PrefixDecl</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[5]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBaseDecl" name="rBaseDecl">BaseDecl</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'BASE'</span> <a href="#rIRIREF">IRIREF</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[6]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPrefixDecl" name="rPrefixDecl">PrefixDecl</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'PREFIX'</span> <a href="#rPNAME_NS">PNAME_NS</a> <a href="#rIRIREF">IRIREF</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[7]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSelectQuery" name="rSelectQuery">SelectQuery</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rSelectClause">SelectClause</a> <a href="#rDatasetClause">DatasetClause</a>* <a href="#rWhereClause">WhereClause</a> <a href="#rSolutionModifier">SolutionModifier</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[8]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSubSelect" name="rSubSelect">SubSelect</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rSelectClause">SelectClause</a> <a href="#rWhereClause">WhereClause</a> <a href="#rSolutionModifier">SolutionModifier</a> <a href="#rValuesClause">ValuesClause</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[9]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSelectClause" name="rSelectClause">SelectClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'SELECT'</span> ( <span class="token">'DISTINCT'</span> | <span class="token">'REDUCED'</span> )? ( ( <a href="#rVar">Var</a> | ( <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">'AS'</span> <a href="#rVar">Var</a> <span class="token">')'</span> ) )+ | <span class="token">'*'</span> )</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[10]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rConstructQuery" name="rConstructQuery">ConstructQuery</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'CONSTRUCT'</span> ( <a href="#rConstructTemplate">ConstructTemplate</a> <a href="#rDatasetClause">DatasetClause</a>* <a href="#rWhereClause">WhereClause</a> <a href="#rSolutionModifier">SolutionModifier</a> | <a href="#rDatasetClause">DatasetClause</a>* <span class="token">'WHERE'</span> <span class="token">'{'</span> <a href="#rTriplesTemplate">TriplesTemplate</a>? <span class="token">'}'</span> <a href="#rSolutionModifier">SolutionModifier</a> )</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[11]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDescribeQuery" name="rDescribeQuery">DescribeQuery</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'DESCRIBE'</span> ( <a href="#rVarOrIri">VarOrIri</a>+ | <span class="token">'*'</span> ) <a href="#rDatasetClause">DatasetClause</a>* <a href="#rWhereClause">WhereClause</a>? <a href="#rSolutionModifier">SolutionModifier</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[12]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rAskQuery" name="rAskQuery">AskQuery</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'ASK'</span> <a href="#rDatasetClause">DatasetClause</a>* <a href="#rWhereClause">WhereClause</a> <a href="#rSolutionModifier">SolutionModifier</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[13]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDatasetClause" name="rDatasetClause">DatasetClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'FROM'</span> ( <a href="#rDefaultGraphClause">DefaultGraphClause</a> | <a href="#rNamedGraphClause">NamedGraphClause</a> )</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[14]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDefaultGraphClause" name="rDefaultGraphClause">DefaultGraphClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rSourceSelector">SourceSelector</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[15]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNamedGraphClause" name="rNamedGraphClause">NamedGraphClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'NAMED'</span> <a href="#rSourceSelector">SourceSelector</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[16]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSourceSelector" name="rSourceSelector">SourceSelector</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[17]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rWhereClause" name="rWhereClause">WhereClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'WHERE'</span>? <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[18]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSolutionModifier" name="rSolutionModifier">SolutionModifier</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rGroupClause">GroupClause</a>? <a href="#rHavingClause">HavingClause</a>? <a href="#rOrderClause">OrderClause</a>? <a href="#rLimitOffsetClauses">LimitOffsetClauses</a>?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[19]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGroupClause" name="rGroupClause">GroupClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'GROUP'</span> <span class="token">'BY'</span> <a href="#rGroupCondition">GroupCondition</a>+</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[20]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGroupCondition" name="rGroupCondition">GroupCondition</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rBuiltInCall">BuiltInCall</a> | <a href="#rFunctionCall">FunctionCall</a> | <span class="token">'('</span> <a href="#rExpression">Expression</a> ( <span class="token">'AS'</span> <a href="#rVar">Var</a> )? <span class="token">')'</span> | <a href="#rVar">Var</a> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[21]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rHavingClause" name="rHavingClause">HavingClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'HAVING'</span> <a href="#rHavingCondition">HavingCondition</a>+</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[22]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rHavingCondition" name="rHavingCondition">HavingCondition</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rConstraint">Constraint</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[23]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rOrderClause" name="rOrderClause">OrderClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'ORDER'</span> <span class="token">'BY'</span> <a href="#rOrderCondition">OrderCondition</a>+</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[24]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rOrderCondition" name="rOrderCondition">OrderCondition</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">   ( ( <span class="token">'ASC'</span> | <span class="token">'DESC'</span> ) <a href="#rBrackettedExpression">BrackettedExpression</a> )<br/>| ( <a href="#rConstraint">Constraint</a> | <a href="#rVar">Var</a> ) </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[25]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rLimitOffsetClauses" name="rLimitOffsetClauses">LimitOffsetClauses</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rLimitClause">LimitClause</a> <a href="#rOffsetClause">OffsetClause</a>? | <a href="#rOffsetClause">OffsetClause</a> <a href="#rLimitClause">LimitClause</a>? </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[26]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rLimitClause" name="rLimitClause">LimitClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'LIMIT'</span> <a href="#rINTEGER">INTEGER</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[27]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rOffsetClause" name="rOffsetClause">OffsetClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'OFFSET'</span> <a href="#rINTEGER">INTEGER</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[28]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rValuesClause" name="rValuesClause">ValuesClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">( <span class="token">'VALUES'</span> <a href="#rDataBlock">DataBlock</a> )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[29]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rUpdate" name="rUpdate">Update</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPrologue">Prologue</a> ( <a href="#rUpdate1">Update1</a> ( <span class="token">';'</span> <a href="#rUpdate">Update</a> )? )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[30]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rUpdate1" name="rUpdate1">Update1</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rLoad">Load</a> | <a href="#rClear">Clear</a> | <a href="#rDrop">Drop</a> | <a href="#rAdd">Add</a> | <a href="#rMove">Move</a> | <a href="#rCopy">Copy</a> | <a href="#rCreate">Create</a> | <a href="#rInsertData">InsertData</a> | <a href="#rDeleteData">DeleteData</a> | <a href="#rDeleteWhere">DeleteWhere</a> | <a href="#rModify">Modify</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[31]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rLoad" name="rLoad">Load</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'LOAD'</span> <span class="token">'SILENT'</span>? <a href="#riri">iri</a> ( <span class="token">'INTO'</span> <a href="#rGraphRef">GraphRef</a> )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[32]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rClear" name="rClear">Clear</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'CLEAR'</span> <span class="token">'SILENT'</span>? <a href="#rGraphRefAll">GraphRefAll</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[33]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDrop" name="rDrop">Drop</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'DROP'</span> <span class="token">'SILENT'</span>? <a href="#rGraphRefAll">GraphRefAll</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[34]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rCreate" name="rCreate">Create</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'CREATE'</span> <span class="token">'SILENT'</span>? <a href="#rGraphRef">GraphRef</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[35]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rAdd" name="rAdd">Add</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'ADD'</span> <span class="token">'SILENT'</span>? <a href="#rGraphOrDefault">GraphOrDefault</a> <span class="token">'TO'</span> <a href="#rGraphOrDefault">GraphOrDefault</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[36]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rMove" name="rMove">Move</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'MOVE'</span> <span class="token">'SILENT'</span>? <a href="#rGraphOrDefault">GraphOrDefault</a> <span class="token">'TO'</span> <a href="#rGraphOrDefault">GraphOrDefault</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[37]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rCopy" name="rCopy">Copy</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'COPY'</span> <span class="token">'SILENT'</span>? <a href="#rGraphOrDefault">GraphOrDefault</a> <span class="token">'TO'</span> <a href="#rGraphOrDefault">GraphOrDefault</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[38]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rInsertData" name="rInsertData">InsertData</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'INSERT DATA'</span> <a href="#rQuadData">QuadData</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[39]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDeleteData" name="rDeleteData">DeleteData</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'DELETE DATA'</span> <a href="#rQuadData">QuadData</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[40]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDeleteWhere" name="rDeleteWhere">DeleteWhere</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'DELETE WHERE'</span> <a href="#rQuadPattern">QuadPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[41]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rModify" name="rModify">Modify</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">( <span class="token">'WITH'</span> <a href="#riri">iri</a> )? ( <a href="#rDeleteClause">DeleteClause</a> <a href="#rInsertClause">InsertClause</a>? | <a href="#rInsertClause">InsertClause</a> ) <a href="#rUsingClause">UsingClause</a>* <span class="token">'WHERE'</span> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[42]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDeleteClause" name="rDeleteClause">DeleteClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'DELETE'</span> <a href="#rQuadPattern">QuadPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[43]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rInsertClause" name="rInsertClause">InsertClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'INSERT'</span> <a href="#rQuadPattern">QuadPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[44]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rUsingClause" name="rUsingClause">UsingClause</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'USING'</span> ( <a href="#riri">iri</a> | <span class="token">'NAMED'</span> <a href="#riri">iri</a> )</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[45]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphOrDefault" name="rGraphOrDefault">GraphOrDefault</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'DEFAULT'</span> | <span class="token">'GRAPH'</span>? <a href="#riri">iri</a> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[46]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphRef" name="rGraphRef">GraphRef</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'GRAPH'</span> <a href="#riri">iri</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[47]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphRefAll" name="rGraphRefAll">GraphRefAll</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rGraphRef">GraphRef</a> | <span class="token">'DEFAULT'</span> | <span class="token">'NAMED'</span> | <span class="token">'ALL'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[48]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rQuadPattern" name="rQuadPattern">QuadPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'{'</span> <a href="#rQuads">Quads</a> <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[49]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rQuadData" name="rQuadData">QuadData</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'{'</span> <a href="#rQuads">Quads</a> <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[50]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rQuads" name="rQuads">Quads</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rTriplesTemplate">TriplesTemplate</a>? ( <a href="#rQuadsNotTriples">QuadsNotTriples</a> <span class="token">'.'</span>? <a href="#rTriplesTemplate">TriplesTemplate</a>? )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[51]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rQuadsNotTriples" name="rQuadsNotTriples">QuadsNotTriples</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'GRAPH'</span> <a href="#rVarOrIri">VarOrIri</a> <span class="token">'{'</span> <a href="#rTriplesTemplate">TriplesTemplate</a>? <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[52]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rTriplesTemplate" name="rTriplesTemplate">TriplesTemplate</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rTriplesSameSubject">TriplesSameSubject</a> ( <span class="token">'.'</span> <a href="#rTriplesTemplate">TriplesTemplate</a>? )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[53]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGroupGraphPattern" name="rGroupGraphPattern">GroupGraphPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'{'</span> ( <a href="#rSubSelect">SubSelect</a> | <a href="#rGroupGraphPatternSub">GroupGraphPatternSub</a> ) <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[54]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGroupGraphPatternSub" name="rGroupGraphPatternSub">GroupGraphPatternSub</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rTriplesBlock">TriplesBlock</a>? ( <a href="#rGraphPatternNotTriples">GraphPatternNotTriples</a> <span class="token">'.'</span>? <a href="#rTriplesBlock">TriplesBlock</a>? )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[55]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rTriplesBlock" name="rTriplesBlock">TriplesBlock</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rTriplesSameSubjectPath">TriplesSameSubjectPath</a> ( <span class="token">'.'</span> <a href="#rTriplesBlock">TriplesBlock</a>? )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[56]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphPatternNotTriples" name="rGraphPatternNotTriples">GraphPatternNotTriples</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rGroupOrUnionGraphPattern">GroupOrUnionGraphPattern</a> | <a href="#rOptionalGraphPattern">OptionalGraphPattern</a> | <a href="#rMinusGraphPattern">MinusGraphPattern</a> | <a href="#rGraphGraphPattern">GraphGraphPattern</a> | <a href="#rServiceGraphPattern">ServiceGraphPattern</a> | <a href="#rFilter">Filter</a> | <a href="#rBind">Bind</a> | <a href="#rInlineData">InlineData</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[57]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rOptionalGraphPattern" name="rOptionalGraphPattern">OptionalGraphPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'OPTIONAL'</span> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[58]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphGraphPattern" name="rGraphGraphPattern">GraphGraphPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'GRAPH'</span> <a href="#rVarOrIri">VarOrIri</a> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[59]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rServiceGraphPattern" name="rServiceGraphPattern">ServiceGraphPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'SERVICE'</span> <span class="token">'SILENT'</span>? <a href="#rVarOrIri">VarOrIri</a> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[60]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBind" name="rBind">Bind</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'BIND'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">'AS'</span> <a href="#rVar">Var</a> <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[61]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rInlineData" name="rInlineData">InlineData</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'VALUES'</span> <a href="#rDataBlock">DataBlock</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[62]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDataBlock" name="rDataBlock">DataBlock</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rInlineDataOneVar">InlineDataOneVar</a> | <a href="#rInlineDataFull">InlineDataFull</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[63]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rInlineDataOneVar" name="rInlineDataOneVar">InlineDataOneVar</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVar">Var</a> <span class="token">'{'</span> <a href="#rDataBlockValue">DataBlockValue</a>* <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[64]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rInlineDataFull" name="rInlineDataFull">InlineDataFull</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">( <a href="#rNIL">NIL</a> | <span class="token">'('</span> <a href="#rVar">Var</a>* <span class="token">')'</span> ) <span class="token">'{'</span> ( <span class="token">'('</span> <a href="#rDataBlockValue">DataBlockValue</a>* <span class="token">')'</span> | <a href="#rNIL">NIL</a> )* <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[65]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDataBlockValue" name="rDataBlockValue">DataBlockValue</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a> |	<a href="#rRDFLiteral">RDFLiteral</a> |	<a href="#rNumericLiteral">NumericLiteral</a> |	<a href="#rBooleanLiteral">BooleanLiteral</a> |	<span class="token">'UNDEF'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[66]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rMinusGraphPattern" name="rMinusGraphPattern">MinusGraphPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'MINUS'</span> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[67]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGroupOrUnionGraphPattern" name="rGroupOrUnionGraphPattern">GroupOrUnionGraphPattern</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rGroupGraphPattern">GroupGraphPattern</a> ( <span class="token">'UNION'</span> <a href="#rGroupGraphPattern">GroupGraphPattern</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[68]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rFilter" name="rFilter">Filter</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'FILTER'</span> <a href="#rConstraint">Constraint</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[69]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rConstraint" name="rConstraint">Constraint</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rBrackettedExpression">BrackettedExpression</a> | <a href="#rBuiltInCall">BuiltInCall</a> | <a href="#rFunctionCall">FunctionCall</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[70]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rFunctionCall" name="rFunctionCall">FunctionCall</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a> <a href="#rArgList">ArgList</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[71]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rArgList" name="rArgList">ArgList</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rNIL">NIL</a> | <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> ( <span class="token">','</span> <a href="#rExpression">Expression</a> )* <span class="token">')'</span> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[72]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rExpressionList" name="rExpressionList">ExpressionList</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rNIL">NIL</a> | <span class="token">'('</span> <a href="#rExpression">Expression</a> ( <span class="token">','</span> <a href="#rExpression">Expression</a> )* <span class="token">')'</span> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[73]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rConstructTemplate" name="rConstructTemplate">ConstructTemplate</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'{'</span> <a href="#rConstructTriples">ConstructTriples</a>? <span class="token">'}'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[74]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rConstructTriples" name="rConstructTriples">ConstructTriples</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rTriplesSameSubject">TriplesSameSubject</a> ( <span class="token">'.'</span> <a href="#rConstructTriples">ConstructTriples</a>? )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[75]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rTriplesSameSubject" name="rTriplesSameSubject">TriplesSameSubject</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVarOrTerm">VarOrTerm</a> <a href="#rPropertyListNotEmpty">PropertyListNotEmpty</a> |	<a href="#rTriplesNode">TriplesNode</a> <a href="#rPropertyList">PropertyList</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[76]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPropertyList" name="rPropertyList">PropertyList</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPropertyListNotEmpty">PropertyListNotEmpty</a>?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[77]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPropertyListNotEmpty" name="rPropertyListNotEmpty">PropertyListNotEmpty</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVerb">Verb</a> <a href="#rObjectList">ObjectList</a> ( <span class="token">';'</span> ( <a href="#rVerb">Verb</a> <a href="#rObjectList">ObjectList</a> )? )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[78]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVerb" name="rVerb">Verb</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVarOrIri">VarOrIri</a> | <span class="token">'a'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[79]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rObjectList" name="rObjectList">ObjectList</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rObject">Object</a> ( <span class="token">','</span> <a href="#rObject">Object</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[80]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rObject" name="rObject">Object</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rGraphNode">GraphNode</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[81]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rTriplesSameSubjectPath" name="rTriplesSameSubjectPath">TriplesSameSubjectPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVarOrTerm">VarOrTerm</a> <a href="#rPropertyListPathNotEmpty">PropertyListPathNotEmpty</a> |	<a href="#rTriplesNodePath">TriplesNodePath</a> <a href="#rPropertyListPath">PropertyListPath</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[82]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPropertyListPath" name="rPropertyListPath">PropertyListPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPropertyListPathNotEmpty">PropertyListPathNotEmpty</a>?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[83]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPropertyListPathNotEmpty" name="rPropertyListPathNotEmpty">PropertyListPathNotEmpty</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">( <a href="#rVerbPath">VerbPath</a> | <a href="#rVerbSimple">VerbSimple</a> ) <a href="#rObjectListPath">ObjectListPath</a> ( <span class="token">';'</span> ( ( <a href="#rVerbPath">VerbPath</a> | <a href="#rVerbSimple">VerbSimple</a> ) <a href="#rObjectList">ObjectList</a> )? )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[84]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVerbPath" name="rVerbPath">VerbPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPath">Path</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[85]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVerbSimple" name="rVerbSimple">VerbSimple</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVar">Var</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[86]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rObjectListPath" name="rObjectListPath">ObjectListPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rObjectPath">ObjectPath</a> ( <span class="token">','</span> <a href="#rObjectPath">ObjectPath</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[87]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rObjectPath" name="rObjectPath">ObjectPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rGraphNodePath">GraphNodePath</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[88]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPath" name="rPath">Path</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPathAlternative">PathAlternative</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[89]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathAlternative" name="rPathAlternative">PathAlternative</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPathSequence">PathSequence</a> ( <span class="token">'|'</span> <a href="#rPathSequence">PathSequence</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[90]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathSequence" name="rPathSequence">PathSequence</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPathEltOrInverse">PathEltOrInverse</a> ( <span class="token">'/'</span> <a href="#rPathEltOrInverse">PathEltOrInverse</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[91]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathElt" name="rPathElt">PathElt</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPathPrimary">PathPrimary</a> <a href="#rPathMod">PathMod</a>?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[92]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathEltOrInverse" name="rPathEltOrInverse">PathEltOrInverse</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPathElt">PathElt</a> | <span class="token">'^'</span> <a href="#rPathElt">PathElt</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[93]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathMod" name="rPathMod">PathMod</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'?'</span> | <span class="token">'*'</span> | <span class="token">'+'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[94]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathPrimary" name="rPathPrimary">PathPrimary</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a> | <span class="token">'a'</span> | <span class="token">'!'</span> <a href="#rPathNegatedPropertySet">PathNegatedPropertySet</a> | <span class="token">'('</span> <a href="#rPath">Path</a> <span class="token">')'</span> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[95]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathNegatedPropertySet" name="rPathNegatedPropertySet">PathNegatedPropertySet</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPathOneInPropertySet">PathOneInPropertySet</a> | <span class="token">'('</span> ( <a href="#rPathOneInPropertySet">PathOneInPropertySet</a> ( <span class="token">'|'</span> <a href="#rPathOneInPropertySet">PathOneInPropertySet</a> )* )? <span class="token">')'</span> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[96]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPathOneInPropertySet" name="rPathOneInPropertySet">PathOneInPropertySet</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a> | <span class="token">'a'</span> | <span class="token">'^'</span> ( <a href="#riri">iri</a> | <span class="token">'a'</span> ) </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[97]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rInteger" name="rInteger">Integer</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rINTEGER">INTEGER</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[98]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rTriplesNode" name="rTriplesNode">TriplesNode</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rCollection">Collection</a> |	<a href="#rBlankNodePropertyList">BlankNodePropertyList</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[99]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBlankNodePropertyList" name="rBlankNodePropertyList">BlankNodePropertyList</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'['</span> <a href="#rPropertyListNotEmpty">PropertyListNotEmpty</a> <span class="token">']'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[100]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rTriplesNodePath" name="rTriplesNodePath">TriplesNodePath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rCollectionPath">CollectionPath</a> |	<a href="#rBlankNodePropertyListPath">BlankNodePropertyListPath</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[101]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBlankNodePropertyListPath" name="rBlankNodePropertyListPath">BlankNodePropertyListPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'['</span> <a href="#rPropertyListPathNotEmpty">PropertyListPathNotEmpty</a> <span class="token">']'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[102]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rCollection" name="rCollection">Collection</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'('</span> <a href="#rGraphNode">GraphNode</a>+ <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[103]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rCollectionPath" name="rCollectionPath">CollectionPath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'('</span> <a href="#rGraphNodePath">GraphNodePath</a>+ <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[104]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphNode" name="rGraphNode">GraphNode</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVarOrTerm">VarOrTerm</a> |	<a href="#rTriplesNode">TriplesNode</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[105]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphNodePath" name="rGraphNodePath">GraphNodePath</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVarOrTerm">VarOrTerm</a> |	<a href="#rTriplesNodePath">TriplesNodePath</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[106]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVarOrTerm" name="rVarOrTerm">VarOrTerm</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVar">Var</a> | <a href="#rGraphTerm">GraphTerm</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[107]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVarOrIri" name="rVarOrIri">VarOrIri</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVar">Var</a> | <a href="#riri">iri</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[108]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVar" name="rVar">Var</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rVAR1">VAR1</a> | <a href="#rVAR2">VAR2</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[109]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rGraphTerm" name="rGraphTerm">GraphTerm</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a> |	<a href="#rRDFLiteral">RDFLiteral</a> |	<a href="#rNumericLiteral">NumericLiteral</a> |	<a href="#rBooleanLiteral">BooleanLiteral</a> |	<a href="#rBlankNode">BlankNode</a> |	<a href="#rNIL">NIL</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[110]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rExpression" name="rExpression">Expression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rConditionalOrExpression">ConditionalOrExpression</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[111]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rConditionalOrExpression" name="rConditionalOrExpression">ConditionalOrExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rConditionalAndExpression">ConditionalAndExpression</a> ( <span class="token">'||'</span> <a href="#rConditionalAndExpression">ConditionalAndExpression</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[112]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rConditionalAndExpression" name="rConditionalAndExpression">ConditionalAndExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rValueLogical">ValueLogical</a> ( <span class="token">'&amp;&amp;'</span> <a href="#rValueLogical">ValueLogical</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[113]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rValueLogical" name="rValueLogical">ValueLogical</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rRelationalExpression">RelationalExpression</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[114]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rRelationalExpression" name="rRelationalExpression">RelationalExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rNumericExpression">NumericExpression</a> ( <span class="token">'='</span> <a href="#rNumericExpression">NumericExpression</a> | <span class="token">'!='</span> <a href="#rNumericExpression">NumericExpression</a> | <span class="token">'&lt;'</span> <a href="#rNumericExpression">NumericExpression</a> | <span class="token">'&gt;'</span> <a href="#rNumericExpression">NumericExpression</a> | <span class="token">'&lt;='</span> <a href="#rNumericExpression">NumericExpression</a> | <span class="token">'&gt;='</span> <a href="#rNumericExpression">NumericExpression</a> | <span class="token">'IN'</span> <a href="#rExpressionList">ExpressionList</a> | <span class="token">'NOT'</span> <span class="token">'IN'</span> <a href="#rExpressionList">ExpressionList</a> )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[115]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNumericExpression" name="rNumericExpression">NumericExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rAdditiveExpression">AdditiveExpression</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[116]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rAdditiveExpression" name="rAdditiveExpression">AdditiveExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rMultiplicativeExpression">MultiplicativeExpression</a> ( <span class="token">'+'</span> <a href="#rMultiplicativeExpression">MultiplicativeExpression</a> | <span class="token">'-'</span> <a href="#rMultiplicativeExpression">MultiplicativeExpression</a> | ( <a href="#rNumericLiteralPositive">NumericLiteralPositive</a> | <a href="#rNumericLiteralNegative">NumericLiteralNegative</a> ) ( ( <span class="token">'*'</span> <a href="#rUnaryExpression">UnaryExpression</a> ) | ( <span class="token">'/'</span> <a href="#rUnaryExpression">UnaryExpression</a> ) )* )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[117]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rMultiplicativeExpression" name="rMultiplicativeExpression">MultiplicativeExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rUnaryExpression">UnaryExpression</a> ( <span class="token">'*'</span> <a href="#rUnaryExpression">UnaryExpression</a> | <span class="token">'/'</span> <a href="#rUnaryExpression">UnaryExpression</a> )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[118]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rUnaryExpression" name="rUnaryExpression">UnaryExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">&nbsp;&nbsp;<span class="token">'!'</span> <a href="#rPrimaryExpression">PrimaryExpression</a> <br/>|	<span class="token">'+'</span> <a href="#rPrimaryExpression">PrimaryExpression</a> <br/>|	<span class="token">'-'</span> <a href="#rPrimaryExpression">PrimaryExpression</a> <br/>|	<a href="#rPrimaryExpression">PrimaryExpression</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[119]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPrimaryExpression" name="rPrimaryExpression">PrimaryExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rBrackettedExpression">BrackettedExpression</a> | <a href="#rBuiltInCall">BuiltInCall</a> | <a href="#ririOrFunction">iriOrFunction</a> | <a href="#rRDFLiteral">RDFLiteral</a> | <a href="#rNumericLiteral">NumericLiteral</a> | <a href="#rBooleanLiteral">BooleanLiteral</a> | <a href="#rVar">Var</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[120]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBrackettedExpression" name="rBrackettedExpression">BrackettedExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[121]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBuiltInCall" name="rBuiltInCall">BuiltInCall</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">&nbsp;&nbsp;<a href="#rAggregate">Aggregate</a> <br/>|	<span class="token">'STR'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'LANG'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'LANGMATCHES'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'DATATYPE'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'BOUND'</span> <span class="token">'('</span> <a href="#rVar">Var</a> <span class="token">')'</span> <br/>|	<span class="token">'IRI'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'URI'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'BNODE'</span> ( <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> | <a href="#rNIL">NIL</a> ) <br/>|	<span class="token">'RAND'</span> <a href="#rNIL">NIL</a> <br/>|	<span class="token">'ABS'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'CEIL'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'FLOOR'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'ROUND'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'CONCAT'</span> <a href="#rExpressionList">ExpressionList</a> <br/>|	<a href="#rSubstringExpression">SubstringExpression</a> <br/>|	<span class="token">'STRLEN'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<a href="#rStrReplaceExpression">StrReplaceExpression</a> <br/>|	<span class="token">'UCASE'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'LCASE'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'ENCODE_FOR_URI'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'CONTAINS'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'STRSTARTS'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'STRENDS'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'STRBEFORE'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'STRAFTER'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'YEAR'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'MONTH'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'DAY'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'HOURS'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'MINUTES'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'SECONDS'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'TIMEZONE'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'TZ'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'NOW'</span> <a href="#rNIL">NIL</a> <br/>|	<span class="token">'UUID'</span> <a href="#rNIL">NIL</a> <br/>|	<span class="token">'STRUUID'</span> <a href="#rNIL">NIL</a> <br/>|	<span class="token">'MD5'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'SHA1'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'SHA256'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'SHA384'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'SHA512'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'COALESCE'</span> <a href="#rExpressionList">ExpressionList</a> <br/>|	<span class="token">'IF'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'STRLANG'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'STRDT'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'sameTerm'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'isIRI'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'isURI'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'isBLANK'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'isLITERAL'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<span class="token">'isNUMERIC'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>|	<a href="#rRegexExpression">RegexExpression</a> <br/>|	<a href="#rExistsFunc">ExistsFunc</a> <br/>|	<a href="#rNotExistsFunc">NotExistsFunc</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[122]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rRegexExpression" name="rRegexExpression">RegexExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'REGEX'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> ( <span class="token">','</span> <a href="#rExpression">Expression</a> )? <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[123]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSubstringExpression" name="rSubstringExpression">SubstringExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'SUBSTR'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> ( <span class="token">','</span> <a href="#rExpression">Expression</a> )? <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[124]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rStrReplaceExpression" name="rStrReplaceExpression">StrReplaceExpression</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'REPLACE'</span> <span class="token">'('</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> <span class="token">','</span> <a href="#rExpression">Expression</a> ( <span class="token">','</span> <a href="#rExpression">Expression</a> )? <span class="token">')'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[125]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rExistsFunc" name="rExistsFunc">ExistsFunc</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'EXISTS'</span> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[126]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNotExistsFunc" name="rNotExistsFunc">NotExistsFunc</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'NOT'</span> <span class="token">'EXISTS'</span> <a href="#rGroupGraphPattern">GroupGraphPattern</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[127]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rAggregate" name="rAggregate">Aggregate</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">&nbsp;&nbsp;<span class="token">'COUNT'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? ( <span class="token">'*'</span> | <a href="#rExpression">Expression</a> ) <span class="token">')'</span> <br/>| <span class="token">'SUM'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>| <span class="token">'MIN'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>| <span class="token">'MAX'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>| <span class="token">'AVG'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>| <span class="token">'SAMPLE'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> <span class="token">')'</span> <br/>| <span class="token">'GROUP_CONCAT'</span> <span class="token">'('</span> <span class="token">'DISTINCT'</span>? <a href="#rExpression">Expression</a> ( <span class="token">';'</span> <span class="token">'SEPARATOR'</span> <span class="token">'='</span> <a href="#rString">String</a> )? <span class="token">')'</span> </code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[128]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="ririOrFunction" name="ririOrFunction">iriOrFunction</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#riri">iri</a> <a href="#rArgList">ArgList</a>?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[129]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rRDFLiteral" name="rRDFLiteral">RDFLiteral</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rString">String</a> ( <a href="#rLANGTAG">LANGTAG</a> | ( <span class="token">'^^'</span> <a href="#riri">iri</a> ) )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[130]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNumericLiteral" name="rNumericLiteral">NumericLiteral</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rNumericLiteralUnsigned">NumericLiteralUnsigned</a> | <a href="#rNumericLiteralPositive">NumericLiteralPositive</a> | <a href="#rNumericLiteralNegative">NumericLiteralNegative</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[131]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNumericLiteralUnsigned" name="rNumericLiteralUnsigned">NumericLiteralUnsigned</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rINTEGER">INTEGER</a> |	<a href="#rDECIMAL">DECIMAL</a> |	<a href="#rDOUBLE">DOUBLE</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[132]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNumericLiteralPositive" name="rNumericLiteralPositive">NumericLiteralPositive</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rINTEGER_POSITIVE">INTEGER_POSITIVE</a> |	<a href="#rDECIMAL_POSITIVE">DECIMAL_POSITIVE</a> |	<a href="#rDOUBLE_POSITIVE">DOUBLE_POSITIVE</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[133]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNumericLiteralNegative" name="rNumericLiteralNegative">NumericLiteralNegative</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rINTEGER_NEGATIVE">INTEGER_NEGATIVE</a> |	<a href="#rDECIMAL_NEGATIVE">DECIMAL_NEGATIVE</a> |	<a href="#rDOUBLE_NEGATIVE">DOUBLE_NEGATIVE</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[134]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBooleanLiteral" name="rBooleanLiteral">BooleanLiteral</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'true'</span> |	<span class="token">'false'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[135]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rString" name="rString">String</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rSTRING_LITERAL1">STRING_LITERAL1</a> | <a href="#rSTRING_LITERAL2">STRING_LITERAL2</a> | <a href="#rSTRING_LITERAL_LONG1">STRING_LITERAL_LONG1</a> | <a href="#rSTRING_LITERAL_LONG2">STRING_LITERAL_LONG2</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[136]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="riri" name="riri">iri</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rIRIREF">IRIREF</a> |	<a href="#rPrefixedName">PrefixedName</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[137]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPrefixedName" name="rPrefixedName">PrefixedName</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPNAME_LN">PNAME_LN</a> | <a href="#rPNAME_NS">PNAME_NS</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[138]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBlankNode" name="rBlankNode">BlankNode</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rBLANK_NODE_LABEL">BLANK_NODE_LABEL</a> |	<a href="#rANON">ANON</a></code></td>
</tr>
  </tbody></table>
</div>
<p>Productions for terminals:</p>
<div class="grammarTable">
  <table><tbody>

<tr valign="baseline">
  <td><code class="gRuleLabel">[139]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rIRIREF" name="rIRIREF">IRIREF</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'&lt;' ([^&lt;&gt;"{}|^`\]-[#x00-#x20])* '&gt;'</span></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[140]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPNAME_NS" name="rPNAME_NS">PNAME_NS</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPN_PREFIX">PN_PREFIX</a>? ':'</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[141]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPNAME_LN" name="rPNAME_LN">PNAME_LN</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPNAME_NS">PNAME_NS</a> <a href="#rPN_LOCAL">PN_LOCAL</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[142]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rBLANK_NODE_LABEL" name="rBLANK_NODE_LABEL">BLANK_NODE_LABEL</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'_:' ( <a href="#rPN_CHARS_U">PN_CHARS_U</a> | [0-9] ) ((<a href="#rPN_CHARS">PN_CHARS</a>|'.')* <a href="#rPN_CHARS">PN_CHARS</a>)?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[143]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVAR1" name="rVAR1">VAR1</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'?' <a href="#rVARNAME">VARNAME</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[144]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVAR2" name="rVAR2">VAR2</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'$' <a href="#rVARNAME">VARNAME</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[145]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rLANGTAG" name="rLANGTAG">LANGTAG</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[146]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rINTEGER" name="rINTEGER">INTEGER</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">[0-9]+</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[147]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDECIMAL" name="rDECIMAL">DECIMAL</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">[0-9]* '.' [0-9]+</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[148]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDOUBLE" name="rDOUBLE">DOUBLE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">[0-9]+ '.' [0-9]* <a href="#rEXPONENT">EXPONENT</a> | '.' ([0-9])+ <a href="#rEXPONENT">EXPONENT</a> | ([0-9])+ <a href="#rEXPONENT">EXPONENT</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[149]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rINTEGER_POSITIVE" name="rINTEGER_POSITIVE">INTEGER_POSITIVE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'+'</span> <a href="#rINTEGER">INTEGER</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[150]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDECIMAL_POSITIVE" name="rDECIMAL_POSITIVE">DECIMAL_POSITIVE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'+'</span> <a href="#rDECIMAL">DECIMAL</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[151]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDOUBLE_POSITIVE" name="rDOUBLE_POSITIVE">DOUBLE_POSITIVE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'+'</span> <a href="#rDOUBLE">DOUBLE</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[152]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rINTEGER_NEGATIVE" name="rINTEGER_NEGATIVE">INTEGER_NEGATIVE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'-'</span> <a href="#rINTEGER">INTEGER</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[153]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDECIMAL_NEGATIVE" name="rDECIMAL_NEGATIVE">DECIMAL_NEGATIVE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'-'</span> <a href="#rDECIMAL">DECIMAL</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[154]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rDOUBLE_NEGATIVE" name="rDOUBLE_NEGATIVE">DOUBLE_NEGATIVE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><span class="token">'-'</span> <a href="#rDOUBLE">DOUBLE</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[155]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rEXPONENT" name="rEXPONENT">EXPONENT</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">[eE] [+-]? [0-9]+</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[156]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSTRING_LITERAL1" name="rSTRING_LITERAL1">STRING_LITERAL1</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">"'" ( ([^#x27#x5C#xA#xD]) | <a href="#rECHAR">ECHAR</a> )* "'"</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[157]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSTRING_LITERAL2" name="rSTRING_LITERAL2">STRING_LITERAL2</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'"' ( ([^#x22#x5C#xA#xD]) | <a href="#rECHAR">ECHAR</a> )* '"'</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[158]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSTRING_LITERAL_LONG1" name="rSTRING_LITERAL_LONG1">STRING_LITERAL_LONG1</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">"'''" ( ( "'" | "''" )? ( [^'\] | <a href="#rECHAR">ECHAR</a> ) )* "'''"</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[159]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rSTRING_LITERAL_LONG2" name="rSTRING_LITERAL_LONG2">STRING_LITERAL_LONG2</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'"""' ( ( '"' | '""' )? ( [^"\] | <a href="#rECHAR">ECHAR</a> ) )* '"""'</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[160]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rECHAR" name="rECHAR">ECHAR</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'\' [tbnrf\"']</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[161]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rNIL" name="rNIL">NIL</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'(' <a href="#rWS">WS</a>* ')'</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[162]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rWS" name="rWS">WS</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">#x20 | #x9 | #xD | #xA</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[163]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rANON" name="rANON">ANON</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'['  <a href="#rWS">WS</a>* ']'</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[164]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPN_CHARS_BASE" name="rPN_CHARS_BASE">PN_CHARS_BASE</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">[A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[165]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPN_CHARS_U" name="rPN_CHARS_U">PN_CHARS_U</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPN_CHARS_BASE">PN_CHARS_BASE</a> | '_'</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[166]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rVARNAME" name="rVARNAME">VARNAME</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">( <a href="#rPN_CHARS_U">PN_CHARS_U</a>  | [0-9] ) ( <a href="#rPN_CHARS_U">PN_CHARS_U</a> | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[167]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPN_CHARS" name="rPN_CHARS">PN_CHARS</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPN_CHARS_U">PN_CHARS_U</a> | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[168]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPN_PREFIX" name="rPN_PREFIX">PN_PREFIX</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPN_CHARS_BASE">PN_CHARS_BASE</a> ((<a href="#rPN_CHARS">PN_CHARS</a>|'.')* <a href="#rPN_CHARS">PN_CHARS</a>)?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[169]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPN_LOCAL" name="rPN_LOCAL">PN_LOCAL</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">(<a href="#rPN_CHARS_U">PN_CHARS_U</a> | ':' | [0-9] | <a href="#rPLX">PLX</a> ) ((<a href="#rPN_CHARS">PN_CHARS</a> | '.' | ':' | <a href="#rPLX">PLX</a>)* (<a href="#rPN_CHARS">PN_CHARS</a> | ':' | <a href="#rPLX">PLX</a>) )?</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[170]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPLX" name="rPLX">PLX</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody"><a href="#rPERCENT">PERCENT</a> | <a href="#rPN_LOCAL_ESC">PN_LOCAL_ESC</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[171]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPERCENT" name="rPERCENT">PERCENT</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'%' <a href="#rHEX">HEX</a> <a href="#rHEX">HEX</a></code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[172]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rHEX" name="rHEX">HEX</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">[0-9] | [A-F] | [a-f]</code></td>
</tr>

<tr valign="baseline">
  <td><code class="gRuleLabel">[173]&nbsp;&nbsp;</code></td>
  <td><code class="gRuleHead"><a id="rPN_LOCAL_ESC" name="rPN_LOCAL_ESC">PN_LOCAL_ESC</a></code></td>
  <td>&nbsp;&nbsp;::=&nbsp;&nbsp;</td>
  <td><code class="gRuleBody">'\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&amp;' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%' )</code></td>
</tr>
  </tbody></table>
</div>
<!-- /MARKER html GRAMMAR -->

        </div2>
      </div1>
      <div1 id="conformance">
	<head>Conformance</head>
	<p>See Section <a href="#grammar">19 SPARQL Grammar</a> regarding conformance of
	<a href="#defn_SPARQLQueryString">SPARQL Query strings</a>, and section
	<a href="#QueryForms">16 Query Forms</a> for conformance of query results. 
	See section <a href="#mediaType">22. Internet Media Type</a> for conformance to 
	the application/sparql-query media type.</p>
	<p>This specification is intended for use in conjunction with the SPARQL 1.1 Protocol 
	[<a href="#SPROT">SPROT</a>], 
	the SPARQL Query Results XML Format [<a href="#SPARQL-XML-RESULTS">SPARQL XML Results</a>],
	the SPARQL 1.1 Query Results JSON Format [<a href="#SPARQL-JSON-RESULTS">SPARQL-JSON-Results</a>] and
	the SPARQL 1.1 Query Results CSV and TSV Formats [<a href="#SPARQL-CSV-TSV-RESULTS">SPARQL CSV and TSV Results</a>].
	See those specifications for their conformance criteria.</p>
	
	<p>Note that the SPARQL protocol describes a means for conveying SPARQL queries to an SPARQL query processing service and returning the query results to the entity that requested them.</p>

    </div1>

    <div1 id="security">
      <head>Security Considerations (Informative)</head>
<p>SPARQL queries using FROM, FROM NAMED, or GRAPH may cause the specified URI to 
be dereferenced. This may cause additional use of network, disk or CPU resources 
along with associated secondary issues such as denial of service. The security issues 
of <a class="norm" href="http://www.ietf.org/rfc/rfc3986.txt">Uniform Resource Identifier 
(URI): Generic Syntax</a> [<a href="#rfc3986">RFC3986</a>] Section 7 should be considered. 
In addition, the contents of <code>file:</code> URIs can in some cases be accessed, 
processed and returned as results, providing unintended access to local resources.</p>
<p>SPARQL requests may cause additional requests to be issued from the SPARQL endpoint, such as FROM NAMED. The endpoint is potentially within an organisations firewall or DMZ, and so such queries may be a source of indirection attacks.</p>
<p>The SPARQL language permits extensions, which will have their own security implications.</p>
<p>Multiple IRIs may have the same appearance. Characters in different scripts may 
look similar (a Cyrillic &quot;&#1086;&quot; may appear similar to a Latin &quot;o&quot;). A character followed 
by combining characters may have the same visual representation as another character 
(LATIN SMALL LETTER E followed by COMBINING ACUTE ACCENT has the same visual representation 
as LATIN SMALL LETTER E WITH ACUTE).
<!-- (<code>foo:resum&#40751;code> and <code>f&#1086;&#1086;:resume&#769;</code>)-->
Users of SPARQL must take care to construct queries with IRIs that match the IRIs 
in the data. Further information about matching of similar characters can be found 
in <a class="inform" href="http://www.unicode.org/reports/tr36/">Unicode Security 
Considerations</a> [<a href="#UNISEC">UNISEC</a>] and
<a class="norm" href="http://www.ietf.org/rfc/rfc3987.txt">Internationalized Resource 
Identifiers (IRIs)</a> [<a href="#rfc3987">RFC3987</a>] Section 8.</p>
    </div1>

    <div1 id="mediaType">
      <head>Internet Media Type, File Extension and Macintosh File Type</head>

      <p>The Internet Media Type / MIME Type for the SPARQL Query Language is &quot;<tt>application/sparql-query</tt>&quot;.</p>
      <p>It is recommended that sparql query files have the extension &quot;.rq&quot; (lowercase) 
      on all platforms.</p>
      <p>It is recommended that sparql query files stored on Macintosh HFS file systems 
      be given a file type of &quot;TEXT&quot;.</p>

      <div class="mime">

	<dl>
	  <dt>Type name:</dt>
	  <dd>application</dd>
	  <dt>Subtype name:</dt>
	  <dd>sparql-query</dd>
	  <dt>Required parameters:</dt>
	  <dd>None</dd>
	  <dt>Optional parameters:</dt>
	  <dd>None</dd>
	  <dt>Encoding considerations:</dt>
	  <dd>The syntax of the SPARQL Query Language is expressed over code points in Unicode 
	  [<a href="#UNICODE">UNICODE</a>]. The encoding is always UTF-8 [<a href="#rfc3629">RFC3629</a>].</dd>
	  <dd>Unicode code points may also be expressed using an \uXXXX (U+0 to U+FFFF) 
	  or \UXXXXXXXX syntax (for U+10000 onwards) where X is a hexadecimal digit [0-9A-F]</dd>
	  <dt>Security considerations:</dt>
	  <dd>See SPARQL Query appendix C, <a href="#security">Security Considerations</a> 
	  as well as <a class="norm" href="http://www.ietf.org/rfc/rfc3629.txt">RFC 3629</a> 
	  [<a href="#rfc3629">RFC3629</a>] section 7, Security Considerations.</dd>
	  <dt>Interoperability considerations:</dt>
	  <dd>There are no known interoperability issues.</dd>
	  <dt>Published specification:</dt>
	  <dd>This specification.</dd>
	  <dt>Applications which use this media type:</dt>
	  <dd>No known applications currently use this media type.</dd>
	  <dt>Additional information:</dt>
	  <dt>Magic number(s):</dt>
	  <dd>A SPARQL query may have the string &#39;PREFIX&#39; (case independent) near the beginning 
	  of the document.</dd>
	  <dt>File extension(s):</dt>
	  <dd>&quot;.rq&quot;</dd>
	  <dt>Base URI:</dt>
	  <dd>The SPARQL &#39;BASE &lt;IRIref&gt;&#39; term can change the current base URI for relative 
	  IRIrefs in the query language that are used sequentially later in the document.</dd>
	  <dt>Macintosh file type code(s):</dt>
	  <dd>&quot;TEXT&quot;</dd>
	  <dt>Person &amp; email address to contact for further information:</dt>
	  <dd>public-rdf-dawg-comments@w3.org</dd>
	  <dt>Intended usage:</dt>
	  <dd>COMMON</dd>
	  <dt>Restrictions on usage:</dt>
	  <dd>None</dd>
	  <dt>Author/Change controller:</dt>
	  <dd>The SPARQL 1.1 specification is a work product of the World Wide Web Consortium&#39;s 
	  SPARQL Working Group. The W3C has change control over these specifications.</dd>
	</dl>
      </div>
    </div1>
  </body>
  <back>
    <!-- &Biblio; -->
    <div1 id="sec-bibliography">
      <head>References</head>
      <div2 id="sec-normative-refs">
        <head>Normative References</head>

  <dl class="bib">
    <dt><a name="CHARMOD" id="CHARMOD">[CHARMOD]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2005/REC-charmod-20050215/">Character
      Model for the World Wide Web 1.0: Fundamentals</a>,
      R. Ishida, F. Yergeau, M. J. D&udotdot;rst, M. Wolf, T. Texin,
      Editors, W3C Recommendation, 15 February 2005,
      http://www.w3.org/TR/2005/REC-charmod-20050215/ . 
    <a href="http://www.w3.org/TR/charmod/" title="Latest version of Character Model for the World Wide Web 1.0: Fundamentals">Latest version</a> available at http://www.w3.org/TR/charmod/
      .</dd>

    <dt><a name="CONCEPTS" id="CONCEPTS">[CONCEPTS]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/">Resource
      Description Framework (RDF): Concepts and Abstract
      Syntax</a>, G. Klyne, J. J. Carroll, Editors, W3C
      Recommendation, 10 February 2004,
      http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/ .
        <a href="http://www.w3.org/TR/rdf-concepts/" title="Latest version of Resource Description Framework (RDF): Concepts and Abstract Syntax">Latest version</a> available at
      http://www.w3.org/TR/rdf-concepts/ .</dd>
    <dt><a name="FUNCOP" id="FUNCOP">[FUNCOP]</a></dt>
    <dd>

    <a href="http://www.w3.org/TR/2007/REC-xpath-functions-20070123/">XQuery
      1.0 and XPath 2.0 Functions and Operators</a>, J.
      Melton, A. Malhotra, N. Walsh, Editors, W3C Recommendation,
      23 January 2007,
      http://www.w3.org/TR/2007/REC-xpath-functions-20070123/ .
        <a href="http://www.w3.org/TR/xpath-functions/" title="Latest version of XQuery 1.0 and XPath 2.0 Functions and Operators">Latest version</a> available at
      http://www.w3.org/TR/xpath-functions/ .</dd>
    <dt><a id="RDF-MT" name="RDF-MT">[RDF-MT]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2004/REC-rdf-mt-20040210/">RDF
      Semantics</a>, P. Hayes, Editor, W3C Recommendation,
      10 February 2004,
      http://www.w3.org/TR/2004/REC-rdf-mt-20040210/ . 
    <a title="Latest version of RDF Semantics" href="http://www.w3.org/TR/rdf-mt/">Latest version</a> available
      at http://www.w3.org/TR/rdf-mt/ .</dd>

    <dt><a name="rfc3629" id="rfc3629">[RFC3629]</a></dt>
    <dd>RFC 3629 
    <a href="http://www.ietf.org/rfc/rfc3629.txt">UTF-8, a transformation
      format of ISO 10646</a>, F. Yergeau November 2003</dd>

  <dt><a name="rfc4647" id="rfc4647">[RFC4647]</a></dt>
  <dd>RFC 4647 <a href="http://www.ietf.org/rfc/rfc4647.txt">Matching of Language Tags</a>, A. Phillips, M. Davis September 2006</dd>

    <dt><a name="rfc3986" id="rfc3986">[RFC3986]</a></dt>
    <dd>RFC 3986 
    <a href="http://www.ietf.org/rfc/rfc3986.txt">Uniform Resource
      Identifier (URI): Generic Syntax</a>, T. Berners-Lee,
      R. Fielding, L. Masinter January 2005</dd>
    <dt><a name="rfc3987" id="rfc3987">[RFC3987]</a></dt>
    <dd>RFC 3987 <a href="http://www.ietf.org/rfc/rfc3987.txt">Internationalized Resource Identifiers (IRIs)</a>, 
      M. D&udotdot;rst , M. Suignard</dd>

    <dt><a name="UNICODE" id="UNICODE">[UNICODE]</a></dt>
    <dd>The Unicode Standard, Version 4. ISBN
      0-321-18578-1, as updated from time to time by the
      publication of new versions. The latest version of Unicode
      and additional information on versions of the standard and of
      the Unicode Character Database is available at 
    <a href="http://www.unicode.org/unicode/standard/versions/">http://www.unicode.org/unicode/standard/versions/</a>.</dd>
    <dt><a name="XML11" id="XML11">[XML11]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2004/REC-xml11-20040204/">Extensible
      Markup Language (XML) 1.1</a>, J. Cowan, J. Paoli, E.
      Maler, C. M. Sperberg-McQueen, F. Yergeau, T. Bray, Editors,
      W3C Recommendation, 4 February 2004,
      http://www.w3.org/TR/2004/REC-xml11-20040204/ . 
    <a href="http://www.w3.org/TR/xml11/" title="Latest version of Extensible Markup Language (XML) 1.1">Latest
      version</a> available at http://www.w3.org/TR/xml11/ .</dd>

    <dt><a name="XPATH20" id="XPATH20">[XPATH20]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2007/REC-xpath20-20070123/">XML Path
      Language (XPath) 2.0</a>, A. Berglund, S. Boag, D. Chamberlin, M. F. Fern&aacute;ndez, M. Kay, J. Robie, J. Sim&eacute;on,
      Editors, W3C Recommendation, 23 January 2007,
      http://www.w3.org/TR/2007/REC-xpath20-20070123/ . 
    <a href="http://www.w3.org/TR/xpath20/" title="Latest version of XML Path Language (XPath) 2.0">Latest
      version</a> available at http://www.w3.org/TR/xpath20/ .</dd>
    <dt><a name="XQUERY" id="XQUERY">[XQUERY]</a></dt>
    <dd>

    <a href="http://www.w3.org/TR/2007/REC-xquery-20070123/">XQuery 1.0:
      An XML Query Language</a>, S. Boag, D. Chamberlin, M. F. Fern&aacute;ndez, D. Florescu, J. Robie, J. Sim&eacute;on, Editors, W3C Recommendation, 23
      January 2007, http://www.w3.org/TR/2007/REC-xquery-20070123/.
        <a href="http://www.w3.org/TR/xquery/" title="Latest version of XQuery 1.0: An XML Query Language">Latest
      version</a> available at http://www.w3.org/TR/xquery/ . 
      <!-- odd... bib generator knows it as http://www.w3.org/TR/xquery
      but the title page says http://www.w3.org/TR/xquery/ --></dd>
    <dt><a name="XSDT" id="XSDT">[XSDT]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/">XML
      Schema Part 2: Datatypes Second Edition</a>, P. V.
      Biron, A. Malhotra, Editors, W3C Recommendation, 28 October
      2004, http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/ .
      <a href="http://www.w3.org/TR/xmlschema-2/">Latest version</a> available at http://www.w3.org/TR/xmlschema-2/.<br/>
      Updated 2012 by <a href="http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/">W3C
      XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes</a>. 
      (<a href="http://www.w3.org/TR/xmlschema11-2/">Latest version</a> available at http://www.w3.org/TR/xmlschema11-2/).
</dd>


  <dt><a name="BCP47" id="BCP47">[BCP47]</a></dt>
  <dd><a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">Best Common Practice 47</a>, P. V. Biron, A. Malhotra, Editors, W3C Recommendation, 28 October 2004, http://www.rfc-editor.org/rfc/bcp/bcp47.txt .</dd>
  </dl>

      </div2>
      <div2 id="sec-non-normative-refs">
        <head>Other References</head>
  <dl class="bib">
    <dt><a name="CBD" id="CBD">[CBD]</a></dt>

    <dd><a href="http://www.w3.org/Submission/CBD/">CBD - Concise 
        Bounded Description</a>, Patrick Stickler, Nokia, W3C Member 
        Submission, 3 June 2005.</dd>
    <dt><a name="DC" id="DC">[DC]</a></dt>
    <dd>
    <a href="http://www.dublincore.org/documents/dcmes-xml/">Expressing
      Simple Dublin Core in RDF/XML</a>
    <a href="http://dublincore.org/">Dublin Core Dublin Core Metadata
      Initiative</a> Recommendation 2002-07-31.</dd><!--
    <dt><a name="namespace" id="namespace">[NAMESPACE]</a></dt>
    <dd>
      <a
      href="http://www.w3.org/TR/2004/REC-xml-names11-20040204">Namespaces
      in XML 1.1</a> , T. Bray, A. Layman, D. Hollander,
      R. Tobin, Editors, W3C Recommendation, 4 February 2004,
      http://www.w3.org/TR/2004/REC-xml-names11-20040204 . <a
      href="http://www.w3.org/TR/xml-names11" title="Latest version
      of Namespaces in XML 1.1">Latest version</a> available at
      http://www.w3.org/TR/xml-names11/ .
    </dd>
-->

        <dt><a id="multiset" name="multiset">[Multiset]</a></dt>
        <dd>
	<a href="http://en.wikipedia.org/w/index.php?title=Multiset&amp;oldid=163605900">Multiset</a>, Wikipedia, The Free Encyclopedia.
	Article as given on October 25, 2007 at http://en.wikipedia.org/w/index.php?title=Multiset&amp;oldid=163605900. The 
	<a href="http://en.wikipedia.org/wiki/Multiset">latest version</a> of this article is at http://en.wikipedia.org/wiki/Multiset.
	</dd>

	<!-- Entailment Regime support is in a separate document.
	<dt><a id="OWL2_Direct_Semantics" name="OWL2_Direct_Semantics">[OWL2-Direct-Semantics]</a></dt>
	<dd>
	<a href="http://www.w3.org/TR/2009/REC-owl2-direct-semantics-20091027/">
	OWL 2 Web Ontology Language Direct Semantics</a>, 
	Boris Motik, Peter F. Patel-Schneider, Bernardo Cuenca Grau,	
	Editors, W3C Recommendation, 27 October 2009
	http://www.w3.org/TR/2009/REC-owl2-direct-semantics-20091027/.
	<a href="http://www.w3.org/TR/owl2-direct-semantics/">Latest
	version</a> at 
	<a href="http://www.w3.org/TR/owl2-direct-semantics/">http://www.w3.org/TR//owl2-direct-semantics/</a>.</dd>

	<dt><a id="OWL2_RDF_Semantics" name="OWL2_RDF_Semantics">[OWL2-RDF-Semantics]</a></dt>
	<dd>
	<a href="http://www.w3.org/TR/2009/REC-owl2-rdf-based-semantics-20091027/">
	OWL 2 Web Ontology Language: RDF-Based Semantics</a>
	Michael Schneider, editor. W3C Recommendation, 27 October 2009, 
	http://www.w3.org/TR/2009/REC-owl2-rdf-based-semantics-20091027/. 
	<a href="http://www.w3.org/TR/owl2-rdf-based-semantics/">Latest
	version</a> at 
	<a href="http://www.w3.org/TR/owl2-rdf-based-semantics/">http://www.w3.org/TR/owl2-rdf-based-semantics/</a>.</dd>

  <dt><a id="rdfschema" name="rdfschema">[RDFS]</a></dt>
  <dd>
    <a href="http://www.w3.org/TR/2004/REC-rdf-schema-20040210/">RDF Vocabulary Description Language 1.0: RDF Schema</a>,
    Dan Brickley, R.V. Guha, Editors,
    W3C Recommendation,
    10 February 2004,
    http://www.w3.org/TR/2004/REC-rdf-schema-20040210/ .
    <a href="http://www.w3.org/TR/rdf-schema/">Latest version</a> at <a href="http://www.w3.org/TR/rdf-schema/">http://www.w3.org/TR/rdf-schema/</a> .
  </dd>
	-->

    <dt><a name="SPARQL-XML-RESULTS" id="SPARQL-XML-RESULTS">[SPARQL XML Results]</a></dt>
    <dd>@@ref-rdf-sparql-XMLres</dd>

    <dt><a name="SPARQL-JSON-RESULTS" id="SPARQL-JSON-RESULTS">[SPARQL JSON Results]</a></dt>
    <dd>@@ref-results-json</dd>

    <dt><a name="SPARQL-CSV-TSV-RESULTS" id="SPARQL-CSV-TSV-RESULTS">[SPARQL CSV and TSV Result]</a></dt>
    <dd>@@ref-results-csv-tsv</dd>

    <dt><a id="SPROT" name="SPROT">[SPROT]</a></dt>
      <dd>@@ref-protocol</dd>

    <dt><a name="TURTLE" id="TURTLE">[TURTLE]</a></dt>
    <dd>@@ref-turtle</dd>

    <dt><a name="UCNR" id="UCNR">[UCNR]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2005/WD-rdf-dawg-uc-20050325/">RDF Data
      Access Use Cases and Requirements</a>, K. Clark,
      Editor, W3C Working Draft, 25 March 2005,
      http://www.w3.org/TR/2005/WD-rdf-dawg-uc-20050325/ . 
    <a href="http://www.w3.org/TR/rdf-dawg-uc/" title="Latest version of RDF Data Access Use Cases and Requirements">Latest version</a> available at
      http://www.w3.org/TR/rdf-dawg-uc/ .
    </dd>

    <dt><a name="UCNR2" id="UCNR2">[UCNR2]</a></dt>
    <dd>
    <a href="http://www.w3.org/TR/2009/WD-sparql-features-20090702/">SPARQL New Features and Rationale</a>, 
        Kjetil Kjernsmo,  Alexandre Passant, Editors,
	W3C Working Draft, 2 July 2009,
	http://www.w3.org/TR/2009/WD-sparql-features-20090702/ .
    <a href="http://www.w3.org/TR/sparql-features/" title="Latest version of SPARQL New Features and Rationale">Latest version</a> available at http://www.w3.org/TR/sparql-features/ .
    </dd>

    <dt><a name="UNISEC" id="UNISEC">[UNISEC]</a></dt>
    <dd><a href="http://www.unicode.org/reports/tr36/">Unicode Security
      Considerations</a>, Mark Davis, Michel Suignard</dd>

  <dt><a id="VCARD" name="VCARD">[VCARD]</a></dt>
  <dd>
    <a href="http://www.w3.org/TR/2001/NOTE-vcard-rdf-20010222/">Representing vCard Objects in RDF/XML</a>,
    Renato Iannella,
    W3C Note,
    22 February 2001,
    http://www.w3.org/TR/2001/NOTE-vcard-rdf-20010222/ .
    <a href="http://www.w3.org/TR/vcard-rdf">Latest version</a> is available at <tt>http://www.w3.org/TR/vcard-rdf</tt> .
  </dd>

  <dt><a name="WEBARCH" id="WEBARCH">[WEBARCH]</a></dt>

  <dd>
    <a href="http://www.w3.org/TR/2004/REC-webarch-20041215/">Architecture of the World Wide Web, Volume One</a>, 
    I. Jacobs, N. Walsh, Editors,
    W3C Recommendation,
    15 December 2004,
    http://www.w3.org/TR/2004/REC-webarch-20041215/ .
    <a href="http://www.w3.org/TR/webarch/">Latest version</a> is available at <tt>http://www.w3.org/TR/webarch/</tt> .
  </dd>

    <dt><a name="UNIID" id="UNIID">[UNIID]</a></dt>
    <dd>

    <a href="http://www.unicode.org/reports/tr31/tr31-5.html">Identifier
      and Pattern Syntax 4.1.0</a>, Mark Davis, Unicode
      Standard Annex #31, 25 March 2005,
      http://www.unicode.org/reports/tr31/tr31-5.html . 
    <a href="http://www.unicode.org/reports/tr31/" title="Latest version of Identifier and Pattern Syntax">Latest
      version</a> available at <a href="http://www.unicode.org/reports/tr31/">http://www.unicode.org/reports/tr31/</a>
      .</dd>
<!-- SPARQL 1.0 references
      <dt>[<a name="refSemantics1" id="refSemantics1">SPARQL-sem-05</a>]</dt>
      <dd><a href="http://www.hpl.hp.com/techreports/2005/HPL-2005-170.html">A relational
      algebra for SPARQL</a>, Richard Cyganiak, 2005</dd>

      <dt>[<a name="refSemantics2" id="refSemantics2">SPARQL-sem-06</a>]</dt>
      <dd><a href="http://arxiv.org/abs/cs/0605124">Semantics of SPARQL</a>, Jorge P&eacute;rez, Marcelo Arenas, and Claudio Gutierrez, 
      2006</dd>
-->
</dl>

      </div2>
    </div1>



<div>
  <h2 id="changelog">Change Log</h2>

  
    <h3 id="changes-since-pr">Changes since Proposed Recommendation</h3>

    <ul>
      <li>Fixed error in example of inverse property path</li>
    </ul>

    <h3 id="changes-since-lc">Changes since Last Call</h3>

      <p>The following are the corrections made since last publication:</p>
      <ul>
	<li>Grammar: <tt>DISTINCT</tt> for paths had been left in the grammar - removed.</li>
	<li>Restore translation of <tt>BIND</tt> as per text in previous publications (first and second last call).</li>
      </ul>
      

    <h3 id="changes-since-10">Since SPARQL 1.0</h3>

      <p>The new features in SPARQL 1.1 Query are:</p>
      <ul>
  <li>
    <a title="Feature:Aggregates" href="#aggregates">Aggregates</a>
  </li>
  <li>
    <a title="Feature:Subqueries" href="#subqueries">Subqueries</a>
  </li>
  <li>
    <a title="Feature:Negation" href="#negation">Negation</a>
  </li>
  <li>
    <a title="Feature:ProjectSelectExpressions" href="#selectExpressions">Expressions in the SELECT clause</a>
  </li>
  <li>
    <a href="#propertypaths">Property Paths</a>
  </li>
  <li>
    <a href="#assignment">Assignment</a>
  </li>
  <li>
    <a href="#constructWhere">A short form for CONSTRUCT</a>
  </li>
  <li>
    <a href="#SparqlOps">An expanded set of functions and operators</a>
  </li>
      </ul>

</div>

  </back>
</spec>
