sparql-templating
Query that shows how Triply Templating can be used to simplify SPARQL queries with complex literals. This is specifically useful for SPARQL queries that return HTML literals, which can be rather complex.
This query is a simplified version of this query that does not use Triply Templating.
sparql-html
This query shows how HTML literals can be returned by a SPARQL query.
Since the creation of complex HTML literals can be rather cumbersome, the query can be rewritten into this query that uses Triply Templates for simplification.
3-3
Aggregation: concatenate
This query applies the string concatenation function to the blocks of aggregated values.
Notice that the projection variables are calculated in sequence, so that later projection variables can make use of earlier ones.
3-2-implicit-bracketed
This query is similar to query 3-2-implicit, but uses anonymous node notation in order to omit the ?item
subject term variable. By doing so, the meaning of this query is significantly changed, as can be seen by the result set.
How to read the aggregation in this query?
- We are dealing with aggregation, because at least one aggregation function (
count
) appears. - No
group by
clause appears, so we are dealing with implicit grouping. - Implicit grouping means grouping around the set of variables that are visible and not argument to an aggregation function. In this case, this set of variables is ∅ (the empty set).
- Grouping based on the empty set means that all results are part one one big group. So this query counts the number of names in the entire dataset.
3-2-implicit
This query is similar to query 3.2, but uses implicit grouping.
Implicit grouping occurs when at least one aggregation function is used (in this case count
) and no group by
clause is given. In this case, grouping is performed based on the set of visible variables that are not themselves arguments to an aggregation function. In this query, implicit grouping result in grouping around the ?item
variable.
3-2
Aggregation: count
This query applies the count
function to the blocks of names that appear with Creative works.
3-1
The result set of this query consists of 'blocks' of values (names in this case) that appear with the same Creative Works.
Aggregation allows functions to be applied to these 'blocks' of values, resulting in one single value per grouping element.
The grouping element can consist of one or more variables.
2-9
Every variable in a SPARQL query can be replaced by an RDF name (an IRI or literal). Replacing a variable with an RDF name makes the query more specific, i.e., results in a smaller result set.
This query is similar to query 2-8, but the ?typeName
variable is replaced by the literal `"StillImage" so that only stillImages for the Creative works are returned.
2-8
Abbreviation: property path notation
This query is similar to query 2-7, but uses Property Path notation (forward slash, /
) in order to skip a node that was not used in the result set.
2-7
This query has a Graph Pattern that consists of four Triple Patterns.
2-6
Filter by language
This query uses the lang/1
function in order to return only those result rows in which one name is in Japanese (ja-ja
) and one name is in US English (en-us
).
The fact that both constraints must be satisfied is expressed by the Boolean conjunction operator (&&
).
2-5
Some properties can have multiple values for the same object. For example, one item has multiple values for the name property (item:name
) in different languages.
Notice that when a Triple Pattern ends with the comma character (,
) the next Triple Pattern implicitly has the same subject and predicate terms as the previous Triple Pattern. (If the number of object terms is small we are used to placing them on the same physical line, as in this query.)
The filter
expression puts additional constraints on which results are returned: the two names must be different. Difference/non-identity is specified by the !=
operator.
Notice that use of !=
means that for every pair 〈A,B〉 the pair 〈B,A〉 is also included. Use the smaller than (<
) or larger than (>
) operator instead in order to exclude such symmetric name pairs in the result set.
2-4
Abbreviation: repeated subject terms
This query is similar to query 2-3, but the subject term is not repeated.
Whenever consecutive Triple Patterns have the same subject term, the subject term of the next Triple Pattern can be skipped if the previous Triple Pattern ends in a semi-colon (;
) instead of a dot (.
).
2-3
Graph Pattern: Four Triple Patterns
This query contains a Graph Pattern that consists of four Triple Patterns. Notice how all TP share the same subject term and how the last two TP also share the same predicate term.
2-2
Graph Pattern: 2 Triple Patterns
This query has a Graph Pattern that consists of 2 Triple Patterns. Notice how the Triple Patterns are connect by a shared variable (?item
).
2-11
Result set modification
This query is similar to query 2-10, but inverts the sort with the descending (desc
) keyword, resulting in the 25 newest images.
2-10
Result set modifiers: order by
This query returns the 25 Creative works with the oldest date of publication.
2-1
Graph Pattern: 1 Triple Pattern
Lesson 1 dealt with SPARQL queries that consist of 1 Triple Pattern. (This often corresponds to one physical line in the query string.) One or more consecutive Triple Patterns together form a Graph Pattern.