SlideShare a Scribd company logo
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

More Related Content

What's hot

SPARQL Tutorial
SPARQL TutorialSPARQL Tutorial
SPARQL Tutorial
Leigh Dodds
 
Jena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for JavaJena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for Java
Aleksander Pohl
 
Relational Database to RDF (RDB2RDF)
Relational Database to RDF (RDB2RDF)Relational Database to RDF (RDB2RDF)
Relational Database to RDF (RDB2RDF)
EUCLID project
 
RDF 개념 및 구문 소개
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개
Dongbum Kim
 
Graph and RDF databases
Graph and RDF databasesGraph and RDF databases
Graph and RDF databases
Nassim Bahri
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
Fabien Gandon
 
Debunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsDebunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative Facts
Neo4j
 
Slides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property GraphsSlides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property Graphs
DATAVERSITY
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)
Ameer Sameer
 
RDF and OWL
RDF and OWLRDF and OWL
RDF and OWL
Rachel Lovinger
 
Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -
Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -
Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -
Dongbum Kim
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
Adriel Café
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
Mariano Rodriguez-Muro
 
Apache Spark Introduction
Apache Spark IntroductionApache Spark Introduction
Apache Spark Introduction
sudhakara st
 
What Is RDD In Spark? | Edureka
What Is RDD In Spark? | EdurekaWhat Is RDD In Spark? | Edureka
What Is RDD In Spark? | Edureka
Edureka!
 
Spark DataFrames and ML Pipelines
Spark DataFrames and ML PipelinesSpark DataFrames and ML Pipelines
Spark DataFrames and ML Pipelines
Databricks
 
RDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic RepositoriesRDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic Repositories
Marin Dimitrov
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
Jose Emilio Labra Gayo
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
Dr Sukhpal Singh Gill
 
RDFS In A Nutshell V1
RDFS In A Nutshell V1RDFS In A Nutshell V1
RDFS In A Nutshell V1
Fabien Gandon
 

What's hot (20)

SPARQL Tutorial
SPARQL TutorialSPARQL Tutorial
SPARQL Tutorial
 
Jena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for JavaJena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for Java
 
Relational Database to RDF (RDB2RDF)
Relational Database to RDF (RDB2RDF)Relational Database to RDF (RDB2RDF)
Relational Database to RDF (RDB2RDF)
 
RDF 개념 및 구문 소개
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개
 
Graph and RDF databases
Graph and RDF databasesGraph and RDF databases
Graph and RDF databases
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 
Debunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsDebunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative Facts
 
Slides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property GraphsSlides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property Graphs
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)
 
RDF and OWL
RDF and OWLRDF and OWL
RDF and OWL
 
Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -
Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -
Linked Data의 RDF 어휘 이해하고 체험하기 - FOAF, SIOC, SKOS를 중심으로 -
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
 
Apache Spark Introduction
Apache Spark IntroductionApache Spark Introduction
Apache Spark Introduction
 
What Is RDD In Spark? | Edureka
What Is RDD In Spark? | EdurekaWhat Is RDD In Spark? | Edureka
What Is RDD In Spark? | Edureka
 
Spark DataFrames and ML Pipelines
Spark DataFrames and ML PipelinesSpark DataFrames and ML Pipelines
Spark DataFrames and ML Pipelines
 
RDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic RepositoriesRDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic Repositories
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
 
RDFS In A Nutshell V1
RDFS In A Nutshell V1RDFS In A Nutshell V1
RDFS In A Nutshell V1
 

Similar to 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 Data
Olaf Hartig
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
Mariano Rodriguez-Muro
 
The Semantics of SPARQL
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQL
Olaf Hartig
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQL
Olaf 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 Web
Shamod 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 web
Marakana Inc.
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
Emanuele 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 APIs
Josef Petrák
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1
andreas_schultz
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
Robert Engels
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
sesam4able
 
Strabon: A Semantic Geospatial Database System
Strabon: A Semantic Geospatial Database SystemStrabon: A Semantic Geospatial Database System
Strabon: A Semantic Geospatial Database System
Kostis 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 / SOAP
Pieter De Leenheer
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
andyseaborne
 
Ontologias - RDF
Ontologias - RDFOntologias - RDF
Ontologias - RDF
elliando dias
 
SWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPINSWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPIN
Nick Bassiliades
 

Similar to 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
 

More from 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 Data
Olaf 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 Web
Olaf 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 Visualization
Olaf 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 Query
Olaf 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 Data
Olaf 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 Data
Olaf 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 Data
Olaf 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 Web
Olaf 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 Data
Olaf Hartig
 

More from 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
 

Recently uploaded

Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
maazsz111
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 

Recently uploaded (20)

Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 

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