SPARQL Extensions
From n² wiki
This page lists the SPARQL extensions supported by both the SPARQL Service and the Multisparql Service.
Extensions to the SPARQL query language can be divided into three categories:
- Extension Functions
- Property Functions
- Language Extensions
The supported extensions in each category are described below.
Users should be aware that certain extensions may not be supported in other triple stores and services, this means that queries using those extensions may not be portable across the same dataset hosted on an alternate platform.
Contents |
[edit] Extension Functions
No extension functions are currently supported.
[edit] Property Functions
No property functions are currently supported.
[edit] Language Extensions
[edit] SPARQL 1.1 Early Access Features
As of Platform Release 29, a subset of the aggregate functions and project expressions being proposed by the W3C SPARQL Working Group for inclusion in SPARQL 1.1 is supported in an experimental capacity. The details of the supported syntax listed below aims to remain as close as possible to the drafts published by the working group, and is subject to change as SPARQL Query 1.1 approaches recommendation status.
The currently supported SPARQL 1.1 features are:
| Extension | Description |
|---|---|
| count(*) | Count rows in results. |
| count(distinct *) | Count the distinct rows in the results |
| count(?x) | Count the number of times ?x is bound in the results |
| count(distinct ?x) | Count the number of distinct values ?x is bound to in the results |
| sum(?x) | Sum the variable over the group. Note: non-numeric values and unbound values are ignored |
| SELECT Expressions | Allow assignments of aggregate values in a SELECT clause (only). E.g. (count(?x) AS ?count) |
| GROUP BY | Transforms a result set so that only one row will appear for each unique set of grouping variables. All other variables from the query will be removed, so any variable that needs to be returned should be included in the GROUP BY. |
| HAVING | Allows an expression to be used to filter the results of a GROUP BY query. The HAVING operator expects an expression similar to that used in a FILTER only with the additional support of aggregate functions |
Note that for the aggregate functions count() and sum() the function will apply to either to the whole results, or the group element (if a GROUP BY clause is provided).
The following examples illustrate the syntax of some of these extensions:
#Count how many people have ages. PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT count(*) WHERE { ?x a foaf:Person; foaf:age ?age. }
#Count how many people have ages. Using select expression PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ( count(*) AS ?count ) WHERE { ?x a foaf:Person; foaf:age ?age. }
#Sum up ages PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ( sum(?age) AS ?ages ) WHERE { ?x a foaf:Person; foaf:age ?age. }
#How many people does Buzz know? PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX data: <http://www.example.org/schema/> PREFIX ex: <http://www.example.org/schema/> SELECT ( count(distinct ?friend) as ?count ) WHERE { ex:Buzz foaf:knows ?friend. }
#Summarize ages using group by and order by PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?age ( count(?age) AS ?count ) WHERE { ?x a foaf:Person; foaf:age ?age. } GROUP BY ?age ORDER BY DESC(?count)
#Which ages have more than one person with that age? PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?age ( count(?age) as ?count ) WHERE { ?x a foaf:Person; foaf:age ?age. } GROUP BY ?age HAVING (?count > 1)

