SlideShare une entreprise Scribd logo
1  sur  76
Télécharger pour lire hors ligne
ICWE 2012 Tutorial

An Introduction to SPARQL and
   Queries over Linked Data
                    ●●●




     Chapter 2: SPARQL
                                          Olaf Hartig
                          http://olafhartig.de/foaf.rdf#olaf
                                                @olafhartig

      Database and Information Systems Research Group
                          Humboldt-Universität zu Berlin
SPARQL in General
 ●   A family of W3C recommendations
 ●   SPARQL Query
     ●   Declarative query language for RDF data
     ●   Our focus today
 ●   SPARQL Update
     ●   Declarative update language for RDF data
 ●   SPARQL Protocol
     ●   Communication between SPARQL processing
         services (a.k.a. SPARQL endpoints) and clients
 ●   SPARQL Query Results XML Format
     ●   XML format for serializing query results
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   2
Main Idea of SPARQL Queries
 ●   Pattern matching:
     ●   Describe subgraphs of the queried RDF graph
     ●   Subgraphs that match your description contribute an answer
     ●   Mean: graph patterns (i.e. RDF graphs with variables)




                                    ?v                 rdf:type
                                                                         umbel-sc:Volcano




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   3
Main Idea of SPARQL Queries
 Queried RDF graph:

                                                              rdf:type
              dbpedia:Mount_Baker                                                 umbel-sc:Volcano
         p:lastEruption                                                                              rdf:type
                                           "1880"                            dbpedia:Mount_Etna


                                    ?v                 rdf:type
                                                                         umbel-sc:Volcano




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   4
Main Idea of SPARQL Queries
 Queried RDF graph:

                                                              rdf:type
              dbpedia:Mount_Baker                                                 umbel-sc:Volcano
         p:lastEruption                                                                              rdf:type
                                           "1880"                            dbpedia:Mount_Etna


                                    ?v                 rdf:type
                                                                         umbel-sc:Volcano
   Result:
                      ?v
   dbpedia:Mount_Baker
   dbpedia:Mount_Etna
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   5
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   6
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Prologue:
     ●   Prefix definitions for using compact URIs (CURIEs)
     ●   Attention (difference to Turtle): No period (“.”) character as
                                           separator
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   7
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Result form specification:
     ●   SELECT, DESCRIBE, CONSTRUCT, or ASK
         (more about that later)


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   8
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Dataset specification:
     ●   Specify the RDF dataset to be queried
         (more about that later)


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   9
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Query Pattern:
     ●   WHERE clause specifies the graph pattern to be matched



Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: 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)



Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   11
Basic Graph Patterns
 ●   Set of triple patterns (i.e. RDF triples with variables)
 ●   Variable names prefixed with “?” or “$” (e.g. ?v, $v)
 ●   Turtle syntax
     ●   Including syntactical sugar (e.g. property and object lists)
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT
 SELECT         ?name
                ?name
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
   ?v rdfs:label ?name .
   ?v rdfs:label ?name .
 }
 }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: 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
     ●   Including syntactical sugar (e.g. property and object lists)
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT
 SELECT         ?name
                ?name
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
      rdfs:label ?name .
      rdfs:label ?name .
 }
 }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   13
Basic Graph Patterns (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data*
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .




 *Prefix definitions omitted
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       14
Basic Graph Patterns (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data*
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●   Question: What are the names of all (known) volcanos?
 SELECT ?name WHERE {
 SELECT ?name WHERE {         Query*
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
            rdfs:label ?name . }
            rdfs:label ?name . }

 *Prefix definitions omitted
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       15
Basic Graph Patterns (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data*
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●Question: What are the names of all (known) volcanos?
                                          Result:
 SELECT ?name WHERE {
 SELECT ?name WHERE {         Query*
   ?v rdf:type umbel-sc:Volcano ;
                                                ?name
      ?v rdf:type umbel-sc:Volcano ;
         rdfs:label ?name . }
         rdfs:label ?name . }
                                                                                      "Etna"
                                                                                      "Бееренберг"@ru
 *Prefix definitions omitted                                                          "Beerenberg"@en
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       16
Basic Graph Patterns (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●   Question: List all types of the volcano called “Beerenberg”
 SELECT ?type WHERE {
 SELECT ?type WHERE {                                            Query
                                                                                                   ?type
   ?v rdf:type ?type ;
   ?v rdf:type ?type ;
            rdfs:label "Beerenberg" .
            rdfs:label "Beerenberg" .
 }
 }

                                                                                  Empty!
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      17
Basic Graph Patterns (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●   Question: List all types of the volcano called “Beerenberg”
 SELECT ?type WHERE {
 SELECT ?type WHERE {                                            Query
   ?v rdf:type ?type ;
   ?v rdf:type ?type ;                                                                       ?type
            rdfs:label "Beerenberg"@en .
            rdfs:label "Beerenberg"@en . umbel-sc:Volcano
 }
 }                                                                       umbel-sc:NaturalElevation
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      18
Basic Graph Patterns (Example)
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;      Data
                     p:location dbpedia:United_States .
                     p:location dbpedia:United_States .
 dbpedia:United_States rdfs:label "United States" .
 dbpedia:United_States rdfs:label "United States" .

 ●   Question: Where are all (known) volcanos located?
                          (List the names of these locations)




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   19
Basic Graph Patterns (Example)
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;      Data
                     p:location dbpedia:United_States .
                     p:location dbpedia:United_States .
 dbpedia:United_States rdfs:label "United States" .
 dbpedia:United_States rdfs:label "United States" .

 ●   Question: Where are all (known) volcanos located?
                          (List the names of these locations)
 ●   Blank nodes in SPARQL queries
     ●   As subject or object of a triple pattern
     ●   “Non-selectable” variables

 SELECT ?name WHERE {
 SELECT ?name WHERE {               Query
                                                                                                     ?name
  _:x rdf:type umbel-sc:Volcano ;
  _:x rdf:type umbel-sc:Volcano ;
                                                                                             "United States"
      p:location [ rdfs:label ?name ] . }
      p:location [ rdfs:label ?name ] . }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   20
Basic Graph Patterns (Example)
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;      Data
              p:location [ rdfs:label "United States"@en ,
              p:location [ rdfs:label "United States"@en ,
                                      "États-Unis"@fr ] .
                                      "États-Unis"@fr ] .
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                    p:location [ rdfs:label "Italy" ] .
                    p:location [ rdfs:label "Italy" ] .

 ●   Blank nodes in the queried data




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   21
Basic Graph Patterns (Example)
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;      Data
              p:location [ rdfs:label "United States"@en ,
              p:location [ rdfs:label "United States"@en ,
                                      "États-Unis"@fr ] .
                                      "États-Unis"@fr ] .
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
                    p:location [ rdfs:label "Italy" ] .
                    p:location [ rdfs:label "Italy" ] .

 ●   Blank nodes in the queried data
     ➔   Blank node identifiers may occur in the results
 SELECT ?l ?name WHERE {
 SELECT ?l ?name WHERE {    Query
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;                                           ?l                   ?name
        p:location
        p:location                 ?l .
                                   ?l .                                    _:x "United States"@en
     ?l rdfs:label
     ?l rdfs:label                 ?name .
                                   ?name .                                 _:x "États-Unis"@fr
 }                                                                         _:y "Italy"
 }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   22
Optional Graph Patterns
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label "Beerenberg"@en .
                                          rdfs:label "Beerenberg"@en .

 ●   Question: What are all (known) volcanos and their names?
 SELECT ?v ?name WHERE {
 SELECT ?v ?name WHERE {       Query
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
            rdfs:label ?name . }
            rdfs:label ?name . }
                                                              ?v                                  ?name
 ●   Problem: Mount
                                             dbpedia:Mount_Etna "Etna"
      Baker missing
                                             dbpedia:Beerenberg "Beerenberg"@en
      (it has no name)
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      23
Optional Graph Patterns
 ●   Keyword OPTIONAL allows for optional patterns
 SELECT ?v ?name WHERE {
 SELECT ?v ?name WHERE {       Query
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
     OPTIONAL { ?v rdfs:label ?name }
     OPTIONAL { ?v rdfs:label ?name }
 }
 }

                                                            ?v                                    ?name
                                        dbpedia:Mount_Etna                            "Etna"
                                        dbpedia:Mount_Baker
                                        dbpedia:Beerenberg                            "Beerenberg"@en
 ●   Optional patterns may result in unbound variables


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   24
Union Graph Patterns
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" ;
                    rdfs:label "Etna" ;
                    p:location dbpedia:Italy .
                    p:location dbpedia:Italy .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
                     p:location dbpedia:United_States .
                     p:location dbpedia:United_States .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label
                                          rdfs:label              "Beerenberg"@en ;
                                                                  "Beerenberg"@en ;
                                          p:location
                                          p:location              dbpedia:Norway .
                                                                  dbpedia:Norway .

 ●   Question: What volcanos are located in Italy or in Norway?
                               SELECT ?v WHERE {
                               SELECT ?v WHERE {             Query
                                 ?v rdf:type umbel-sc:Volcano ;
                                 ?v rdf:type umbel-sc:Volcano ;
                                          p:location
                                          p:location                    ?
                                                                        ?          . }
                                                                                   . }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      25
Union Graph Patterns
 ●   Union graph patterns allow for alternatives
     SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
     SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
                                          { ?v p:location dbpedia:Italy }
                                          { ?v p:location dbpedia:Italy }
                                          UNION
                                          UNION
                                          { ?v p:location dbpedia:Norway }
                                          { ?v p:location dbpedia:Norway }
     }
     }                                                                                              Query




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   26
Union Graph Patterns
 ●   Union graph patterns allow for alternatives
     SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
     SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
                                          { ?v p:location dbpedia:Italy }
                                          { ?v p:location dbpedia:Italy }
                                          UNION
                                          UNION
                                          { ?v p:location dbpedia:Norway }
                                          { ?v p:location dbpedia:Norway }
     }
     }                                                                                              Query
                                               SELECT
                                               SELECT         ?v WHERE
                                                              ?v WHERE            {
                                                                                  {             Query
                                                 { ?v
                                                 { ?v         rdf:type
                                                              rdf:type            umbel-sc:Volcano ;
                                                                                  umbel-sc:Volcano ;
                                                        p:location dbpedia:Italy }
                                                         p:location dbpedia:Italy }
         Semantically                              UNION
                                                   UNION
          equivalent                               { ?v rdf:type umbel-sc:Volcano
                                                   { ?v rdf:type umbel-sc:Volcano                               ;
                                                                                                                ;
                                                        p:location dbpedia:Norway
                                                        p:location dbpedia:Norway                               }
                                                                                                                }
                                               }
                                               }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       27
Group Graph Patterns
   SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
   SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano .
                     { ?v p:location dbpedia:Italy }
                     { ?v p:location dbpedia:Italy }
                                          UNION
                                          UNION
                                          { ?v p:location dbpedia:Norway }
                                          { ?v p:location dbpedia:Norway }
   }
   }                                                                                                            Query

                   Semantically equivalent

   SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano }
   SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano }
                                          { { ?v p:location dbpedia:Italy }
                                          { { ?v p:location dbpedia:Italy }
                                            UNION
                                            UNION
                                              { ?v p:location dbpedia:Norway } }
                                              { ?v p:location dbpedia:Norway } }
   }
   }                                                                                                            Query
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       28
Constraints on Solutions
 ●   Syntax: Keyword FILTER followed by filter expression
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 PREFIX p: <http://dbpedia.org/property/>
 PREFIX p: <http://dbpedia.org/property/>
 SELECT ?v
 SELECT ?v
 WHERE {
 WHERE {
     ?v rdf:type umbel-sc:Volcano ;
     ?v rdf:type umbel-sc:Volcano ;
        p:lastEruption ?le .
        p:lastEruption ?le .
     FILTER ( ?le > 1900 )
     FILTER ( ?le > 1900 )
 }
 }

 ●   Filter expressions contain operators and functions
 ●   Operators and functions operate on RDF terms
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   29
Constraints (Truth Table)
 ●   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

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   30
Unary Operators in Constraints

                     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


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   31
Constraints (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                             umbel-sc:NaturalElevation ;
                             umbel-sc:NaturalElevation ;
                    rdfs:label "Beerenberg"@en ;
                    rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●   Question: List all types of the volcano called “Beerenberg”
 SELECT ?type WHERE {
 SELECT ?type WHERE {                                                  Query
   ?v rdf:type ?type ;
   ?v rdf:type ?type ;
        rdfs:label ?name
        rdfs:label ?name                        .
                                                .
     FILTER ( STR(?name)
     FILTER ( STR(?name)                        = "Beerenberg" )
                                                = "Beerenberg" )
 }
 }

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      32
Constraints (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                             umbel-sc:NaturalElevation ;
                             umbel-sc:NaturalElevation ;
                    rdfs:label "Beerenberg"@en ;
                    rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●Question: List all types of the volcano called “Beerenberg”
 SELECT ?type WHERE {
 SELECT ?type WHERE {                Query     ?type
     ?v rdf:type ?type ;
     ?v rdf:type ?type ;            umbel-sc:Volcano
        rdfs:label ?name .
        rdfs:label ?name .
                                    umbel-sc:NaturalElevation
     FILTER ( STR(?name) = "Beerenberg" )
     FILTER ( STR(?name) = "Beerenberg" )
 }
 }

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      33
Constraints (Further Operators)
 ●   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)

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   34
Constraints (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                             umbel-sc:NaturalElevation ;
                             umbel-sc:NaturalElevation ;
                    rdfs:label "Beerenberg"@en ;
                    rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●   Question: What volcanos have an “e” in their name?
 SELECT ?v WHERE {
 SELECT ?v WHERE {             Query
                                                                                                     ?v
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
        rdfs:label ?name .                                                          dbpedia:Beerenberg
        rdfs:label ?name .
                                                                                    dbpedia:Beerenberg
     FILTER( REGEX(STR(?name),"e") )
     FILTER( REGEX(STR(?name),"e") )
 }
 }

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      35
Constraints (Example)
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                             umbel-sc:NaturalElevation ;
                             umbel-sc:NaturalElevation ;
                    rdfs:label "Beerenberg"@en ;
                    rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
 ●   Question: What volcanos have an “e” in their name?
 SELECT ?v WHERE {
 SELECT ?v WHERE {               Query
                                               ?v
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
      rdfs:label ?name .               dbpedia:Mount_Etna
      rdfs:label ?name .
                                                                                    dbpedia:Beerenberg
     FILTER( REGEX(STR(?name),"e","i") )
     FILTER( REGEX(STR(?name),"e","i") ) dbpedia:Beerenberg
 }
 }

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      36
Graph Graph Patterns




●   SPARQL queries
    are executed over
    an RDF dataset:
    ●   One default graph and
    ●   Zero or more named graphs (identified by an URI)
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   37
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                                           dbpedia:Beerenberg http://example.org/d3
                                           dbpedia:Beerenberg
●   SPARQL queries                              rdf:type umbel-sc:Volcano ;
                                                rdf:type umbel-sc:Volcano ;
    are executed over                                rdfs:label "Beerenberg"@en .
                                                     rdfs:label "Beerenberg"@en .
    an RDF dataset:
    ●   One default graph and
    ●   Zero or more named graphs (identified by an URI)
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   38
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Dataset specification:
     ●   Specify the RDF dataset to be queried
         (more about that later)


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   39
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Dataset specification:
     ●   Specify the RDF dataset to be queried
         (more about that later)                           here ...
 ●   Specification using FROM and FROM NAMED
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   40
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                                      dbpedia:Beerenberg
                                      dbpedia:Beerenberg   http://example.org/d3
                                           rdf:type umbel-sc:Volcano ;
                                           rdf:type umbel-sc:Volcano ;
                                                 rdfs:label "Beerenberg"@en .
                                                 rdfs:label "Beerenberg"@en .




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   41
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                                      dbpedia:Beerenberg
                                      dbpedia:Beerenberg   http://example.org/d3
                                           rdf:type umbel-sc:Volcano ;
                                           rdf:type umbel-sc:Volcano ;
                                                 rdfs:label "Beerenberg"@en .
                                                 rdfs:label "Beerenberg"@en .

 ●   Evaluation of patterns w.r.t. active graph
 ●   GRAPH clause for making a named graph the active graph
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   42
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                  dbpedia:Beerenberg    http://example.org/d3
 SELECT ?v WHERE { dbpedia:Beerenberg
 SELECT ?v WHERE {
                        rdf:type umbel-sc:Volcano ;
   GRAPH <http://example.org/d1> umbel-sc:Volcano ;
                        rdf:type
   GRAPH <http://example.org/d1> {{
                        rdfs:label "Beerenberg"@en .
                        rdfs:label "Beerenberg"@en .
     ?v rdf:type umbel-sc:Volcano .
     ?v rdf:type umbel-sc:Volcano .
   }
   }                                           ?v
 }
 }                                                                            dbpedia:Mount_Etna
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   43
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                  dbpedia:Beerenberg    http://example.org/d3
 SELECT ?v WHERE { dbpedia:Beerenberg
 SELECT ?v WHERE {
                        rdf:type umbel-sc:Volcano ;
                        rdf:type umbel-sc:Volcano ;
   GRAPH ?g {
   GRAPH ?g {                                   ?v
                        rdfs:label "Beerenberg"@en .
                        rdfs:label "Beerenberg"@en .
     ?v rdf:type umbel-sc:Volcano .
     ?v rdf:type umbel-sc:Volcano . dbpedia:Mount_Etna
   }
   }                                 dbpedia:Mount_Baker
 }
 }                                                                           dbpedia:Beerenberg
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   44
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                  dbpedia:Beerenberg
                   dbpedia:Beerenberg   http://example.org/d3
 SELECT ?v ?g WHERE {
 SELECT ?v ?g WHERE {
                        rdf:type umbel-sc:Volcano ;
                        rdf:type umbel-sc:Volcano ;
   GRAPH ?g {
   GRAPH ?g {             ?v                     ?g
                        rdfs:label "Beerenberg"@en .
                        rdfs:label "Beerenberg"@en .
     ?v rdf:type umbel-sc:Volcano .
     ?v rdf:type umbel-sc:Volcano . <http://example.org/d1>
                dbpedia:Mount_Etna
   }
   }            dbpedia:Mount_Baker <http://example.org/d2>
 }
 }                               dbpedia:Beerenberg                            <http://example.org/d3>
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   45
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                 dbpedia:Mount_Baker http://example.org/d2
                  dbpedia:Mount_Baker
                       rdf:type umbel-sc:Volcano .
                       rdf:type umbel-sc:Volcano .
 SELECT ?v WHERE {
 SELECT ?v WHERE {
                   dbpedia:Beerenberg
                   dbpedia:Beerenberg    http://example.org/d3
   _:x rdfs:seeAlso ?g
   _:x rdfs:seeAlso ?g
                        rdf:type umbel-sc:Volcano ;
                         rdf:type umbel-sc:Volcano ;
   GRAPH ?g {
   GRAPH ?g {
                        rdfs:label "Beerenberg"@en .
                         rdfs:label "Beerenberg"@en .
     ?v rdf:type umbel-sc:Volcano .
     ?v rdf:type umbel-sc:Volcano .                                                              ?v
     }
     }
                                                                             dbpedia:Mount_Etna
 }
 }                                                                           dbpedia:Mount_Baker
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   46
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label
                                          rdfs:label              "Beerenberg"@en
                                                                  "Beerenberg"@en                   ;
                                                                                                    ;
                                          rdfs:label
                                          rdfs:label              "Бееренберг"@ru
                                                                  "Бееренберг"@ru                   .
                                                                                                    .
 ●   Question: What volcanos do not have a name in our data?




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      47
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label
                                          rdfs:label              "Beerenberg"@en
                                                                  "Beerenberg"@en                   ;
                                                                                                    ;
                                          rdfs:label
                                          rdfs:label              "Бееренберг"@ru
                                                                  "Бееренберг"@ru                   .
                                                                                                    .
 ●   Question: What volcanos do not have a name in our data?
 SELECT ?v WHERE {
 SELECT ?v WHERE {             Query
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
     OPTIONAL { ?v rdfs:label ?name }          ?v
     OPTIONAL { ?v rdfs:label ?name }
     FILTER( ! BOUND(?name) )
     FILTER( ! BOUND(?name) )         dbpedia:Mount_Baker
 }
 }
                                                                              Negation as Failure
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      48
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label
                                          rdfs:label              "Beerenberg"@en
                                                                  "Beerenberg"@en                   ;
                                                                                                    ;
                                          rdfs:label
                                          rdfs:label              "Бееренберг"@ru
                                                                  "Бееренберг"@ru                   .
                                                                                                    .
 ●   Question: What volcanos are not called “Beerenberg”?




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      49
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label
                                          rdfs:label              "Beerenberg"@en
                                                                  "Beerenberg"@en                   ;
                                                                                                    ;
                                          rdfs:label
                                          rdfs:label              "Бееренберг"@ru
                                                                  "Бееренберг"@ru                   .
                                                                                                    .
 ●   Question: What volcanos are not called “Beerenberg”?
 SELECT ?v WHERE {
 SELECT ?v WHERE {                                                         Query
  ?v rdf:type umbel-sc:Volcano .
  ?v rdf:type umbel-sc:Volcano .
     rdfs:label ?name .
     rdfs:label ?name .
  FILTER (STR(?name) != "Beerenberg")
   FILTER (STR(?name) != "Beerenberg")
 }
 }

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      50
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                    Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                    rdfs:label
                                    rdfs:label           "Beerenberg"@en
                                                         "Beerenberg"@en              ;
                                                                                      ;
                                    rdfs:label
                                    rdfs:label           "Бееренберг"@ru
                                                         "Бееренберг"@ru              .
                                                                                      .
 ●   Question: What volcanos are not called “Beerenberg”?
 SELECT ?v WHERE {
 SELECT ?v WHERE {                                              Query
  ?v rdf:type umbel-sc:Volcano .
  ?v rdf:type umbel-sc:Volcano .
     rdfs:label ?name .
     rdfs:label ?name .
  FILTER (STR(?name) != "Beerenberg")           ?v
   FILTER (STR(?name) != "Beerenberg")
 }
 }
                                       dbpedia:Mount_Etna
                                                                                   dbpedia:Mount_Baker
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linkeddbpedia:Beerenberg 51
                                                                                   Data" - Chapter 2: SPARQL
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                    Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                    rdfs:label
                                    rdfs:label           "Beerenberg"@en
                                                         "Beerenberg"@en              ;
                                                                                      ;
                                    rdfs:label
                                    rdfs:label           "Бееренберг"@ru
                                                         "Бееренберг"@ru              .
                                                                                      .
 ●   Question: What volcanos are not called “Beerenberg”?
 SELECT ?v WHERE {
 SELECT ?v WHERE {                                              Query
  ?v rdf:type umbel-sc:Volcano .
  ?v rdf:type umbel-sc:Volcano .                                 !=
     rdfs:label ?name .
     rdfs:label ?name .
  FILTER (STR(?name) != "Beerenberg")           ?v
   FILTER (STR(?name) != "Beerenberg")
 }
 }
                                       dbpedia:Mount_Etna
                                                                                   dbpedia:Mount_Baker
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linkeddbpedia:Beerenberg 52
                                                                                   Data" - Chapter 2: SPARQL
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                    Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                    rdfs:label
                                    rdfs:label           "Beerenberg"@en
                                                         "Beerenberg"@en              ;
                                                                                      ;
                                    rdfs:label
                                    rdfs:label           "Бееренберг"@ru
                                                         "Бееренберг"@ru              .
                                                                                      .
 ●   Question: What volcanos are not called “Beerenberg”?
 SELECT ?v WHERE {
 SELECT ?v WHERE {                                              Query
  ?v rdf:type umbel-sc:Volcano .
  ?v rdf:type umbel-sc:Volcano .                                 !=
     rdfs:label ?name .
     rdfs:label ?name .
  FILTER (STR(?name) != "Beerenberg")           ?v
   FILTER (STR(?name) != "Beerenberg")
 }
 }
                                       dbpedia:Mount_Etna
                                                                                   dbpedia:Mount_Baker
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linkeddbpedia:Beerenberg 53
                                                                                   Data" - Chapter 2: SPARQL
Negation
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                                          rdfs:label
                                          rdfs:label              "Beerenberg"@en
                                                                  "Beerenberg"@en                   ;
                                                                                                    ;
                                          rdfs:label
                                          rdfs:label              "Бееренберг"@ru
                                                                  "Бееренберг"@ru                   .
                                                                                                    .
 ●Question: What volcanos are not called “Beerenberg”?
 SELECT ?v WHERE {
 SELECT ?v WHERE {
                                               ?v
                                            Query
     ?v rdf:type umbel-sc:Volcano .
     ?v rdf:type umbel-sc:Volcano .     dbpedia:Mount_Etna
     OPTIONAL { ?v rdfs:label ?name .
     OPTIONAL { ?v rdfs:label ?name .
                                        dbpedia:Mount_Baker
                FILTER (STR(?name) = "Beerenberg") }
                FILTER (STR(?name) = "Beerenberg") }
  FILTER ( ! BOUND(?name) )
   FILTER ( ! BOUND(?name) )
 }                                                                            Negation as Failure
 }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      54
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
                                    dbpedia:Mount_Baker http://example.org/d2
                                    dbpedia:Mount_Baker
                                         rdf:type umbel-sc:Volcano .
                                         rdf:type umbel-sc:Volcano .
                                      dbpedia:Beerenberg
                                      dbpedia:Beerenberg   http://example.org/d3
                                           rdf:type umbel-sc:Volcano ;
                                           rdf:type umbel-sc:Volcano ;
                                                 rdfs:label "Beerenberg"@en .
                                                 rdfs:label "Beerenberg"@en .
 ●   Question: Which named graphs contain the name of a
       volcano that is not referenced in the default graph?
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   55
Graph Graph Patterns
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
 dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>.
                                 dbpedia:Mount_Etna
                                 dbpedia:Mount_Etna   http://example.org/d1
                                      rdf:type umbel-sc:Volcano ;
                                      rdf:type umbel-sc:Volcano ;
 Default
                                            rdfs:label "Etna" .
                                            rdfs:label "Etna" .
 Graph
 SELECT ?g WHERE
 SELECT ?g WHERE    {
                    dbpedia:Mount_Baker http://example.org/d2
                    {dbpedia:Mount_Baker
   GRAPH ?g {
   GRAPH ?g {             rdf:type umbel-sc:Volcano .
                          rdf:type umbel-sc:Volcano .
        ?v rdf:type umbel-sc:Volcano ;
        ?v rdf:type umbel-sc:Volcano ;
                      dbpedia:Beerenberg
                      dbpedia:Beerenberg    http://example.org/d3
           rdfs:label ?name .
           rdfs:label ?name .
                           rdf:type umbel-sc:Volcano ;
                            rdf:type umbel-sc:Volcano ;
     }}
                           rdfs:label "Beerenberg"@en .
     OPTIONAL { ?v rdfs:seeAlso ?r } "Beerenberg"@en .
                            rdfs:label
      OPTIONAL { ?v rdfs:seeAlso ?r }
 ●   Question: ! BOUND(?r) ) graphs contain the name of a
     FILTER ( Which named
      FILTER ( ! BOUND(?r) )
 }
 }       volcano that is not referenced in the default graph?
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   56
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



Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   57
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Result form specification:
     ●   SELECT, DESCRIBE, CONSTRUCT, or ASK
         (more about that later)


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   58
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Result form specification:
     ●   SELECT, DESCRIBE, CONSTRUCT, or ASK
         (more about that later)
                   ^                                      here ...


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   59
Result Forms
 ●   SELECT
     ●   Result: sequence of solutions (i.e. sets of variable bindings)
     ●   Selected variables separated by space (not by comma!)
     ●   Asterisk character (“*”) selects all variables in the pattern




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   60
Result Forms
 ●   SELECT
     ●   Result: sequence of solutions (i.e. sets of variable bindings)
     ●   Selected variables separated by space (not by comma!)
     ●   Asterisk character (“*”) selects all variables in the pattern
 ●   ASK
     ●   Check whether there is at least one result
     ●   Result: true or false
     ●   Example: Do we have data about volcanos?
                               ASK WHERE {
                               ASK WHERE {                  Query
                                  ?v rdf:type umbel-sc:Volcano .
                                  ?v rdf:type umbel-sc:Volcano .
                               }
                               }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   61
Result Forms
 ●   DESCRIBE
     ●   Result: an RDF graph with data about resources
     ●   Non-deterministic (i.e. query processor defines the actual
                            structure of the resulting RDF graph)
     ●   Example: just name the resource
 DESCRIBE <http://dbpedia.org/resource/Beerenberg>
 DESCRIBE <http://dbpedia.org/resource/Beerenberg>                                                              Query




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       62
Result Forms
 ●   DESCRIBE
     ●   Result: an RDF graph with data about resources
     ●   Non-deterministic (i.e. query processor defines the actual
                            structure of the resulting RDF graph)
     ●   Example: just name the resource
 DESCRIBE <http://dbpedia.org/resource/Beerenberg>
 DESCRIBE <http://dbpedia.org/resource/Beerenberg>                                                              Query
     ●   Example: Specify the resource(s) with a query pattern
 DESCRIBE ?v WHERE {
 DESCRIBE ?v WHERE {                                                                                            Query
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
      rdfs:label ?name .
      rdfs:label ?name .                                                    }
                                                                            }
     ●   Multiple variables possible or asterisk (“*”) for all
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       63
Result Forms
 ●   CONSTRUCT
     ●   Result: an RDF graph constructed from a template
     ●   Template: graph pattern with variables from the query pattern




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   64
Result Forms
 ●   CONSTRUCT
     ●   Result: an RDF graph constructed from a template
     ●   Template: graph pattern with variables from the query pattern
 CONSTRUCT { ?v rdfs:label ?name ;
 CONSTRUCT { ?v rdfs:label ?name ;                  Query
                rdf:type myTypes:VolcanosOutsideTheUS
                rdf:type myTypes:VolcanosOutsideTheUS
 }
 }
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano ;
   ?v rdf:type umbel-sc:Volcano ;
      rdfs:label ?name .
      rdfs:label ?name .
         OPTIONAL { ?v p:location
         OPTIONAL { ?v p:location                          ?l
                                                           ?l
                    FILTER ( ?l =
                    FILTER ( ?l =                          dbpedia:United_States ) }
                                                           dbpedia:United_States ) }
         FILTER ( ! BOUND(?l) )
         FILTER ( ! BOUND(?l) )
 }
 }
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   65
Result Forms
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" ;
                    rdfs:label "Etna" ;
                    p:location dbpedia:Italy .
                    p:location dbpedia:Italy .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ;
                     rdfs:label "Mount Baker" ;
                     rdfs:label "Mount Baker" ;
                     p:location dbpedia:United_States .
                     p:location dbpedia:United_States .
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ;
                    rdfs:label "Beerenberg"@en ;
                    rdfs:label "Beerenberg"@en ;
                                          p:location dbpedia:Norway .
                                          p:location dbpedia:Norway .

 dbpedia:Mount_Etna rdfs:label "Etna" ;
 dbpedia:Mount_Etna rdfs:label "Etna" ;             Result
                    rdf:type myTypes:VolcanosOutsideTheUS.
                    rdf:type myTypes:VolcanosOutsideTheUS.
 dbpedia:Beerenberg rdf:type myTypes:VolcanosOutsideTheUS;
 dbpedia:Beerenberg rdf:type myTypes:VolcanosOutsideTheUS;
                    rdfs:label "Beerenberg"@en .
                    rdfs:label "Beerenberg"@en .
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      66
Components of SPARQL Queries
 PREFIX
 PREFIX         rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX
 PREFIX         umbel-sc: <http://umbel.org/umbel/sc/>
                umbel-sc: <http://umbel.org/umbel/sc/>
 SELECT ?v
 SELECT ?v
 FROM <http://example.org/myGeoData>
 FROM <http://example.org/myGeoData>
 WHERE {
 WHERE {
   ?v rdf:type umbel-sc:Volcano .
   ?v rdf:type umbel-sc:Volcano .
 }
 }
 ORDER BY ?name
 ORDER BY ?name

 ●   Solution modifiers:
     ●   Only for SELECT queries
     ●   Modify the result set as a whole (not single solutions)
     ●   Keywords: DISTINCT, ORDER BY, LIMIT, and OFFSET
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   67
Solution Modifiers
 ●   DISTINCT removes duplicates from the result set
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
                                                                                           ?type
 SELECT ?type
 SELECT ?type              Query
                                                                        umbel-sc:Volcano
 WHERE { _:x rdf:type ?type }
 WHERE { _:x rdf:type ?type }                                           umbel-sc:Volcano
                                                                        umbel-sc:NaturalElevation
                                                                        umbel-sc:Volcano
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      68
Solution Modifiers
 ●   DISTINCT removes duplicates from the result set
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;                                                                 Data
                    rdfs:label "Etna" .
                    rdfs:label "Etna" .
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano.
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
 dbpedia:Beerenberg rdf:type umbel-sc:Volcano,
                                                   umbel-sc:NaturalElevation ;
                                                   umbel-sc:NaturalElevation ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Beerenberg"@en ;
                                          rdfs:label "Бееренберг"@ru .
                                          rdfs:label "Бееренберг"@ru .
                                                                                           ?type
 SELECT DISTINCT ?type
 SELECT DISTINCT ?type     Query
                                                                        umbel-sc:Volcano
 WHERE { _:x rdf:type ?type }
 WHERE { _:x rdf:type ?type }                                           umbel-sc:NaturalElevation


Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL      69
Solution Modifiers
 ●   ORDER BY orders the results
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;                                                               Query
                      rdfs:label ?name }
                      rdfs:label ?name }
 ORDER BY ?name
 ORDER BY ?name




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       70
Solution Modifiers
 ●   ORDER BY orders the results
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;
 SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;                                                               Query
                      rdfs:label ?name }
                      rdfs:label ?name }
 ORDER BY ?name
 ORDER BY ?name
     ●   How do we order 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
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ;
                         p:lastEruption ?le ;
                         p:lastEruption ?le ;
                         rdfs:label ?name }
                         rdfs:label ?name }
 ORDER BY DESC(?le), ?name
 ORDER BY DESC(?le), ?name
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL       71
Solution Modifiers
 ●   LIMIT – limits the number of results
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ;
                         rdfs:label ?name }
                         rdfs:label ?name }
 ORDER
 ORDER        BY ?name
              BY ?name
 LIMIT
 LIMIT        5
              5




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   72
Solution Modifiers
 ●   LIMIT – limits the number of results
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ;
                         rdfs:label ?name }
                         rdfs:label ?name }
 ORDER
 ORDER        BY ?name
              BY ?name
 LIMIT
 LIMIT        5
              5
 ●   OFFSET – position/index of the first reported results
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query
 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ;
                         rdfs:label ?name }
                         rdfs:label ?name }
 ORDER
 ORDER        BY ?name
              BY ?name
 LIMIT
 LIMIT        5 OFFSET 10
              5 OFFSET 10
 ●   Order of result should be predictable
                        (i.e. combine with ORDER BY)
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   73
SPARQL 1.1
 ●   New features of SPARQL 1.1 Query:
     ●   Aggregate functions (e.g. COUNT, SUM, AVG)
     ●   Subqueries
     ●   Negation (EXISTS, NOT EXISTS, MINUS)
     ●   Assignments (e.g. BIND, SELECT expressions)
     ●   Property paths
     ●   Basic query federation (SERVICE, BINDINGS)
 ●   SPARQL 1.1 Update:
     ●   Graph update (INSERT DATA, DELETE DATA, INSERT,
                       DELETE, DELETE WHERE, LOAD, CLEAR)
     ●   Graph management (CREATE, DROP, COPY, MOVE, ADD)

Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   74
Outline

        Chapter 1:
          Linked Data and RDF
                                                                 No
                                                                      w:
        Chapter 2:            Ha
                                 nd
                                    s-o
          The SPARQL Query Language n

        Chapter 3:
          Querying Linked Data on the Web



                                    http://olafhartig.de/icwe.html
Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   75
These slides have been created by
                                      Olaf Hartig

                                             http://olafhartig.de


                     This work is licensed under a
       Creative Commons Attribution-Share Alike 3.0 License
           (http://creativecommons.org/licenses/by-sa/3.0/)




Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL   76

Contenu connexe

Tendances

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.
 
RDB2RDF, an overview of R2RML and Direct Mapping
RDB2RDF, an overview of R2RML and Direct MappingRDB2RDF, an overview of R2RML and Direct Mapping
RDB2RDF, an overview of R2RML and Direct Mapping
Boris Villazón-Terrazas
 
Hooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQLHooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQL
Samuel Lampa
 

Tendances (20)

NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
 
Linked Open Data - Masaryk University in Brno 8.11.2016
Linked Open Data - Masaryk University in Brno 8.11.2016Linked Open Data - Masaryk University in Brno 8.11.2016
Linked Open Data - Masaryk University in Brno 8.11.2016
 
Relational Database to RDF (RDB2RDF)
Relational Database to RDF (RDB2RDF)Relational Database to RDF (RDB2RDF)
Relational Database to RDF (RDB2RDF)
 
Mapping Relational Databases to Linked Data
Mapping Relational Databases to Linked DataMapping Relational Databases to Linked Data
Mapping Relational Databases to Linked Data
 
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic RepresentationGetty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
 
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
 
RDB2RDF Tutorial (R2RML and Direct Mapping) at ISWC 2013
RDB2RDF Tutorial (R2RML and Direct Mapping) at ISWC 2013RDB2RDF Tutorial (R2RML and Direct Mapping) at ISWC 2013
RDB2RDF Tutorial (R2RML and Direct Mapping) at ISWC 2013
 
Fine-grained Evaluation of SPARQL Endpoint Federation Systems
Fine-grained Evaluation of SPARQL Endpoint Federation SystemsFine-grained Evaluation of SPARQL Endpoint Federation Systems
Fine-grained Evaluation of SPARQL Endpoint Federation Systems
 
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
 
GDG Meets U event - Big data & Wikidata - no lies codelab
GDG Meets U event - Big data & Wikidata -  no lies codelabGDG Meets U event - Big data & Wikidata -  no lies codelab
GDG Meets U event - Big data & Wikidata - no lies codelab
 
Querying the Web of Data
Querying the Web of DataQuerying the Web of Data
Querying the Web of Data
 
RDB2RDF, an overview of R2RML and Direct Mapping
RDB2RDF, an overview of R2RML and Direct MappingRDB2RDF, an overview of R2RML and Direct Mapping
RDB2RDF, an overview of R2RML and Direct Mapping
 
Uplift – Generating RDF datasets from non-RDF data with R2RML
Uplift – Generating RDF datasets from non-RDF data with R2RMLUplift – Generating RDF datasets from non-RDF data with R2RML
Uplift – Generating RDF datasets from non-RDF data with R2RML
 
Hooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQLHooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQL
 
Wi2015 - Clustering of Linked Open Data - the LODeX tool
Wi2015 - Clustering of Linked Open Data - the LODeX toolWi2015 - Clustering of Linked Open Data - the LODeX tool
Wi2015 - Clustering of Linked Open Data - the LODeX tool
 
Spark Cassandra 2016
Spark Cassandra 2016Spark Cassandra 2016
Spark Cassandra 2016
 
Introduction to RDFa
Introduction to RDFaIntroduction to RDFa
Introduction to RDFa
 
Producing, publishing and consuming linked data - CSHALS 2013
Producing, publishing and consuming linked data - CSHALS 2013Producing, publishing and consuming linked data - CSHALS 2013
Producing, publishing and consuming linked data - CSHALS 2013
 
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OOVirtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
 
Linked Open Data Visualization
Linked Open Data VisualizationLinked Open Data Visualization
Linked Open Data Visualization
 

Similaire à Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (ICWE 2012 Ed.)

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
 

Similaire à Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (ICWE 2012 Ed.) (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)
 
An Introduction to SPARQL
An Introduction to SPARQLAn Introduction to SPARQL
An Introduction to SPARQL
 
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
 
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
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
 
SWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPINSWRL2SPIN: Converting SWRL to SPIN
SWRL2SPIN: Converting SWRL to SPIN
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
Linking the world with Python and Semantics
Linking the world with Python and SemanticsLinking the world with Python and Semantics
Linking the world with Python and Semantics
 
The Semantics of SPARQL
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQL
 
Semantic Variation Graphs the case for RDF & SPARQL
Semantic Variation Graphs the case for RDF & SPARQLSemantic Variation Graphs the case for RDF & SPARQL
Semantic Variation Graphs the case for RDF & SPARQL
 
Learning Commonalities in RDF and SPARQL
Learning Commonalities in RDF and SPARQLLearning Commonalities in RDF and SPARQL
Learning Commonalities in RDF and SPARQL
 
A Little SPARQL in your Analytics
A Little SPARQL in your AnalyticsA Little SPARQL in your Analytics
A Little SPARQL in your Analytics
 
XSLT+SPARQL: Scripting the Semantic Web with SPARQL embedded into XSLT styles...
XSLT+SPARQL: Scripting the Semantic Web with SPARQL embedded into XSLT styles...XSLT+SPARQL: Scripting the Semantic Web with SPARQL embedded into XSLT styles...
XSLT+SPARQL: Scripting the Semantic Web with SPARQL embedded into XSLT styles...
 
Data in RDF
Data in RDFData in RDF
Data in RDF
 
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
 
Sparql semantic information retrieval by
Sparql semantic information retrieval bySparql semantic information retrieval by
Sparql semantic information retrieval by
 
Querying Linked Data
Querying Linked DataQuerying Linked Data
Querying Linked Data
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 

Plus de 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
 
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
 

Plus de Olaf Hartig (20)

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.)
 
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
 
Using Web Data Provenance for Quality Assessment
Using Web Data Provenance for Quality AssessmentUsing Web Data Provenance for Quality Assessment
Using Web Data Provenance for Quality Assessment
 
Answers to usual issues in getting started with consuming Linked Data
Answers to usual issues in getting started with consuming Linked DataAnswers to usual issues in getting started with consuming Linked Data
Answers to usual issues in getting started with consuming Linked Data
 
Querying Trust in RDF Data with tSPARQL
Querying Trust in RDF Data with tSPARQLQuerying Trust in RDF Data with tSPARQL
Querying Trust in RDF Data with tSPARQL
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (ICWE 2012 Ed.)

  • 1. ICWE 2012 Tutorial An Introduction to SPARQL and Queries over Linked Data ●●● Chapter 2: SPARQL Olaf Hartig http://olafhartig.de/foaf.rdf#olaf @olafhartig Database and Information Systems Research Group Humboldt-Universität zu Berlin
  • 2. SPARQL in General ● A family of W3C recommendations ● SPARQL Query ● Declarative query language for RDF data ● Our focus today ● SPARQL Update ● Declarative update language for RDF data ● SPARQL Protocol ● Communication between SPARQL processing services (a.k.a. SPARQL endpoints) and clients ● SPARQL Query Results XML Format ● XML format for serializing query results Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 2
  • 3. Main Idea of SPARQL Queries ● Pattern matching: ● Describe subgraphs of the queried RDF graph ● Subgraphs that match your description contribute an answer ● Mean: graph patterns (i.e. RDF graphs with variables) ?v rdf:type umbel-sc:Volcano Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 3
  • 4. Main Idea of SPARQL Queries Queried RDF graph: rdf:type dbpedia:Mount_Baker umbel-sc:Volcano p:lastEruption rdf:type "1880" dbpedia:Mount_Etna ?v rdf:type umbel-sc:Volcano Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 4
  • 5. Main Idea of SPARQL Queries Queried RDF graph: rdf:type dbpedia:Mount_Baker umbel-sc:Volcano p:lastEruption rdf:type "1880" dbpedia:Mount_Etna ?v rdf:type umbel-sc:Volcano Result: ?v dbpedia:Mount_Baker dbpedia:Mount_Etna Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 5
  • 6. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 6
  • 7. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Prologue: ● Prefix definitions for using compact URIs (CURIEs) ● Attention (difference to Turtle): No period (“.”) character as separator Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 7
  • 8. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Result form specification: ● SELECT, DESCRIBE, CONSTRUCT, or ASK (more about that later) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 8
  • 9. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Dataset specification: ● Specify the RDF dataset to be queried (more about that later) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 9
  • 10. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Query Pattern: ● WHERE clause specifies the graph pattern to be matched Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: 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) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: 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) ● Turtle syntax ● Including syntactical sugar (e.g. property and object lists) PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT SELECT ?name ?name WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . ?v rdfs:label ?name . ?v rdfs:label ?name . } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: 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 ● Including syntactical sugar (e.g. property and object lists) PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT SELECT ?name ?name WHERE { WHERE { ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . rdfs:label ?name . } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 13
  • 14. Basic Graph Patterns (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data* rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . *Prefix definitions omitted Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 14
  • 15. Basic Graph Patterns (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data* rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ● Question: What are the names of all (known) volcanos? SELECT ?name WHERE { SELECT ?name WHERE { Query* ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . } rdfs:label ?name . } *Prefix definitions omitted Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 15
  • 16. Basic Graph Patterns (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data* rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ●Question: What are the names of all (known) volcanos? Result: SELECT ?name WHERE { SELECT ?name WHERE { Query* ?v rdf:type umbel-sc:Volcano ; ?name ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . } rdfs:label ?name . } "Etna" "Бееренберг"@ru *Prefix definitions omitted "Beerenberg"@en Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 16
  • 17. Basic Graph Patterns (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ● Question: List all types of the volcano called “Beerenberg” SELECT ?type WHERE { SELECT ?type WHERE { Query ?type ?v rdf:type ?type ; ?v rdf:type ?type ; rdfs:label "Beerenberg" . rdfs:label "Beerenberg" . } } Empty! Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 17
  • 18. Basic Graph Patterns (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ● Question: List all types of the volcano called “Beerenberg” SELECT ?type WHERE { SELECT ?type WHERE { Query ?v rdf:type ?type ; ?v rdf:type ?type ; ?type rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . umbel-sc:Volcano } } umbel-sc:NaturalElevation Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 18
  • 19. Basic Graph Patterns (Example) dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; Data p:location dbpedia:United_States . p:location dbpedia:United_States . dbpedia:United_States rdfs:label "United States" . dbpedia:United_States rdfs:label "United States" . ● Question: Where are all (known) volcanos located? (List the names of these locations) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 19
  • 20. Basic Graph Patterns (Example) dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; Data p:location dbpedia:United_States . p:location dbpedia:United_States . dbpedia:United_States rdfs:label "United States" . dbpedia:United_States rdfs:label "United States" . ● Question: Where are all (known) volcanos located? (List the names of these locations) ● Blank nodes in SPARQL queries ● As subject or object of a triple pattern ● “Non-selectable” variables SELECT ?name WHERE { SELECT ?name WHERE { Query ?name _:x rdf:type umbel-sc:Volcano ; _:x rdf:type umbel-sc:Volcano ; "United States" p:location [ rdfs:label ?name ] . } p:location [ rdfs:label ?name ] . } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 20
  • 21. Basic Graph Patterns (Example) dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; Data p:location [ rdfs:label "United States"@en , p:location [ rdfs:label "United States"@en , "États-Unis"@fr ] . "États-Unis"@fr ] . dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; p:location [ rdfs:label "Italy" ] . p:location [ rdfs:label "Italy" ] . ● Blank nodes in the queried data Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 21
  • 22. Basic Graph Patterns (Example) dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; Data p:location [ rdfs:label "United States"@en , p:location [ rdfs:label "United States"@en , "États-Unis"@fr ] . "États-Unis"@fr ] . dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; p:location [ rdfs:label "Italy" ] . p:location [ rdfs:label "Italy" ] . ● Blank nodes in the queried data ➔ Blank node identifiers may occur in the results SELECT ?l ?name WHERE { SELECT ?l ?name WHERE { Query ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; ?l ?name p:location p:location ?l . ?l . _:x "United States"@en ?l rdfs:label ?l rdfs:label ?name . ?name . _:x "États-Unis"@fr } _:y "Italy" } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 22
  • 23. Optional Graph Patterns dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ● Question: What are all (known) volcanos and their names? SELECT ?v ?name WHERE { SELECT ?v ?name WHERE { Query ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . } rdfs:label ?name . } ?v ?name ● Problem: Mount dbpedia:Mount_Etna "Etna" Baker missing dbpedia:Beerenberg "Beerenberg"@en (it has no name) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 23
  • 24. Optional Graph Patterns ● Keyword OPTIONAL allows for optional patterns SELECT ?v ?name WHERE { SELECT ?v ?name WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . OPTIONAL { ?v rdfs:label ?name } OPTIONAL { ?v rdfs:label ?name } } } ?v ?name dbpedia:Mount_Etna "Etna" dbpedia:Mount_Baker dbpedia:Beerenberg "Beerenberg"@en ● Optional patterns may result in unbound variables Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 24
  • 25. Union Graph Patterns dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" ; rdfs:label "Etna" ; p:location dbpedia:Italy . p:location dbpedia:Italy . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; p:location dbpedia:United_States . p:location dbpedia:United_States . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en ; "Beerenberg"@en ; p:location p:location dbpedia:Norway . dbpedia:Norway . ● Question: What volcanos are located in Italy or in Norway? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; p:location p:location ? ? . } . } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 25
  • 26. Union Graph Patterns ● Union graph patterns allow for alternatives SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . { ?v p:location dbpedia:Italy } { ?v p:location dbpedia:Italy } UNION UNION { ?v p:location dbpedia:Norway } { ?v p:location dbpedia:Norway } } } Query Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 26
  • 27. Union Graph Patterns ● Union graph patterns allow for alternatives SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . { ?v p:location dbpedia:Italy } { ?v p:location dbpedia:Italy } UNION UNION { ?v p:location dbpedia:Norway } { ?v p:location dbpedia:Norway } } } Query SELECT SELECT ?v WHERE ?v WHERE { { Query { ?v { ?v rdf:type rdf:type umbel-sc:Volcano ; umbel-sc:Volcano ; p:location dbpedia:Italy } p:location dbpedia:Italy } Semantically UNION UNION equivalent { ?v rdf:type umbel-sc:Volcano { ?v rdf:type umbel-sc:Volcano ; ; p:location dbpedia:Norway p:location dbpedia:Norway } } } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 27
  • 28. Group Graph Patterns SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . { ?v p:location dbpedia:Italy } { ?v p:location dbpedia:Italy } UNION UNION { ?v p:location dbpedia:Norway } { ?v p:location dbpedia:Norway } } } Query Semantically equivalent SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano } SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano } { { ?v p:location dbpedia:Italy } { { ?v p:location dbpedia:Italy } UNION UNION { ?v p:location dbpedia:Norway } } { ?v p:location dbpedia:Norway } } } } Query Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 28
  • 29. Constraints on Solutions ● Syntax: Keyword FILTER followed by filter expression PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> PREFIX p: <http://dbpedia.org/property/> PREFIX p: <http://dbpedia.org/property/> SELECT ?v SELECT ?v WHERE { WHERE { ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; p:lastEruption ?le . p:lastEruption ?le . FILTER ( ?le > 1900 ) FILTER ( ?le > 1900 ) } } ● Filter expressions contain operators and functions ● Operators and functions operate on RDF terms Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 29
  • 30. Constraints (Truth Table) ● 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 Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 30
  • 31. Unary Operators in Constraints 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 Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 31
  • 32. Constraints (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ● Question: List all types of the volcano called “Beerenberg” SELECT ?type WHERE { SELECT ?type WHERE { Query ?v rdf:type ?type ; ?v rdf:type ?type ; rdfs:label ?name rdfs:label ?name . . FILTER ( STR(?name) FILTER ( STR(?name) = "Beerenberg" ) = "Beerenberg" ) } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 32
  • 33. Constraints (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ●Question: List all types of the volcano called “Beerenberg” SELECT ?type WHERE { SELECT ?type WHERE { Query ?type ?v rdf:type ?type ; ?v rdf:type ?type ; umbel-sc:Volcano rdfs:label ?name . rdfs:label ?name . umbel-sc:NaturalElevation FILTER ( STR(?name) = "Beerenberg" ) FILTER ( STR(?name) = "Beerenberg" ) } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 33
  • 34. Constraints (Further Operators) ● 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) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 34
  • 35. Constraints (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ● Question: What volcanos have an “e” in their name? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . dbpedia:Beerenberg rdfs:label ?name . dbpedia:Beerenberg FILTER( REGEX(STR(?name),"e") ) FILTER( REGEX(STR(?name),"e") ) } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 35
  • 36. Constraints (Example) dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ● Question: What volcanos have an “e” in their name? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . dbpedia:Mount_Etna rdfs:label ?name . dbpedia:Beerenberg FILTER( REGEX(STR(?name),"e","i") ) FILTER( REGEX(STR(?name),"e","i") ) dbpedia:Beerenberg } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 36
  • 37. Graph Graph Patterns ● SPARQL queries are executed over an RDF dataset: ● One default graph and ● Zero or more named graphs (identified by an URI) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 37
  • 38. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg http://example.org/d3 dbpedia:Beerenberg ● SPARQL queries rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; are executed over rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . an RDF dataset: ● One default graph and ● Zero or more named graphs (identified by an URI) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 38
  • 39. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Dataset specification: ● Specify the RDF dataset to be queried (more about that later) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 39
  • 40. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Dataset specification: ● Specify the RDF dataset to be queried (more about that later) here ... ● Specification using FROM and FROM NAMED Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 40
  • 41. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg dbpedia:Beerenberg http://example.org/d3 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 41
  • 42. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg dbpedia:Beerenberg http://example.org/d3 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ● Evaluation of patterns w.r.t. active graph ● GRAPH clause for making a named graph the active graph Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 42
  • 43. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg http://example.org/d3 SELECT ?v WHERE { dbpedia:Beerenberg SELECT ?v WHERE { rdf:type umbel-sc:Volcano ; GRAPH <http://example.org/d1> umbel-sc:Volcano ; rdf:type GRAPH <http://example.org/d1> {{ rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ?v } } dbpedia:Mount_Etna Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 43
  • 44. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg http://example.org/d3 SELECT ?v WHERE { dbpedia:Beerenberg SELECT ?v WHERE { rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; GRAPH ?g { GRAPH ?g { ?v rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . dbpedia:Mount_Etna } } dbpedia:Mount_Baker } } dbpedia:Beerenberg Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 44
  • 45. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg dbpedia:Beerenberg http://example.org/d3 SELECT ?v ?g WHERE { SELECT ?v ?g WHERE { rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; GRAPH ?g { GRAPH ?g { ?v ?g rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . <http://example.org/d1> dbpedia:Mount_Etna } } dbpedia:Mount_Baker <http://example.org/d2> } } dbpedia:Beerenberg <http://example.org/d3> Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 45
  • 46. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . SELECT ?v WHERE { SELECT ?v WHERE { dbpedia:Beerenberg dbpedia:Beerenberg http://example.org/d3 _:x rdfs:seeAlso ?g _:x rdfs:seeAlso ?g rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; GRAPH ?g { GRAPH ?g { rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . ?v } } dbpedia:Mount_Etna } } dbpedia:Mount_Baker Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 46
  • 47. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos do not have a name in our data? Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 47
  • 48. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos do not have a name in our data? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . OPTIONAL { ?v rdfs:label ?name } ?v OPTIONAL { ?v rdfs:label ?name } FILTER( ! BOUND(?name) ) FILTER( ! BOUND(?name) ) dbpedia:Mount_Baker } } Negation as Failure Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 48
  • 49. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos are not called “Beerenberg”? Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 49
  • 50. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos are not called “Beerenberg”? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . rdfs:label ?name . rdfs:label ?name . FILTER (STR(?name) != "Beerenberg") FILTER (STR(?name) != "Beerenberg") } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 50
  • 51. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos are not called “Beerenberg”? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . rdfs:label ?name . rdfs:label ?name . FILTER (STR(?name) != "Beerenberg") ?v FILTER (STR(?name) != "Beerenberg") } } dbpedia:Mount_Etna dbpedia:Mount_Baker Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linkeddbpedia:Beerenberg 51 Data" - Chapter 2: SPARQL
  • 52. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos are not called “Beerenberg”? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . != rdfs:label ?name . rdfs:label ?name . FILTER (STR(?name) != "Beerenberg") ?v FILTER (STR(?name) != "Beerenberg") } } dbpedia:Mount_Etna dbpedia:Mount_Baker Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linkeddbpedia:Beerenberg 52 Data" - Chapter 2: SPARQL
  • 53. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ● Question: What volcanos are not called “Beerenberg”? SELECT ?v WHERE { SELECT ?v WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . != rdfs:label ?name . rdfs:label ?name . FILTER (STR(?name) != "Beerenberg") ?v FILTER (STR(?name) != "Beerenberg") } } dbpedia:Mount_Etna dbpedia:Mount_Baker Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linkeddbpedia:Beerenberg 53 Data" - Chapter 2: SPARQL
  • 54. Negation dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label rdfs:label "Beerenberg"@en "Beerenberg"@en ; ; rdfs:label rdfs:label "Бееренберг"@ru "Бееренберг"@ru . . ●Question: What volcanos are not called “Beerenberg”? SELECT ?v WHERE { SELECT ?v WHERE { ?v Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . dbpedia:Mount_Etna OPTIONAL { ?v rdfs:label ?name . OPTIONAL { ?v rdfs:label ?name . dbpedia:Mount_Baker FILTER (STR(?name) = "Beerenberg") } FILTER (STR(?name) = "Beerenberg") } FILTER ( ! BOUND(?name) ) FILTER ( ! BOUND(?name) ) } Negation as Failure } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 54
  • 55. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph dbpedia:Mount_Baker http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . dbpedia:Beerenberg dbpedia:Beerenberg http://example.org/d3 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . ● Question: Which named graphs contain the name of a volcano that is not referenced in the default graph? Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 55
  • 56. Graph Graph Patterns dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Etna rdfs:seeAlso <http://example.org/d1>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d2>. dbpedia:Mount_Etna dbpedia:Mount_Etna http://example.org/d1 rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; Default rdfs:label "Etna" . rdfs:label "Etna" . Graph SELECT ?g WHERE SELECT ?g WHERE { dbpedia:Mount_Baker http://example.org/d2 {dbpedia:Mount_Baker GRAPH ?g { GRAPH ?g { rdf:type umbel-sc:Volcano . rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg dbpedia:Beerenberg http://example.org/d3 rdfs:label ?name . rdfs:label ?name . rdf:type umbel-sc:Volcano ; rdf:type umbel-sc:Volcano ; }} rdfs:label "Beerenberg"@en . OPTIONAL { ?v rdfs:seeAlso ?r } "Beerenberg"@en . rdfs:label OPTIONAL { ?v rdfs:seeAlso ?r } ● Question: ! BOUND(?r) ) graphs contain the name of a FILTER ( Which named FILTER ( ! BOUND(?r) ) } } volcano that is not referenced in the default graph? Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 56
  • 57. 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 Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 57
  • 58. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Result form specification: ● SELECT, DESCRIBE, CONSTRUCT, or ASK (more about that later) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 58
  • 59. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Result form specification: ● SELECT, DESCRIBE, CONSTRUCT, or ASK (more about that later) ^ here ... Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 59
  • 60. Result Forms ● SELECT ● Result: sequence of solutions (i.e. sets of variable bindings) ● Selected variables separated by space (not by comma!) ● Asterisk character (“*”) selects all variables in the pattern Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 60
  • 61. Result Forms ● SELECT ● Result: sequence of solutions (i.e. sets of variable bindings) ● Selected variables separated by space (not by comma!) ● Asterisk character (“*”) selects all variables in the pattern ● ASK ● Check whether there is at least one result ● Result: true or false ● Example: Do we have data about volcanos? ASK WHERE { ASK WHERE { Query ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 61
  • 62. Result Forms ● DESCRIBE ● Result: an RDF graph with data about resources ● Non-deterministic (i.e. query processor defines the actual structure of the resulting RDF graph) ● Example: just name the resource DESCRIBE <http://dbpedia.org/resource/Beerenberg> DESCRIBE <http://dbpedia.org/resource/Beerenberg> Query Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 62
  • 63. Result Forms ● DESCRIBE ● Result: an RDF graph with data about resources ● Non-deterministic (i.e. query processor defines the actual structure of the resulting RDF graph) ● Example: just name the resource DESCRIBE <http://dbpedia.org/resource/Beerenberg> DESCRIBE <http://dbpedia.org/resource/Beerenberg> Query ● Example: Specify the resource(s) with a query pattern DESCRIBE ?v WHERE { DESCRIBE ?v WHERE { Query ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . rdfs:label ?name . } } ● Multiple variables possible or asterisk (“*”) for all Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 63
  • 64. Result Forms ● CONSTRUCT ● Result: an RDF graph constructed from a template ● Template: graph pattern with variables from the query pattern Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 64
  • 65. Result Forms ● CONSTRUCT ● Result: an RDF graph constructed from a template ● Template: graph pattern with variables from the query pattern CONSTRUCT { ?v rdfs:label ?name ; CONSTRUCT { ?v rdfs:label ?name ; Query rdf:type myTypes:VolcanosOutsideTheUS rdf:type myTypes:VolcanosOutsideTheUS } } WHERE { WHERE { ?v rdf:type umbel-sc:Volcano ; ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . rdfs:label ?name . OPTIONAL { ?v p:location OPTIONAL { ?v p:location ?l ?l FILTER ( ?l = FILTER ( ?l = dbpedia:United_States ) } dbpedia:United_States ) } FILTER ( ! BOUND(?l) ) FILTER ( ! BOUND(?l) ) } } Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 65
  • 66. Result Forms dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" ; rdfs:label "Etna" ; p:location dbpedia:Italy . p:location dbpedia:Italy . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; dbpedia:Mount_Baker rdf:type umbel-sc:Volcano ; rdfs:label "Mount Baker" ; rdfs:label "Mount Baker" ; p:location dbpedia:United_States . p:location dbpedia:United_States . dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; p:location dbpedia:Norway . p:location dbpedia:Norway . dbpedia:Mount_Etna rdfs:label "Etna" ; dbpedia:Mount_Etna rdfs:label "Etna" ; Result rdf:type myTypes:VolcanosOutsideTheUS. rdf:type myTypes:VolcanosOutsideTheUS. dbpedia:Beerenberg rdf:type myTypes:VolcanosOutsideTheUS; dbpedia:Beerenberg rdf:type myTypes:VolcanosOutsideTheUS; rdfs:label "Beerenberg"@en . rdfs:label "Beerenberg"@en . Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 66
  • 67. Components of SPARQL Queries PREFIX PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX PREFIX umbel-sc: <http://umbel.org/umbel/sc/> umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v SELECT ?v FROM <http://example.org/myGeoData> FROM <http://example.org/myGeoData> WHERE { WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdf:type umbel-sc:Volcano . } } ORDER BY ?name ORDER BY ?name ● Solution modifiers: ● Only for SELECT queries ● Modify the result set as a whole (not single solutions) ● Keywords: DISTINCT, ORDER BY, LIMIT, and OFFSET Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 67
  • 68. Solution Modifiers ● DISTINCT removes duplicates from the result set dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ?type SELECT ?type SELECT ?type Query umbel-sc:Volcano WHERE { _:x rdf:type ?type } WHERE { _:x rdf:type ?type } umbel-sc:Volcano umbel-sc:NaturalElevation umbel-sc:Volcano Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 68
  • 69. Solution Modifiers ● DISTINCT removes duplicates from the result set dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; Data rdfs:label "Etna" . rdfs:label "Etna" . dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. dbpedia:Beerenberg rdf:type umbel-sc:Volcano, dbpedia:Beerenberg rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Beerenberg"@en ; rdfs:label "Бееренберг"@ru . rdfs:label "Бееренберг"@ru . ?type SELECT DISTINCT ?type SELECT DISTINCT ?type Query umbel-sc:Volcano WHERE { _:x rdf:type ?type } WHERE { _:x rdf:type ?type } umbel-sc:NaturalElevation Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 69
  • 70. Solution Modifiers ● ORDER BY orders the results SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; Query rdfs:label ?name } rdfs:label ?name } ORDER BY ?name ORDER BY ?name Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 70
  • 71. Solution Modifiers ● ORDER BY orders the results SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; Query rdfs:label ?name } rdfs:label ?name } ORDER BY ?name ORDER BY ?name ● How do we order 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 SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; p:lastEruption ?le ; p:lastEruption ?le ; rdfs:label ?name } rdfs:label ?name } ORDER BY DESC(?le), ?name ORDER BY DESC(?le), ?name Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 71
  • 72. Solution Modifiers ● LIMIT – limits the number of results SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } rdfs:label ?name } ORDER ORDER BY ?name BY ?name LIMIT LIMIT 5 5 Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 72
  • 73. Solution Modifiers ● LIMIT – limits the number of results SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } rdfs:label ?name } ORDER ORDER BY ?name BY ?name LIMIT LIMIT 5 5 ● OFFSET – position/index of the first reported results SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; Query SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } rdfs:label ?name } ORDER ORDER BY ?name BY ?name LIMIT LIMIT 5 OFFSET 10 5 OFFSET 10 ● Order of result should be predictable (i.e. combine with ORDER BY) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 73
  • 74. SPARQL 1.1 ● New features of SPARQL 1.1 Query: ● Aggregate functions (e.g. COUNT, SUM, AVG) ● Subqueries ● Negation (EXISTS, NOT EXISTS, MINUS) ● Assignments (e.g. BIND, SELECT expressions) ● Property paths ● Basic query federation (SERVICE, BINDINGS) ● SPARQL 1.1 Update: ● Graph update (INSERT DATA, DELETE DATA, INSERT, DELETE, DELETE WHERE, LOAD, CLEAR) ● Graph management (CREATE, DROP, COPY, MOVE, ADD) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 74
  • 75. Outline Chapter 1: Linked Data and RDF No w: Chapter 2: Ha nd s-o The SPARQL Query Language n Chapter 3: Querying Linked Data on the Web http://olafhartig.de/icwe.html Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 75
  • 76. These slides have been created by Olaf Hartig http://olafhartig.de This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License (http://creativecommons.org/licenses/by-sa/3.0/) Olaf Hartig - ICWE 2012 Tutorial "An Introduction to SPARQL and Queries over Linked Data" - Chapter 2: SPARQL 76