๐Ÿ” SPARQL โ€” Query Language

Lecture 6 Interactive Learning Companion

๐Ÿ” SPARQL Vocabulary Explorer

Explore SPARQL 1.1 features interactively. Select a category to see syntax, semantics, and examples.

// Select a category above to explore SPARQL 1.1 features
๐Ÿ“š Remember: SPARQL is to RDF what SQL is to relational databases. It uses graph pattern matching with variables (prefixed with ?) to find data in RDF graphs.

๐Ÿ—๏ธ SPARQL Query Builder

Build SPARQL queries step by step. Add triple patterns, filters, and modifiers to construct a complete query.

form
limit order

Generated SPARQL:

PREFIX ex: <http://example.org/> # Add patterns above and click Generate!
๐Ÿ’ก Tip: SPARQL joins are implicit โ€” shared variables across triple patterns act as join keys. No need for explicit JOIN ... ON like in SQL.

๐Ÿงช Query Sandbox

Write SPARQL queries against a sample RDF dataset and see the results. The dataset is a small university ontology.

๐Ÿ’ก Sandbox: This is a simulated SPARQL engine running in your browser. It supports basic SELECT, FILTER, OPTIONAL, aggregation, and CONSTRUCT over a fixed university dataset.

โš™๏ธ SPARQL Evaluation Simulator

Watch step-by-step how a SPARQL engine evaluates a query: from parsing to pattern matching to results.

Select a scenario above

๐Ÿง  Key Concept: SPARQL evaluation is bottom-up: first evaluate Basic Graph Patterns (BGPs), then apply joins (AND), left-joins (OPTIONAL), unions (UNION), and finally filters (FILTER).

๐ŸŽฎ SPARQL Challenge Game

Test your knowledge of SPARQL query language, patterns, operators, and semantics!

Score: 0
Question 1 / 10

Press "Start Game" to begin!

๐Ÿ“ Lecture 6 Quiz

Test your understanding of SPARQL: query forms, graph patterns, operators, aggregation, and federation!

1. Which SPARQL query form returns a new RDF graph?
SELECT
CONSTRUCT
ASK
DESCRIBE
1 / 12

๐Ÿ“‹ SPARQL 1.1 Cheat Sheet

Quick reference for SPARQL query forms, operators, functions, property paths, and aggregation.

๐Ÿ“‹ Query Forms

SELECT โ€” Returns a table of variable bindings
CONSTRUCT โ€” Returns a new RDF graph from a template
ASK โ€” Returns true/false (existence check)
DESCRIBE โ€” Returns an RDF description of a resource
SELECT DISTINCT ?name ?age WHERE { ?p ex:name ?name . ?p ex:age ?age } ORDER BY ?name LIMIT 10 OFFSET 5

๐Ÿ”— Graph Pattern Operators

. (dot) โ€” Join (AND) two triple patterns
OPTIONAL { } โ€” Left outer join (include even if no match)
UNION { } { } โ€” Combine alternatives (OR)
MINUS { } โ€” Set difference (remove matches)
FILTER NOT EXISTS { } โ€” Filter-based negation
GRAPH <uri> { } โ€” Query a named graph
BIND (expr AS ?var) โ€” Create a new variable
VALUES ?x { v1 v2 } โ€” Inline data injection

๐Ÿ” Filter Functions

FILTER (?age > 18) FILTER (LANG(?name) = "en") FILTER REGEX(?name, "^Ali", "i") FILTER (BOUND(?email)) FILTER (isIRI(?x) || isLiteral(?x)) FILTER (CONTAINS(?name, "Alice")) FILTER (STRSTARTS(?uri, "http://")) FILTER (?date > "2024-01-01"^^xsd:date)

๐Ÿ›ค๏ธ Property Paths

p/q โ€” Sequence (p then q) p|q โ€” Alternative (p or q) p* โ€” Zero or more (transitive closure) p+ โ€” One or more p? โ€” Zero or one ^p โ€” Inverse (follow backwards) !(p) โ€” Negated (any property except p) (p/q)* โ€” Grouped with repetition

๐Ÿ“Š Aggregation

GROUP BY โ€” Partition solutions into groups
HAVING โ€” Filter groups after aggregation
COUNT, SUM, AVG, MIN, MAX โ€” Aggregate functions
GROUP_CONCAT โ€” Concatenate strings in a group
SAMPLE โ€” Arbitrary value from group
SELECT ?dept (COUNT(?p) AS ?cnt) WHERE { ?p ex:worksIn ?dept } GROUP BY ?dept HAVING (COUNT(?p) > 5) ORDER BY DESC(?cnt)

๐Ÿ“ Update & Federation

INSERT DATA { triples } โ€” Add triples
DELETE DATA { triples } โ€” Remove triples
DELETE { } INSERT { } WHERE { } โ€” Conditional update
LOAD <url> โ€” Load triples from URL
SERVICE <endpoint> { } โ€” Federated query
SERVICE SILENT โ€” Ignore remote errors