# ========================================================================== # Q01 Every bookshop on the trail # ========================================================================== # # ASKS # What bookshops are in this dataset, and what are they called? # # HOW IT WORKS # One triple pattern finds the shops, a second fetches each one's label. # Both patterns mention ?shop, so the engine keeps only the combinations # where the same ?shop satisfies both -- that shared variable is the # join, and it's the only join mechanism SPARQL has. # # DIAGRAM # ?shop ---- rdf:type ----> bs:Bookshop (which things are shops) # | # +------- rdfs:label ---> ?name (what each is called) # # Both lines constrain the SAME ?shop, so a row survives only if # both are true of it. 33 shops in, 33 rows out. # # # WHAT TO TAKE AWAY # - A query is a graph pattern: you draw the shape you want and the # engine finds every place the shape fits. # - `a` is shorthand for rdf:type. It's the one abbreviation SPARQL # borrows from Turtle. # - Repeating a variable joins the patterns. There's no JOIN keyword # because there doesn't need to be one. # # DATA bookshop-trail-1.1.ttl # LOAD IT https://semantechs.co.uk/turtle-editor-viewer/?dot=https%3A%2F%2Fraw.githubusercontent.com%2Fpwin%2FSPARQL_Course%2Fmain%2Fdata%2Fbookshop-trail-1.1.ttl # RUNS ON editor, holos, fuseki # SPEC SPARQL 1.2 Query 2. Making Simple Queries # https://www.w3.org/TR/sparql12-query/#x2-making-simple-queries-informative # SPARQL 1.2 Query 4. SPARQL Syntax # https://www.w3.org/TR/sparql12-query/#x4-sparql-syntax # RETURNS 33 rows, on every engine that runs it # ========================================================================== PREFIX bs: PREFIX rdfs: SELECT ?shop ?name WHERE { ?shop a bs:Bookshop ; rdfs:label ?name . } ORDER BY ?name