SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
SPARQL - Querying the Web of Data
                      Seminar WS 2008/2009

   An Introduction to SPARQL


                                  Olaf Hartig
               hartig@informatik.hu-berlin.de
SPARQL in General
     SPARQL Protocol and RDF Query Language
 ●



     SPARQL Query Language for RDF
 ●


         Declarative
     ●


         Based on the RDF data model (triples/graph)
     ●


         Our focus
     ●



     SPARQL Query Results XML Format
 ●


         Representation of the results of SPARQL queries
     ●



     SPARQL Protocol for RDF
 ●


         Transmission of SPARQL queries and the results
     ●


         SPARQL endpoint: Web service that implements the
     ●

                          protocol
An Introduction to SPARQL                                   2
Main Idea of SPARQL Queries
     Main idea: pattern matching
 ●


         Describe subgraphs of the queried RDF graph
     ●


         Subgraphs that match your description yield a result
     ●


         Mean: graph patterns (i.e. RDF graphs with variables)
     ●




                                 rdf:type
                            ?v
                                            umbel-sc:Volcano




An Introduction to SPARQL                                        3
Main Idea of SPARQL Queries
 Queried
 graph:
                           rdf:type
       dbpedia:Mount_Baker          umbel-sc:Volcano
         p:lastEruption                                      rdf:type
                                 quot;1880quot;           dbpedia:Mount_Etna


                                      rdf:type
                            ?v
                                                 umbel-sc:Volcano
   Results:
                     ?v
   dbpedia:Mount_Baker
   dbpedia:Mount_Etna
An Introduction to SPARQL                                               4
Components of SPARQL Queries
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 FROM <http://example.org/myGeoData>
 WHERE {
     ?v rdf:type umbel-sc:Volcano .
 }
 ORDER BY ?name




An Introduction to SPARQL                                5
Components of SPARQL Queries
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 FROM <http://example.org/myGeoData>
 WHERE {
         ?v rdf:type umbel-sc:Volcano .
 }
 ORDER BY ?name

     Prologue:
 ●


         Prefix definitions enable CURIEs in the query
     ●


         Attention: No period (“.”) character to separate (as in N3)
     ●




An Introduction to SPARQL                                              6
Components of SPARQL Queries
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 FROM <http://example.org/myGeoData>
 WHERE {
         ?v rdf:type umbel-sc:Volcano .
 }
 ORDER BY ?name

     Result form specification:
 ●


         SELECT, DESCRIBE, CONSTRUCT, or ASK
     ●


         SELECT: - Variable list or asterisk (“*”) character for all
     ●

                 - DISTINCT for disjoint results
An Introduction to SPARQL                                              7
Components of SPARQL Queries
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 FROM <http://example.org/myGeoData>
 WHERE {
         ?v rdf:type umbel-sc:Volcano .
 }
 ORDER BY ?name

     Dataset specification:
 ●


         Specify the dataset to be queried
     ●


         Use FROM and FROM NAMED clauses (each with a URI)
     ●




An Introduction to SPARQL                                    8
Components of SPARQL Queries
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 FROM <http://example.org/myGeoData>
 WHERE {
         ?v rdf:type umbel-sc:Volcano .
 }
 ORDER BY ?name

     Query Pattern:
 ●


         WHERE clause specifies the graph pattern to be matched
     ●




An Introduction to SPARQL                                         9
Components of SPARQL Queries
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 FROM <http://example.org/myGeoData>
 WHERE {
         ?v rdf:type umbel-sc:Volcano .
 }
 ORDER BY ?name

     Solution modifiers:
 ●


         Modify the result set, but not the single results
     ●


         ORDER BY, LIMIT, or OFFSET
     ●




An Introduction to SPARQL                                    10
Graph Patterns


     Different types of graph patterns for the query pattern
 ●

     (WHERE clause):
         Basic graph pattern (BGP)
     ●


         Group graph pattern
     ●


         Optional graph pattern
     ●


         Union graph pattern
     ●


         Graph graph pattern
     ●


         (Constraints)
     ●




An Introduction to SPARQL                                      11
Basic Graph Patterns
     Set of triple patterns (i.e. RDF triples with variables)
 ●


     Variable names prefixed with “?” or “$” (e.g. ?v, $v)
 ●




 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?name
 WHERE {
     ?v rdf:type umbel-sc:Volcano .
     ?v rdfs:label ?name .
 }
An Introduction to SPARQL                                       12
Basic Graph Patterns
     Set of triple patterns (i.e. RDF triples with variables)
 ●


     Variable names prefixed with “?” or “$” (e.g. ?v, $v)
 ●


     Turtle syntax (similar to N3)
 ●


     Syntactical sugar as in N3 (e.g. property and object lists)
 ●



 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?name
 WHERE {
     ?v rdf:type umbel-sc:Volcano ;
           rdfs:label ?name .
 }
An Introduction to SPARQL                                          13
Basic Graph Patterns
                                                                Data*
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                               rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                       umbel-sc:NaturalElevation ;
                               rdfs:label quot;Beerenbergquot;@en ;
                               rdfs:label quot;Бееренбергquot;@ru   .

  Question: What are the names of all (known) volcanos?
 ●

                                          Result:
                              Query*
 SELECT ?name WHERE {
                                                ?name
   ?v rdf:type umbel-sc:Volcano ;
                                                     quot;Etnaquot;
           rdfs:label ?name . }
                                                     quot;Бееренбергquot;@ru
                                                     quot;Beerenbergquot;@en
 *Prefix definitions omitted
An Introduction to SPARQL                                              14
Basic Graph Patterns
                                                                 Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru    .

     Question: List all types of the volcano called “Beerenberg”
 ●



                                      Query
 SELECT ?type WHERE {
                                                         ?type
     ?v rdf:type ?type ;
           rdfs:label quot;Beerenbergquot; .
 }

An Introduction to SPARQL                                           15
Basic Graph Patterns
                                                              Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru   .

     Question: List all types of the volcano called “Beerenberg”
 ●



                                      Query
 SELECT ?type WHERE {
     ?v rdf:type ?type ;                           ?type
           rdfs:label quot;Beerenbergquot;@en .
                                          umbel-sc:Volcano
 }                                        umbel-sc:NaturalElevation
An Introduction to SPARQL                                         16
Basic Graph Patterns
                                                               Data
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
                            p:location dbpedia:United_States .
 dbpedia:United_States rdfs:label quot;United Statesquot; .

     Question: Where are all (known) volcanos located? List
 ●

     the names.
     Blank nodes in SPARQL queries
 ●


         Permitted as subject and object of a triple pattern
     ●


         Like non-selectable variables
     ●




                                            Query
 SELECT ?name WHERE {
                                                         ?name
     _:x rdf:type umbel-sc:Volcano ;
                                                     quot;United Statesquot;
           p:location [ rdfs:label ?name ] . }
An Introduction to SPARQL                                              17
Basic Graph Patterns
                                                                     Data
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
                            p:location [ rdfs:label quot;United Statesquot;@en ,
                                                      quot;États-Unisquot;@fr ] .
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                                 p:location [ rdfs:label quot;Italyquot; ] .

     Blank nodes in the queried graph
 ●


         Blank node identifiers may occur in the results
     ●



                                         Query
 SELECT ?l ?name WHERE {
                                                 ?l          ?name
         ?v rdf:type umbel-sc:Volcano ;
                                                 _:x quot;United Statesquot;@en
           p:location ?l .
                                                 _:x quot;États-Unisquot;@fr
         ?l rdfs:label ?name .
                                                 _:y quot;Italyquot;
 }
An Introduction to SPARQL                                                   18
Optional Graph Patterns
                                                              Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Beerenbergquot;@en .

     Question: What are all (known) volcanos and their names?
 ●



                                      Query
 SELECT ?v ?name WHERE {
     ?v rdf:type umbel-sc:Volcano ;
           rdfs:label ?name . }
                                     ?v               ?name
     Problem: Mount
 ●
                             dbpedia:Mount_Etna quot;Etnaquot;
      Baker missing
                             dbpedia:Beerenberg quot;Beerenbergquot;@en
      (it has no name)
An Introduction to SPARQL                                         19
Optional Graph Patterns
     Keyword OPTIONAL allows for optional patterns
 ●



                                         Query
 SELECT ?v ?name WHERE {
     ?v rdf:type umbel-sc:Volcano .
     OPTIONAL { ?v rdfs:label ?name }
 }


                                    ?v                 ?name
                            dbpedia:Mount_Etna    quot;Etnaquot;
                            dbpedia:Mount_Baker
                            dbpedia:Beerenberg    quot;Beerenbergquot;@en
     Optional patterns may yield unbound variables
 ●




An Introduction to SPARQL                                           20
Union Graph Patterns
                                                                Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                               rdfs:label quot;Etnaquot; ;
                               p:location dbpedia:Italy .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
                                p:location dbpedia:United_States .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                               rdfs:label quot;Beerenbergquot;@en ;
                               p:location dbpedia:Norway .

     Question: What volcanos are located in the Italy or in
 ●

     Norway?
                                                  Query
                 SELECT ?v WHERE {
                            ?v rdf:type umbel-sc:Volcano ;
                                            ?
                              p:location             .}
An Introduction to SPARQL                                            21
Union Graph Patterns
     Union graph patterns allow for alternatives
 ●



                                                                Query
                               SELECT ?v WHERE {
                                    { ?v rdf:type umbel-sc:Volcano ;
  Semantically                          p:location dbpedia:Italy }
   equivalent
                                    UNION
                                    { ?v rdf:type umbel-sc:Volcano ;
                                        p:location dbpedia:Norway }
                               }
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
                            { ?v p:location dbpedia:Italy }
                            UNION
                            { ?v p:location dbpedia:Norway }
                                                        Query
 }
An Introduction to SPARQL                                              22
Group Graph Patterns
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
                             { ?v p:location dbpedia:Italy }
                             UNION
                             { ?v p:location dbpedia:Norway }
                                                                 Query
 }

                  Semantically equivalent

 SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano }
                             { { ?v p:location dbpedia:Italy }
                                UNION
                                { ?v p:location dbpedia:Norway } }
                                                                 Query
 }
An Introduction to SPARQL                                            23
Constraints
     Constraints filter solutions
 ●


     Keyword FILTER followed by expression
 ●


     Filter expressions contain operators and functions
 ●



 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
 PREFIX p: <http://dbpedia.org/property/>
 SELECT ?v
 WHERE {
     ?v rdf:type umbel-sc:Volcano ;
           p:lastEruption ?le .
     FILTER ( ?le > 1900 )
 }
An Introduction to SPARQL                                 24
Constraints
     Operators and functions operate on RDF terms
 ●


     Filter expressions evaluate to true, false, or error
 ●


     Truth table:
 ●
                            A   B   A || B   A && B
                            T   T     T         T
                            T   F     T         F
                            F   T     T         F
                            F   F      F        F
                            T   E     T         E
                            E   T     T         E
                            F   E      E        F
                            E   F      E        F
                            E   E      E        E
An Introduction to SPARQL                                   25
Constraints
     Unary operators:
 ●




                       Operator          Type(A)      Result type
                         !A           xsd:boolean     xsd:boolean
                         +A           numeric         numeric
                         -A           numeric         numeric
                       BOUND(A)       variable        xsd:boolean
                       isURI(A)       RDF term        xsd:boolean
                       isBLANK(A)     RDF term        xsd:boolean
                       isLITERAL(A)   RDF term        xsd:boolean
                       STR(A)         literal / URI   simple literal
                       LANG(A)        literal         simple literal
                       DATATYPE(A)    literal         simple literal
An Introduction to SPARQL                                              26
Constraints
                                                              Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru   .

  Question: List all types of the volcano called “Beerenberg”
 ●


                                               ?type
                                     Query
 SELECT ?type WHERE {
                                          umbel-sc:Volcano
     ?v rdf:type ?type ;
                                          umbel-sc:NaturalElevation
           rdfs:label ?name .
     FILTER ( STR(?name) = quot;Beerenbergquot; )
 }

An Introduction to SPARQL                                             27
Constraints
     Binary operators:
 ●


         Logical connectives && and || for xsd:boolean
     ●


         Comparison operators =, !=, <, >, <=, and >= for numeric
     ●

         datatypes, xsd:dateTime, xsd:string, and xsd:boolean
         Comparison operators = and != for other datatypes
     ●


         Arithmetic operators +, -, *, and / for numeric datatypes
     ●




     Furthermore:
 ●


         REGEX(String,Pattern) or REGEX(String,Pattern,Flags)
     ●


         sameTERM(A,B)
     ●


         langMATCHES(A,B)
     ●




An Introduction to SPARQL                                            28
Constraints
                                                                Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru    .

     Question: What volcanos have an “e” in their name?
 ●



                                      Query
 SELECT ?v WHERE {
                                                          ?v
     ?v rdf:type umbel-sc:Volcano ;
                                                  dbpedia:Beerenberg
           rdfs:label ?name .
                                                  dbpedia:Beerenberg
     FILTER( REGEX(STR(?name),quot;equot;) )
 }

An Introduction to SPARQL                                          29
Constraints
                                                              Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru   .

     Question: What volcanos have an “e” in their name?
 ●



                                        Query
 SELECT ?v WHERE {
                                                         ?v
     ?v rdf:type umbel-sc:Volcano ;
                                         dbpedia:Mount_Etna
           rdfs:label ?name .
                                         dbpedia:Beerenberg
     FILTER( REGEX(STR(?name),quot;equot;,quot;iquot;) )
                                         dbpedia:Beerenberg
 }

An Introduction to SPARQL                                         30
Negation
                                                            Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru .

     Question: What volcanos do not have a name in our data?
 ●



                                      Query
 SELECT ?v WHERE {
     ?v rdf:type umbel-sc:Volcano .
                                                     ?v
     OPTIONAL { ?v rdfs:label ?name }
                                            dbpedia:Mount_Baker
     FILTER( ! BOUND(?name) )
 }

An Introduction to SPARQL                                         31
Negation
                                                             Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru .

     Question: What volcanos are not called “Beerenberg”?
 ●



                                           Query
 SELECT ?v WHERE {
                                            !=
     ?v rdf:type umbel-sc:Volcano .
         rdfs:label ?name .
                                                       ?v
     FILTER (STR(?name) != quot;Beerenbergquot;)
                                              dbpedia:Mount_Etna
 }
                                              dbpedia:Mount_Baker
                                              dbpedia:Beerenberg 32
An Introduction to SPARQL
Negation
                                                                    Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                                  rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                  rdfs:label quot;Beerenbergquot;@en ;
                                  rdfs:label quot;Бееренбергquot;@ru .

  Question: What volcanos are not called “Beerenberg”?
 ●


                                               ?v
                                            Query
 SELECT ?v WHERE {
                                                    dbpedia:Mount_Etna
     ?v rdf:type umbel-sc:Volcano .
                                                    dbpedia:Mount_Baker
     OPTIONAL { ?v rdfs:label ?name .
                            FILTER (STR(?name) = quot;Beerenbergquot;) }
     FILTER ( ! BOUND(?name) )
                                                   Negation as Failure
 }
An Introduction to SPARQL                                                 33
Graph Graph Patterns


     SPARQL queries are executed against an RDF dataset
 ●


     An RDF dataset comprises:
 ●


         One default graph and
     ●


         Zero or more named graphs (identified by an URI)
     ●


     Keyword GRAPH makes one of the named graphs the
 ●

     active graph used for pattern matching




An Introduction to SPARQL                                   34
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                   http://example.org/d1
                            dbpedia:Mount_Etna
                                rdf:type umbel-sc:Volcano ;
 Default
                                rdfs:label quot;Etnaquot; .
 Graph
                                                    http://example.org/d2
                             dbpedia:Mount_Baker
                                  rdf:type umbel-sc:Volcano .
                                                     http://example.org/d3
                              dbpedia:Beerenberg
                                   rdf:type umbel-sc:Volcano ;
                                   rdfs:label quot;Beerenbergquot;@en .




An Introduction to SPARQL                                                   35
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                   http://example.org/d1
                            dbpedia:Mount_Etna
                                rdf:type umbel-sc:Volcano ;
                                rdfs:label quot;Etnaquot; .
                                                    http://example.org/d2
                             dbpedia:Mount_Baker
                                  rdf:type umbel-sc:Volcano .
                                                     http://example.org/d3
                              dbpedia:Beerenberg
 SELECT ?v WHERE {
                         rdf:type umbel-sc:Volcano ;
     GRAPH <http://example.org/d1> {
                         rdfs:label quot;Beerenbergquot;@en .
       ?v rdf:type umbel-sc:Volcano .
                                                           ?v
     }
 }                                                 dbpedia:Mount_Etna
An Introduction to SPARQL                                                   36
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                   http://example.org/d1
                            dbpedia:Mount_Etna
                                rdf:type umbel-sc:Volcano ;
                                rdfs:label quot;Etnaquot; .
                                                    http://example.org/d2
                             dbpedia:Mount_Baker
                                  rdf:type umbel-sc:Volcano .
                                                      http://example.org/d3
                              dbpedia:Beerenberg
 SELECT ?v WHERE {
                                   rdf:type umbel-sc:Volcano ;
     GRAPH ?g {                                             ?v
                           rdfs:label quot;Beerenbergquot;@en .
         ?v rdf:type umbel-sc:Volcano .
                                                   dbpedia:Mount_Etna
     }                                             dbpedia:Mount_Baker
 }                                                 dbpedia:Beerenberg
An Introduction to SPARQL                                                   37
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                    http://example.org/d1
                             dbpedia:Mount_Etna
                                  rdf:type umbel-sc:Volcano ;
                                  rdfs:label quot;Etnaquot; .
                                                      http://example.org/d2
                              dbpedia:Mount_Baker
                                   rdf:type umbel-sc:Volcano .
                                       http://example.org/d3
                  dbpedia:Beerenberg
 SELECT ?v ?g WHERE {
                       rdf:type umbel-sc:Volcano ;
   GRAPH ?g {           ?v                     ?g
                       rdfs:label quot;Beerenbergquot;@en .
     ?v rdf:type umbel-sc:Volcano .
                            dbpedia:Mount_Etna      <http://example.org/d1>
     }                      dbpedia:Mount_Baker     <http://example.org/d2>
 }                          dbpedia:Beerenberg      <http://example.org/d3>
An Introduction to SPARQL                                                     38
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                   http://example.org/d1
                            dbpedia:Mount_Etna
                                rdf:type umbel-sc:Volcano ;
                                rdfs:label quot;Etnaquot; .
                                                    http://example.org/d2
                             dbpedia:Mount_Baker
                                  rdf:type umbel-sc:Volcano .
 SELECT ?v WHERE {
                                         http://example.org/d3
                    dbpedia:Beerenberg
     _:x rdfs:seeAlso ?g
                         rdf:type umbel-sc:Volcano ;
     GRAPH ?g {
                         rdfs:label quot;Beerenbergquot;@en .
       ?v rdf:type umbel-sc:Volcano .
                                                            ?v
     }
                                                   dbpedia:Mount_Etna
 }
                                                   dbpedia:Mount_Baker
An Introduction to SPARQL                                                   39
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                   http://example.org/d1
                            dbpedia:Mount_Etna
                                rdf:type umbel-sc:Volcano ;
                                rdfs:label quot;Etnaquot; .
                                                    http://example.org/d2
                             dbpedia:Mount_Baker
                                  rdf:type umbel-sc:Volcano .
                                                     http://example.org/d3
                              dbpedia:Beerenberg
                                   rdf:type umbel-sc:Volcano ;
                                   rdfs:label quot;Beerenbergquot;@en .

     Question: Which named graphs contain the name of a
 ●

       volcano that is not referenced in the default graph?
An Introduction to SPARQL                                                   40
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                                 http://example.org/d1
                            dbpedia:Mount_Etna
                                rdf:type umbel-sc:Volcano ;
                                rdfs:label quot;Etnaquot; .
 SELECT ?g WHERE {
                 dbpedia:Mount_Baker http://example.org/d2
   GRAPH ?g {         rdf:type umbel-sc:Volcano .
         ?v rdf:type umbel-sc:Volcano ;
                                           http://example.org/d3
                      dbpedia:Beerenberg
            rdfs:label ?name .
                           rdf:type umbel-sc:Volcano ;
     }
                         rdfs:label quot;Beerenbergquot;@en .
     OPTIONAL { ?v rdfs:seeAlso ?r }
   Question: ! BOUND(?r) ) graphs contain the name of a
   FILTER ( Which named
 ●

     volcano that is not referenced in the default graph?
 }
An Introduction to SPARQL                                                41
Summary – Graph Patterns


     Different types of graph patterns for the query pattern
 ●

     (WHERE clause):
         Basic graph pattern (BGP)
     ●


         Group graph pattern
     ●


         Optional graph pattern – keyword OPTIONAL
     ●


         Union graph pattern – keyword UNION
     ●


         Graph graph pattern – keyword GRAPH
     ●


         Constraints – keyword FILTER
     ●




An Introduction to SPARQL                                      42
Result Forms
     SELECT
 ●


         Sequence of results (i.e. sets of variable bindings)
     ●


         Selected variables separated by space (not by comma!)
     ●


         Asterisk (“*”) character selects all variables in the pattern
     ●



     ASK
 ●


         Check if there is at least one result
     ●


         Example: Do we have volcanos that do not have a name?
     ●



                                                                Query
 ASK WHERE { ?v rdf:type umbel-sc:Volcano .
                            OPTIONAL { ?v rdfs:label ?name }
                            FILTER( ! BOUND(?name) )
 }

An Introduction to SPARQL                                            43
Result Forms
     DESCRIBE
 ●


         Returns an RDF graph with data about resources
     ●


         Nondeterministic (i.e. query processor determines the
     ●

                     actual structure of the returned RDF graph)
         Name the resource:
     ●



                                                                 Query
 DESCRIBE <http://dbpedia.org/resource/Beerenberg>

         Specify the resource with a query pattern:
     ●



                                                                 Query
 DESCRIBE ?v WHERE {
         ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name .
         FILTER ( STR(?name) = quot;Beerenbergquot; )                     }

         Multiple variables possible or asterisk (“*”) for all
     ●


An Introduction to SPARQL                                             44
Result Forms
     CONSTRUCT
 ●


         Returns an RDF graph created from a template
     ●


         Template: graph pattern with variables from the query
     ●

         pattern
                                                                  Query
 CONSTRUCT { ?v rdfs:label ?name ;
                             rdf:type myTypes:VolcanosOutsideTheUS }
 WHERE {
         ?v rdf:type umbel-sc:Volcano ;
           rdfs:label ?name .
         OPTIONAL { ?v p:location ?l
                            FILTER ( ?l = dbpedia:United_States ) }
         FILTER ( ! BOUND(?l) )
 }
An Introduction to SPARQL                                              45
Result Forms
                                                             Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; ;
                            p:location dbpedia:Italy .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Mount Bakerquot; ;
                            p:location dbpedia:United_States .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            p:location dbpedia:Norway .

                                                            Result
 dbpedia:Mount_Etna rdfs:label quot;Etnaquot; ;
                            rdf:type myTypes:VolcanosOutsideTheUS.
 dbpedia:Beerenberg rdf:type myTypes:VolcanosOutsideTheUS;
                            rdfs:label quot;Beerenbergquot;@en .
An Introduction to SPARQL                                        46
Solution Modifiers


     Modify the result set, but not the single results
 ●


     Permitted for SELECT queries only
 ●


         DISTINCT
     ●


         ORDER BY
     ●


         LIMIT
     ●


         OFFSET
     ●




An Introduction to SPARQL                                47
Solution Modifiers
     DISTINCT – removes duplicates from the result set
 ●



                                                               Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru   .
                                                   ?type
                                  Query
 SELECT ?type
                                          umbel-sc:Volcano
 WHERE { _:x rdf:type ?type }             umbel-sc:Volcano
                                          umbel-sc:NaturalElevation
                                          umbel-sc:Volcano
An Introduction to SPARQL                                             48
Solution Modifiers
     DISTINCT – removes duplicates from the result set
 ●



                                                               Data
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                            rdfs:label quot;Etnaquot; .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                    umbel-sc:NaturalElevation ;
                            rdfs:label quot;Beerenbergquot;@en ;
                            rdfs:label quot;Бееренбергquot;@ru   .
                                                   ?type
                                  Query
 SELECT DISTINCT ?type
                                          umbel-sc:Volcano
 WHERE { _:x rdf:type ?type }             umbel-sc:NaturalElevation


An Introduction to SPARQL                                             49
Solution Modifiers
     ORDER BY – orders the results
 ●



                                                           Query
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;
                             rdfs:label ?name }
 ORDER BY ?name

         Order for different kinds of elements:
     ●

           unbound variable < blank node < URI < literal
         ASC for ascending (default) and DESC for descending
     ●


         Hierarchical order criteria:
     ●



 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query
                                 p:lastEruption ?le ;
                                 rdfs:label ?name }
 ORDER BY DESC(?le), ?name
An Introduction to SPARQL                                      50
Solution Modifiers
     LIMIT – limits the number of results
 ●



 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query
                              rdfs:label ?name }
 ORDER BY ?name
 LIMIT 5

     OFFSET – position/index of the first returned results
 ●



 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query
                              rdfs:label ?name }
 ORDER BY ?name
 LIMIT 5 OFFSET 10

     Only useful if the order is predictable (i.e. ordered results)
 ●



An Introduction to SPARQL                                             51
Further Reading
     W3C RDF Data Access Working Group
 ●

                     http://www.w3.org/2001/sw/DataAccess/
         SPARQL Query Language for RDF
     ●


         SPARQL Protocol for RDF
     ●


         SPARQL Query Results XML Format
     ●


     SPARQL interface
 ●

      for dbpedia:
      http://dbpedia.org/snorql/




An Introduction to SPARQL                                52

Weitere ähnliche Inhalte

Was ist angesagt?

SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshellFabien Gandon
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialAdonisDamian
 
Introduction To RDF and RDFS
Introduction To RDF and RDFSIntroduction To RDF and RDFS
Introduction To RDF and RDFSNilesh Wagmare
 
Introduction of Knowledge Graphs
Introduction of Knowledge GraphsIntroduction of Knowledge Graphs
Introduction of Knowledge GraphsJeff Z. Pan
 
Rdf data-model-and-storage
Rdf data-model-and-storageRdf data-model-and-storage
Rdf data-model-and-storage灿辉 葛
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeAdriel Café
 
온톨로지 개념 및 표현언어
온톨로지 개념 및 표현언어온톨로지 개념 및 표현언어
온톨로지 개념 및 표현언어Dongbum Kim
 
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...Jeff Z. Pan
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)Ameer Sameer
 
Introduction to Knowledge Graphs and Semantic AI
Introduction to Knowledge Graphs and Semantic AIIntroduction to Knowledge Graphs and Semantic AI
Introduction to Knowledge Graphs and Semantic AISemantic Web Company
 
Understanding RDF: the Resource Description Framework in Context (1999)
Understanding RDF: the Resource Description Framework in Context  (1999)Understanding RDF: the Resource Description Framework in Context  (1999)
Understanding RDF: the Resource Description Framework in Context (1999)Dan Brickley
 
Knowledge Graph Introduction
Knowledge Graph IntroductionKnowledge Graph Introduction
Knowledge Graph IntroductionSören Auer
 
Semantic Web - Ontologies
Semantic Web - OntologiesSemantic Web - Ontologies
Semantic Web - OntologiesSerge Linckels
 
SHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data MudSHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data MudRichard Cyganiak
 
SHACL in Apache jena - ApacheCon2020
SHACL in Apache jena - ApacheCon2020SHACL in Apache jena - ApacheCon2020
SHACL in Apache jena - ApacheCon2020andyseaborne
 

Was ist angesagt? (20)

SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
RDF and OWL
RDF and OWLRDF and OWL
RDF and OWL
 
Introduction To RDF and RDFS
Introduction To RDF and RDFSIntroduction To RDF and RDFS
Introduction To RDF and RDFS
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
Introduction of Knowledge Graphs
Introduction of Knowledge GraphsIntroduction of Knowledge Graphs
Introduction of Knowledge Graphs
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
 
Rdf data-model-and-storage
Rdf data-model-and-storageRdf data-model-and-storage
Rdf data-model-and-storage
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
온톨로지 개념 및 표현언어
온톨로지 개념 및 표현언어온톨로지 개념 및 표현언어
온톨로지 개념 및 표현언어
 
SHACL Overview
SHACL OverviewSHACL Overview
SHACL Overview
 
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)
 
Introduction to Knowledge Graphs and Semantic AI
Introduction to Knowledge Graphs and Semantic AIIntroduction to Knowledge Graphs and Semantic AI
Introduction to Knowledge Graphs and Semantic AI
 
Understanding RDF: the Resource Description Framework in Context (1999)
Understanding RDF: the Resource Description Framework in Context  (1999)Understanding RDF: the Resource Description Framework in Context  (1999)
Understanding RDF: the Resource Description Framework in Context (1999)
 
Knowledge Graph Introduction
Knowledge Graph IntroductionKnowledge Graph Introduction
Knowledge Graph Introduction
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
 
Semantic Web - Ontologies
Semantic Web - OntologiesSemantic Web - Ontologies
Semantic Web - Ontologies
 
SHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data MudSHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data Mud
 
SHACL in Apache jena - ApacheCon2020
SHACL in Apache jena - ApacheCon2020SHACL in Apache jena - ApacheCon2020
SHACL in Apache jena - ApacheCon2020
 

Ähnlich wie An Introduction to SPARQL

(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)Olaf Hartig
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...Olaf Hartig
 
An Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of DataAn Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of DataOlaf Hartig
 
The Semantics of SPARQL
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQLOlaf Hartig
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQLOlaf Hartig
 
Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)Olaf Hartig
 
A Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic WebA Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic WebShamod Lacoul
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic webMarakana Inc.
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLEmanuele Della Valle
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIsJosef Petrák
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1andreas_schultz
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011sesam4able
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011Robert Engels
 
Strabon: A Semantic Geospatial Database System
Strabon: A Semantic Geospatial Database SystemStrabon: A Semantic Geospatial Database System
Strabon: A Semantic Geospatial Database SystemKostis Kyzirakos
 
SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)andyseaborne
 
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPOpen Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPPieter De Leenheer
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Storesandyseaborne
 
SWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPINSWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPINNick Bassiliades
 

Ähnlich wie An Introduction to SPARQL (20)

(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
 
An Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of DataAn Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of Data
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
 
The Semantics of SPARQL
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQL
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQL
 
Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)
 
A Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic WebA Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic Web
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic web
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
 
Strabon: A Semantic Geospatial Database System
Strabon: A Semantic Geospatial Database SystemStrabon: A Semantic Geospatial Database System
Strabon: A Semantic Geospatial Database System
 
SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
 
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPOpen Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
 
Ontologias - RDF
Ontologias - RDFOntologias - RDF
Ontologias - RDF
 
SWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPINSWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPIN
 

Mehr von Olaf Hartig

LDQL: A Query Language for the Web of Linked Data
LDQL: A Query Language for the Web of Linked DataLDQL: A Query Language for the Web of Linked Data
LDQL: A Query Language for the Web of Linked DataOlaf Hartig
 
A Context-Based Semantics for SPARQL Property Paths over the Web
A Context-Based Semantics for SPARQL Property Paths over the WebA Context-Based Semantics for SPARQL Property Paths over the Web
A Context-Based Semantics for SPARQL Property Paths over the WebOlaf Hartig
 
Rethinking Online SPARQL Querying to Support Incremental Result Visualization
Rethinking Online SPARQL Querying to Support Incremental Result VisualizationRethinking Online SPARQL Querying to Support Incremental Result Visualization
Rethinking Online SPARQL Querying to Support Incremental Result VisualizationOlaf Hartig
 
Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...
Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...
Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...Olaf Hartig
 
Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...
Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...
Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...Olaf Hartig
 
Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...
Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...
Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...Olaf Hartig
 
Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...
Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...
Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...Olaf Hartig
 
Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)
Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)
Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)Olaf Hartig
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...Olaf Hartig
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...Olaf Hartig
 
An Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and QueryAn Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and QueryOlaf Hartig
 
Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...
Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...
Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...Olaf Hartig
 
The Impact of Data Caching of on Query Execution for Linked Data
The Impact of Data Caching of on Query Execution for Linked DataThe Impact of Data Caching of on Query Execution for Linked Data
The Impact of Data Caching of on Query Execution for Linked DataOlaf Hartig
 
How Caching Improves Efficiency and Result Completeness for Querying Linked Data
How Caching Improves Efficiency and Result Completeness for Querying Linked DataHow Caching Improves Efficiency and Result Completeness for Querying Linked Data
How Caching Improves Efficiency and Result Completeness for Querying Linked DataOlaf Hartig
 
A Main Memory Index Structure to Query Linked Data
A Main Memory Index Structure to Query Linked DataA Main Memory Index Structure to Query Linked Data
A Main Memory Index Structure to Query Linked DataOlaf Hartig
 
Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...
Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...
Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...Olaf Hartig
 
Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)
Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)
Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)Olaf Hartig
 
Answers to usual issues in getting started with consuming Linked Data (2010)
Answers to usual issues in getting started with consuming Linked Data (2010)Answers to usual issues in getting started with consuming Linked Data (2010)
Answers to usual issues in getting started with consuming Linked Data (2010)Olaf Hartig
 
Linked Data on the Web
Linked Data on the WebLinked Data on the Web
Linked Data on the WebOlaf Hartig
 
Executing SPARQL Queries of the Web of Linked Data
Executing SPARQL Queries of the Web of Linked DataExecuting SPARQL Queries of the Web of Linked Data
Executing SPARQL Queries of the Web of Linked DataOlaf Hartig
 

Mehr von Olaf Hartig (20)

LDQL: A Query Language for the Web of Linked Data
LDQL: A Query Language for the Web of Linked DataLDQL: A Query Language for the Web of Linked Data
LDQL: A Query Language for the Web of Linked Data
 
A Context-Based Semantics for SPARQL Property Paths over the Web
A Context-Based Semantics for SPARQL Property Paths over the WebA Context-Based Semantics for SPARQL Property Paths over the Web
A Context-Based Semantics for SPARQL Property Paths over the Web
 
Rethinking Online SPARQL Querying to Support Incremental Result Visualization
Rethinking Online SPARQL Querying to Support Incremental Result VisualizationRethinking Online SPARQL Querying to Support Incremental Result Visualization
Rethinking Online SPARQL Querying to Support Incremental Result Visualization
 
Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...
Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...
Tutorial "Linked Data Query Processing" Part 5 "Query Planning and Optimizati...
 
Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...
Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...
Tutorial "Linked Data Query Processing" Part 4 "Execution Process" (WWW 2013 ...
 
Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...
Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...
Tutorial "Linked Data Query Processing" Part 3 "Source Selection Strategies" ...
 
Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...
Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...
Tutorial "Linked Data Query Processing" Part 2 "Theoretical Foundations" (WWW...
 
Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)
Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)
Tutorial "Linked Data Query Processing" Part 1 "Introduction" (WWW 2013 Ed.)
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 3 (...
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 1 (...
 
An Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and QueryAn Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and Query
 
Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...
Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...
Zero-Knowledge Query Planning for an Iterator Implementation of Link Traversa...
 
The Impact of Data Caching of on Query Execution for Linked Data
The Impact of Data Caching of on Query Execution for Linked DataThe Impact of Data Caching of on Query Execution for Linked Data
The Impact of Data Caching of on Query Execution for Linked Data
 
How Caching Improves Efficiency and Result Completeness for Querying Linked Data
How Caching Improves Efficiency and Result Completeness for Querying Linked DataHow Caching Improves Efficiency and Result Completeness for Querying Linked Data
How Caching Improves Efficiency and Result Completeness for Querying Linked Data
 
A Main Memory Index Structure to Query Linked Data
A Main Memory Index Structure to Query Linked DataA Main Memory Index Structure to Query Linked Data
A Main Memory Index Structure to Query Linked Data
 
Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...
Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...
Towards a Data-Centric Notion of Trust in the Semantic Web (A Position Statem...
 
Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)
Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)
Brief Introduction to the Provenance Vocabulary (for W3C prov-xg)
 
Answers to usual issues in getting started with consuming Linked Data (2010)
Answers to usual issues in getting started with consuming Linked Data (2010)Answers to usual issues in getting started with consuming Linked Data (2010)
Answers to usual issues in getting started with consuming Linked Data (2010)
 
Linked Data on the Web
Linked Data on the WebLinked Data on the Web
Linked Data on the Web
 
Executing SPARQL Queries of the Web of Linked Data
Executing SPARQL Queries of the Web of Linked DataExecuting SPARQL Queries of the Web of Linked Data
Executing SPARQL Queries of the Web of Linked Data
 

Kürzlich hochgeladen

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Kürzlich hochgeladen (20)

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

An Introduction to SPARQL

  • 1. SPARQL - Querying the Web of Data Seminar WS 2008/2009 An Introduction to SPARQL Olaf Hartig hartig@informatik.hu-berlin.de
  • 2. SPARQL in General SPARQL Protocol and RDF Query Language ● SPARQL Query Language for RDF ● Declarative ● Based on the RDF data model (triples/graph) ● Our focus ● SPARQL Query Results XML Format ● Representation of the results of SPARQL queries ● SPARQL Protocol for RDF ● Transmission of SPARQL queries and the results ● SPARQL endpoint: Web service that implements the ● protocol An Introduction to SPARQL 2
  • 3. Main Idea of SPARQL Queries Main idea: pattern matching ● Describe subgraphs of the queried RDF graph ● Subgraphs that match your description yield a result ● Mean: graph patterns (i.e. RDF graphs with variables) ● rdf:type ?v umbel-sc:Volcano An Introduction to SPARQL 3
  • 4. Main Idea of SPARQL Queries Queried graph: rdf:type dbpedia:Mount_Baker umbel-sc:Volcano p:lastEruption rdf:type quot;1880quot; dbpedia:Mount_Etna rdf:type ?v umbel-sc:Volcano Results: ?v dbpedia:Mount_Baker dbpedia:Mount_Etna An Introduction to SPARQL 4
  • 5. Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name An Introduction to SPARQL 5
  • 6. Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name Prologue: ● Prefix definitions enable CURIEs in the query ● Attention: No period (“.”) character to separate (as in N3) ● An Introduction to SPARQL 6
  • 7. Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name Result form specification: ● SELECT, DESCRIBE, CONSTRUCT, or ASK ● SELECT: - Variable list or asterisk (“*”) character for all ● - DISTINCT for disjoint results An Introduction to SPARQL 7
  • 8. Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name Dataset specification: ● Specify the dataset to be queried ● Use FROM and FROM NAMED clauses (each with a URI) ● An Introduction to SPARQL 8
  • 9. Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name Query Pattern: ● WHERE clause specifies the graph pattern to be matched ● An Introduction to SPARQL 9
  • 10. Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name Solution modifiers: ● Modify the result set, but not the single results ● ORDER BY, LIMIT, or OFFSET ● An Introduction to SPARQL 10
  • 11. Graph Patterns Different types of graph patterns for the query pattern ● (WHERE clause): Basic graph pattern (BGP) ● Group graph pattern ● Optional graph pattern ● Union graph pattern ● Graph graph pattern ● (Constraints) ● An Introduction to SPARQL 11
  • 12. Basic Graph Patterns Set of triple patterns (i.e. RDF triples with variables) ● Variable names prefixed with “?” or “$” (e.g. ?v, $v) ● PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdfs:label ?name . } An Introduction to SPARQL 12
  • 13. Basic Graph Patterns Set of triple patterns (i.e. RDF triples with variables) ● Variable names prefixed with “?” or “$” (e.g. ?v, $v) ● Turtle syntax (similar to N3) ● Syntactical sugar as in N3 (e.g. property and object lists) ● PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . } An Introduction to SPARQL 13
  • 14. Basic Graph Patterns Data* dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: What are the names of all (known) volcanos? ● Result: Query* SELECT ?name WHERE { ?name ?v rdf:type umbel-sc:Volcano ; quot;Etnaquot; rdfs:label ?name . } quot;Бееренбергquot;@ru quot;Beerenbergquot;@en *Prefix definitions omitted An Introduction to SPARQL 14
  • 15. Basic Graph Patterns Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: List all types of the volcano called “Beerenberg” ● Query SELECT ?type WHERE { ?type ?v rdf:type ?type ; rdfs:label quot;Beerenbergquot; . } An Introduction to SPARQL 15
  • 16. Basic Graph Patterns Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: List all types of the volcano called “Beerenberg” ● Query SELECT ?type WHERE { ?v rdf:type ?type ; ?type rdfs:label quot;Beerenbergquot;@en . umbel-sc:Volcano } umbel-sc:NaturalElevation An Introduction to SPARQL 16
  • 17. Basic Graph Patterns Data dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; p:location dbpedia:United_States . dbpedia:United_States rdfs:label quot;United Statesquot; . Question: Where are all (known) volcanos located? List ● the names. Blank nodes in SPARQL queries ● Permitted as subject and object of a triple pattern ● Like non-selectable variables ● Query SELECT ?name WHERE { ?name _:x rdf:type umbel-sc:Volcano ; quot;United Statesquot; p:location [ rdfs:label ?name ] . } An Introduction to SPARQL 17
  • 18. Basic Graph Patterns Data dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; p:location [ rdfs:label quot;United Statesquot;@en , quot;États-Unisquot;@fr ] . dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; p:location [ rdfs:label quot;Italyquot; ] . Blank nodes in the queried graph ● Blank node identifiers may occur in the results ● Query SELECT ?l ?name WHERE { ?l ?name ?v rdf:type umbel-sc:Volcano ; _:x quot;United Statesquot;@en p:location ?l . _:x quot;États-Unisquot;@fr ?l rdfs:label ?name . _:y quot;Italyquot; } An Introduction to SPARQL 18
  • 19. Optional Graph Patterns Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en . Question: What are all (known) volcanos and their names? ● Query SELECT ?v ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . } ?v ?name Problem: Mount ● dbpedia:Mount_Etna quot;Etnaquot; Baker missing dbpedia:Beerenberg quot;Beerenbergquot;@en (it has no name) An Introduction to SPARQL 19
  • 20. Optional Graph Patterns Keyword OPTIONAL allows for optional patterns ● Query SELECT ?v ?name WHERE { ?v rdf:type umbel-sc:Volcano . OPTIONAL { ?v rdfs:label ?name } } ?v ?name dbpedia:Mount_Etna quot;Etnaquot; dbpedia:Mount_Baker dbpedia:Beerenberg quot;Beerenbergquot;@en Optional patterns may yield unbound variables ● An Introduction to SPARQL 20
  • 21. Union Graph Patterns Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; ; p:location dbpedia:Italy . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; p:location dbpedia:United_States . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en ; p:location dbpedia:Norway . Question: What volcanos are located in the Italy or in ● Norway? Query SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; ? p:location .} An Introduction to SPARQL 21
  • 22. Union Graph Patterns Union graph patterns allow for alternatives ● Query SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano ; Semantically p:location dbpedia:Italy } equivalent UNION { ?v rdf:type umbel-sc:Volcano ; p:location dbpedia:Norway } } SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . { ?v p:location dbpedia:Italy } UNION { ?v p:location dbpedia:Norway } Query } An Introduction to SPARQL 22
  • 23. Group Graph Patterns SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . { ?v p:location dbpedia:Italy } UNION { ?v p:location dbpedia:Norway } Query } Semantically equivalent SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano } { { ?v p:location dbpedia:Italy } UNION { ?v p:location dbpedia:Norway } } Query } An Introduction to SPARQL 23
  • 24. Constraints Constraints filter solutions ● Keyword FILTER followed by expression ● Filter expressions contain operators and functions ● PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> PREFIX p: <http://dbpedia.org/property/> SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; p:lastEruption ?le . FILTER ( ?le > 1900 ) } An Introduction to SPARQL 24
  • 25. Constraints Operators and functions operate on RDF terms ● Filter expressions evaluate to true, false, or error ● Truth table: ● A B A || B A && B T T T T T F T F F T T F F F F F T E T E E T T E F E E F E F E F E E E E An Introduction to SPARQL 25
  • 26. Constraints Unary operators: ● Operator Type(A) Result type !A xsd:boolean xsd:boolean +A numeric numeric -A numeric numeric BOUND(A) variable xsd:boolean isURI(A) RDF term xsd:boolean isBLANK(A) RDF term xsd:boolean isLITERAL(A) RDF term xsd:boolean STR(A) literal / URI simple literal LANG(A) literal simple literal DATATYPE(A) literal simple literal An Introduction to SPARQL 26
  • 27. Constraints Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: List all types of the volcano called “Beerenberg” ● ?type Query SELECT ?type WHERE { umbel-sc:Volcano ?v rdf:type ?type ; umbel-sc:NaturalElevation rdfs:label ?name . FILTER ( STR(?name) = quot;Beerenbergquot; ) } An Introduction to SPARQL 27
  • 28. Constraints Binary operators: ● Logical connectives && and || for xsd:boolean ● Comparison operators =, !=, <, >, <=, and >= for numeric ● datatypes, xsd:dateTime, xsd:string, and xsd:boolean Comparison operators = and != for other datatypes ● Arithmetic operators +, -, *, and / for numeric datatypes ● Furthermore: ● REGEX(String,Pattern) or REGEX(String,Pattern,Flags) ● sameTERM(A,B) ● langMATCHES(A,B) ● An Introduction to SPARQL 28
  • 29. Constraints Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: What volcanos have an “e” in their name? ● Query SELECT ?v WHERE { ?v ?v rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdfs:label ?name . dbpedia:Beerenberg FILTER( REGEX(STR(?name),quot;equot;) ) } An Introduction to SPARQL 29
  • 30. Constraints Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: What volcanos have an “e” in their name? ● Query SELECT ?v WHERE { ?v ?v rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdfs:label ?name . dbpedia:Beerenberg FILTER( REGEX(STR(?name),quot;equot;,quot;iquot;) ) dbpedia:Beerenberg } An Introduction to SPARQL 30
  • 31. Negation Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: What volcanos do not have a name in our data? ● Query SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . ?v OPTIONAL { ?v rdfs:label ?name } dbpedia:Mount_Baker FILTER( ! BOUND(?name) ) } An Introduction to SPARQL 31
  • 32. Negation Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: What volcanos are not called “Beerenberg”? ● Query SELECT ?v WHERE { != ?v rdf:type umbel-sc:Volcano . rdfs:label ?name . ?v FILTER (STR(?name) != quot;Beerenbergquot;) dbpedia:Mount_Etna } dbpedia:Mount_Baker dbpedia:Beerenberg 32 An Introduction to SPARQL
  • 33. Negation Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . Question: What volcanos are not called “Beerenberg”? ● ?v Query SELECT ?v WHERE { dbpedia:Mount_Etna ?v rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker OPTIONAL { ?v rdfs:label ?name . FILTER (STR(?name) = quot;Beerenbergquot;) } FILTER ( ! BOUND(?name) ) Negation as Failure } An Introduction to SPARQL 33
  • 34. Graph Graph Patterns SPARQL queries are executed against an RDF dataset ● An RDF dataset comprises: ● One default graph and ● Zero or more named graphs (identified by an URI) ● Keyword GRAPH makes one of the named graphs the ● active graph used for pattern matching An Introduction to SPARQL 34
  • 35. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Default rdfs:label quot;Etnaquot; . Graph http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . http://example.org/d3 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en . An Introduction to SPARQL 35
  • 36. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . http://example.org/d3 dbpedia:Beerenberg SELECT ?v WHERE { rdf:type umbel-sc:Volcano ; GRAPH <http://example.org/d1> { rdfs:label quot;Beerenbergquot;@en . ?v rdf:type umbel-sc:Volcano . ?v } } dbpedia:Mount_Etna An Introduction to SPARQL 36
  • 37. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . http://example.org/d3 dbpedia:Beerenberg SELECT ?v WHERE { rdf:type umbel-sc:Volcano ; GRAPH ?g { ?v rdfs:label quot;Beerenbergquot;@en . ?v rdf:type umbel-sc:Volcano . dbpedia:Mount_Etna } dbpedia:Mount_Baker } dbpedia:Beerenberg An Introduction to SPARQL 37
  • 38. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . http://example.org/d3 dbpedia:Beerenberg SELECT ?v ?g WHERE { rdf:type umbel-sc:Volcano ; GRAPH ?g { ?v ?g rdfs:label quot;Beerenbergquot;@en . ?v rdf:type umbel-sc:Volcano . dbpedia:Mount_Etna <http://example.org/d1> } dbpedia:Mount_Baker <http://example.org/d2> } dbpedia:Beerenberg <http://example.org/d3> An Introduction to SPARQL 38
  • 39. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . SELECT ?v WHERE { http://example.org/d3 dbpedia:Beerenberg _:x rdfs:seeAlso ?g rdf:type umbel-sc:Volcano ; GRAPH ?g { rdfs:label quot;Beerenbergquot;@en . ?v rdf:type umbel-sc:Volcano . ?v } dbpedia:Mount_Etna } dbpedia:Mount_Baker An Introduction to SPARQL 39
  • 40. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . http://example.org/d3 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en . Question: Which named graphs contain the name of a ● volcano that is not referenced in the default graph? An Introduction to SPARQL 40
  • 41. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . SELECT ?g WHERE { dbpedia:Mount_Baker http://example.org/d2 GRAPH ?g { rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano ; http://example.org/d3 dbpedia:Beerenberg rdfs:label ?name . rdf:type umbel-sc:Volcano ; } rdfs:label quot;Beerenbergquot;@en . OPTIONAL { ?v rdfs:seeAlso ?r } Question: ! BOUND(?r) ) graphs contain the name of a FILTER ( Which named ● volcano that is not referenced in the default graph? } An Introduction to SPARQL 41
  • 42. Summary – Graph Patterns Different types of graph patterns for the query pattern ● (WHERE clause): Basic graph pattern (BGP) ● Group graph pattern ● Optional graph pattern – keyword OPTIONAL ● Union graph pattern – keyword UNION ● Graph graph pattern – keyword GRAPH ● Constraints – keyword FILTER ● An Introduction to SPARQL 42
  • 43. Result Forms SELECT ● Sequence of results (i.e. sets of variable bindings) ● Selected variables separated by space (not by comma!) ● Asterisk (“*”) character selects all variables in the pattern ● ASK ● Check if there is at least one result ● Example: Do we have volcanos that do not have a name? ● Query ASK WHERE { ?v rdf:type umbel-sc:Volcano . OPTIONAL { ?v rdfs:label ?name } FILTER( ! BOUND(?name) ) } An Introduction to SPARQL 43
  • 44. Result Forms DESCRIBE ● Returns an RDF graph with data about resources ● Nondeterministic (i.e. query processor determines the ● actual structure of the returned RDF graph) Name the resource: ● Query DESCRIBE <http://dbpedia.org/resource/Beerenberg> Specify the resource with a query pattern: ● Query DESCRIBE ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . FILTER ( STR(?name) = quot;Beerenbergquot; ) } Multiple variables possible or asterisk (“*”) for all ● An Introduction to SPARQL 44
  • 45. Result Forms CONSTRUCT ● Returns an RDF graph created from a template ● Template: graph pattern with variables from the query ● pattern Query CONSTRUCT { ?v rdfs:label ?name ; rdf:type myTypes:VolcanosOutsideTheUS } WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . OPTIONAL { ?v p:location ?l FILTER ( ?l = dbpedia:United_States ) } FILTER ( ! BOUND(?l) ) } An Introduction to SPARQL 45
  • 46. Result Forms Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; ; p:location dbpedia:Italy . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; rdfs:label quot;Mount Bakerquot; ; p:location dbpedia:United_States . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label quot;Beerenbergquot;@en ; p:location dbpedia:Norway . Result dbpedia:Mount_Etna rdfs:label quot;Etnaquot; ; rdf:type myTypes:VolcanosOutsideTheUS. dbpedia:Beerenberg rdf:type myTypes:VolcanosOutsideTheUS; rdfs:label quot;Beerenbergquot;@en . An Introduction to SPARQL 46
  • 47. Solution Modifiers Modify the result set, but not the single results ● Permitted for SELECT queries only ● DISTINCT ● ORDER BY ● LIMIT ● OFFSET ● An Introduction to SPARQL 47
  • 48. Solution Modifiers DISTINCT – removes duplicates from the result set ● Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . ?type Query SELECT ?type umbel-sc:Volcano WHERE { _:x rdf:type ?type } umbel-sc:Volcano umbel-sc:NaturalElevation umbel-sc:Volcano An Introduction to SPARQL 48
  • 49. Solution Modifiers DISTINCT – removes duplicates from the result set ● Data dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label quot;Etnaquot; . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label quot;Beerenbergquot;@en ; rdfs:label quot;Бееренбергquot;@ru . ?type Query SELECT DISTINCT ?type umbel-sc:Volcano WHERE { _:x rdf:type ?type } umbel-sc:NaturalElevation An Introduction to SPARQL 49
  • 50. Solution Modifiers ORDER BY – orders the results ● Query SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } ORDER BY ?name Order for different kinds of elements: ● unbound variable < blank node < URI < literal ASC for ascending (default) and DESC for descending ● Hierarchical order criteria: ● SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query p:lastEruption ?le ; rdfs:label ?name } ORDER BY DESC(?le), ?name An Introduction to SPARQL 50
  • 51. Solution Modifiers LIMIT – limits the number of results ● SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query rdfs:label ?name } ORDER BY ?name LIMIT 5 OFFSET – position/index of the first returned results ● SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query rdfs:label ?name } ORDER BY ?name LIMIT 5 OFFSET 10 Only useful if the order is predictable (i.e. ordered results) ● An Introduction to SPARQL 51
  • 52. Further Reading W3C RDF Data Access Working Group ● http://www.w3.org/2001/sw/DataAccess/ SPARQL Query Language for RDF ● SPARQL Protocol for RDF ● SPARQL Query Results XML Format ● SPARQL interface ● for dbpedia: http://dbpedia.org/snorql/ An Introduction to SPARQL 52