Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
SPARQL 1.1

Andy Seaborne
SPARQL is ...
●   A standard query language for RDF
    –   And now with update of RDF stores
●   Product of W3C Process
        ●   Submissions
        ●   “members”
        ●   Working groups
        ●   Consensus (amongst the active participants)
●   Widely implemented
History 1.0
●   SPARQL 1.0
    –   Timescale: 2004 – 2008
        ●   2 years late
    –   Lots of choices for starting points
    –   Controversies
        ●   Syntax
        ●   Named graphs
        ●   Algebra
SPARQL 1.0 Example
@prefix person: <http://example/person/> .
@prefix foaf:   <http://xmlns.com/foaf/0.1/> .

person:A foaf:name "Alice" .
person:A foaf:mbox <mailto:alice@example.net> .
person:B foaf:name "Bob" .


PREFIX person: <http://example/person/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?n ?mailbox
WHERE
  { person:A foaf:mbox ?mailbox ;
             foaf:name ?n . }


----------------------------------------
| n       | mailbox                    |
========================================
| "Alice" | <mailto:alice@example.net> |
----------------------------------------
SPARQL 1.0 Example
@prefix dc:    <http://purl.org/dc/elements/1.1/> .
@prefix stock: <http://example.org/stock#> .

stock:book1   dc:title   "SPARQL Query Language Tutorial" .
stock:book2   dc:title   "SPARQL Query Language (2nd ed)" .
stock:book3   dc:title   "Moving from SQL to SPARQL" .
stock:book4   dc:title   "Applying XQuery" .

PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX stock: <http://example.org/stock#>

SELECT ?book ?title
{
  ?book dc:title ?title .
  FILTER (regex(?title, "SPARQL"))
}


--------------------------------------------------
| book        | title                            |
==================================================
| stock:book3 | "Moving from SQL to SPARQL"      |
| stock:book2 | "SPARQL Query Language (2nd ed)" |
| stock:book1 | "SPARQL Query Language Tutorial" |
--------------------------------------------------
SPARQL 1.0
●   Experimentation for new features started
    before the first standard was published
    –   But you can't wait until “completely complete”
●   Issues
    –   Counting
    –   Standard function library
    –   Hard-to-use negation
    –   Query only, no update
    –   Only a “note” about a JSON output
History 1.1
●   SPARQL 1.1
    –   Timescale : 2009 – 2013
        ●   2 years late …
    –   Controversies
        ●   Negation
        ●   Property paths
        ●   Graphs … REST ...
SPARQL 1.1
●
    SPARQL 1.1 Query
●   SPARQL 1.1 Update
●
    SPARQL 1.1 Protocol
●   SPARQL 1.1 Graph Store Protocol
●
    SPARQL 1.1 Service Description
●   SPARQL 1.1 Federated Query
●
    SPARQL 1.1 Query Results JSON Format
●   SPARQL 1.1 Query Results CSV and TSV Formats
●
    SPARQL Query Results XML Format
●
    SPARQL 1.1 Entailment Regimes
SPARQL 1.1
              The important bits (IMO)
●   SPARQL 1.1 Query
    –   Subqueries, aggregation
    –   negation
    –   property paths
    –   remote query
●   SPARQL 1.1 Update
●   SPARQL 1.1 Graph Store Protocol
SPARQL 1.1 Query Examples
PREFIX rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf:       <http://xmlns.com/foaf/0.1/>

SELECT ?name
{
  { SELECT ?x (count(*) AS ?count)
    { ?x foaf:knows ?y . }
    GROUP BY ?x
    HAVING (?count = 3)
  }
  ?x foaf:name ?name .
}


PREFIX rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf:       <http://xmlns.com/foaf/0.1/>

SELECT ?x
{ ?x rdf:type foaf:Person .
  FILTER NOT EXISTS { ?x foaf:name ?name }
}
Property Paths and Inference
      Class inference
PREFIX rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#>
PREFIX :       <http://example/>

SELECT ?s {
    ?s rdf:type ?T .
    ?T rdfs:subClassOf* :SomeClass .
}



       Property inference
PREFIX rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#>
PREFIX :       <http://example/>

SELECT * {
    ?s ?p ?o .
    ?p rdfs:subPropertyOf* :property .
}
SPARQL 1.1 Update
●   Fine grain graph manipulations
    –   Act on a “graph store”
    –   Add and remove graphs
    –   Act on the contents of graphs
    –   Quad centric
●   LOAD, DROP, CREATE
●   INSERT, DELETE
    –   Data and patterns
●   One request is multiple operations
Data Operations
PREFIX rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf:   <http://xmlns.com/foaf/0.1/>

DELETE DATA { <http://example/abc> foaf:name "DEF" . } ;

INSERT DATA { <http://example/abc> foaf:name "ABC" . } ;
Pattern Operations : DELETE-INSERT
     Pattern → Delete triples → Insert triples


 PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
 PREFIX vc:     <http://www.w3.org/2006/vcard/ns#>

 DELETE { ?p vc:fn ?x }
 INSERT { ?p foaf:name ?x }
 WHERE
 {
    ?p vc:fn ?x .
    ?p foaf:knows <http://example/#me> }
 }
SPARQL 1.1 Graph Store Protocol
●   Simple way to manage a store (RDF Dataset)
●   GET, PUT, POST, DELETE
●   Naming
    –   Same server
          http://server/store/graph1
    –   Different server
          http://server/store?graph=http://example/g1
          http://server/store?graph=http%3A//example/g1
          http://server/store?default
RESTful(ish) operation
 curl -T D.ttl --header 'Content-type: text/turtle' 
        http://server.com/store?graph=http%3A//example/g1




PUT /store?graph=http%3A//example/g1 HTTP/1.1
Host: server.com
Content-type: text/turtle

@prefix : <http://example/> .

:subject :pred1 1 ;

     :pred2 “hello” .
Digression: RDF 1.1
●   Work-in-progress
●   Incremental
●   Turtle, TriG, N-Triples, N-Quads
●   RDF Datasets (as SPARQL?)
●   Related: JSON-LD
JSON-LD
●   Links and semantics for the JSON ecosystem
●   Adds a "context" to map JSON to RDF
●   RDF → JSON-LD → RDF is lossless
{
    "@context": "http://json-ld.org/contexts/person.jsonld",
    "@id": "http://example.org/alice.foaf#me",
    "name": "Alice Hacker",
    "homepage": "http://example.org/alice",
}

@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://example.org/alice.foaf#me>
       foaf:name "Alice Hacker" ;
       foaf:homepage <http://example.org/alice> .
http://jena.apache.org/
Title:(asf_logo.eps)
Creator:Adobe Illustrator(R) 8.0
CreationDate:(10/20/99) (11:38 AM)
Apache Jena
●   Full Apache Project since May 2012
●   SPARQL 1.1
    –   Query
    –   Update
    –   Protocol
    –   Graph Store Protocol
Fuseki – SPARQL Server
           ●   SPARQL server
           ●   RDF native database
               –   ACID transactions
               –   Query timeout
           ●   Deployed live
Data Management
●   Web UI
●   curl / wget
●   SOH (SPARQL over HTTP)
    –   Scripts
    –   s-get, s-put, s-post, s-delete, s-query, s-update
Online
●   http://www.sparql.org/
    –   Fuseki running on Apache project hardware
●   Services
    –     SPARQL query validator
    –     SPARQL update validator
    –     RDF data validator
    –     IRI validator

More Related Content

SPARQL 1.1 Update (2013-03-05)

  • 2. SPARQL is ... ● A standard query language for RDF – And now with update of RDF stores ● Product of W3C Process ● Submissions ● “members” ● Working groups ● Consensus (amongst the active participants) ● Widely implemented
  • 3. History 1.0 ● SPARQL 1.0 – Timescale: 2004 – 2008 ● 2 years late – Lots of choices for starting points – Controversies ● Syntax ● Named graphs ● Algebra
  • 4. SPARQL 1.0 Example @prefix person: <http://example/person/> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . person:A foaf:name "Alice" . person:A foaf:mbox <mailto:alice@example.net> . person:B foaf:name "Bob" . PREFIX person: <http://example/person/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?n ?mailbox WHERE { person:A foaf:mbox ?mailbox ; foaf:name ?n . } ---------------------------------------- | n | mailbox | ======================================== | "Alice" | <mailto:alice@example.net> | ----------------------------------------
  • 5. SPARQL 1.0 Example @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix stock: <http://example.org/stock#> . stock:book1 dc:title "SPARQL Query Language Tutorial" . stock:book2 dc:title "SPARQL Query Language (2nd ed)" . stock:book3 dc:title "Moving from SQL to SPARQL" . stock:book4 dc:title "Applying XQuery" . PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX stock: <http://example.org/stock#> SELECT ?book ?title { ?book dc:title ?title . FILTER (regex(?title, "SPARQL")) } -------------------------------------------------- | book | title | ================================================== | stock:book3 | "Moving from SQL to SPARQL" | | stock:book2 | "SPARQL Query Language (2nd ed)" | | stock:book1 | "SPARQL Query Language Tutorial" | --------------------------------------------------
  • 6. SPARQL 1.0 ● Experimentation for new features started before the first standard was published – But you can't wait until “completely complete” ● Issues – Counting – Standard function library – Hard-to-use negation – Query only, no update – Only a “note” about a JSON output
  • 7. History 1.1 ● SPARQL 1.1 – Timescale : 2009 – 2013 ● 2 years late … – Controversies ● Negation ● Property paths ● Graphs … REST ...
  • 8. SPARQL 1.1 ● SPARQL 1.1 Query ● SPARQL 1.1 Update ● SPARQL 1.1 Protocol ● SPARQL 1.1 Graph Store Protocol ● SPARQL 1.1 Service Description ● SPARQL 1.1 Federated Query ● SPARQL 1.1 Query Results JSON Format ● SPARQL 1.1 Query Results CSV and TSV Formats ● SPARQL Query Results XML Format ● SPARQL 1.1 Entailment Regimes
  • 9. SPARQL 1.1 The important bits (IMO) ● SPARQL 1.1 Query – Subqueries, aggregation – negation – property paths – remote query ● SPARQL 1.1 Update ● SPARQL 1.1 Graph Store Protocol
  • 10. SPARQL 1.1 Query Examples PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name { { SELECT ?x (count(*) AS ?count) { ?x foaf:knows ?y . } GROUP BY ?x HAVING (?count = 3) } ?x foaf:name ?name . } PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x { ?x rdf:type foaf:Person . FILTER NOT EXISTS { ?x foaf:name ?name } }
  • 11. Property Paths and Inference Class inference PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX : <http://example/> SELECT ?s { ?s rdf:type ?T . ?T rdfs:subClassOf* :SomeClass . } Property inference PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX : <http://example/> SELECT * { ?s ?p ?o . ?p rdfs:subPropertyOf* :property . }
  • 12. SPARQL 1.1 Update ● Fine grain graph manipulations – Act on a “graph store” – Add and remove graphs – Act on the contents of graphs – Quad centric ● LOAD, DROP, CREATE ● INSERT, DELETE – Data and patterns ● One request is multiple operations
  • 13. Data Operations PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> DELETE DATA { <http://example/abc> foaf:name "DEF" . } ; INSERT DATA { <http://example/abc> foaf:name "ABC" . } ;
  • 14. Pattern Operations : DELETE-INSERT Pattern → Delete triples → Insert triples PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX vc: <http://www.w3.org/2006/vcard/ns#> DELETE { ?p vc:fn ?x } INSERT { ?p foaf:name ?x } WHERE { ?p vc:fn ?x . ?p foaf:knows <http://example/#me> } }
  • 15. SPARQL 1.1 Graph Store Protocol ● Simple way to manage a store (RDF Dataset) ● GET, PUT, POST, DELETE ● Naming – Same server http://server/store/graph1 – Different server http://server/store?graph=http://example/g1 http://server/store?graph=http%3A//example/g1 http://server/store?default
  • 16. RESTful(ish) operation curl -T D.ttl --header 'Content-type: text/turtle' http://server.com/store?graph=http%3A//example/g1 PUT /store?graph=http%3A//example/g1 HTTP/1.1 Host: server.com Content-type: text/turtle @prefix : <http://example/> . :subject :pred1 1 ; :pred2 “hello” .
  • 17. Digression: RDF 1.1 ● Work-in-progress ● Incremental ● Turtle, TriG, N-Triples, N-Quads ● RDF Datasets (as SPARQL?) ● Related: JSON-LD
  • 18. JSON-LD ● Links and semantics for the JSON ecosystem ● Adds a "context" to map JSON to RDF ● RDF → JSON-LD → RDF is lossless { "@context": "http://json-ld.org/contexts/person.jsonld", "@id": "http://example.org/alice.foaf#me", "name": "Alice Hacker", "homepage": "http://example.org/alice", } @prefix foaf: <http://xmlns.com/foaf/0.1/> . <http://example.org/alice.foaf#me> foaf:name "Alice Hacker" ; foaf:homepage <http://example.org/alice> .
  • 20. Apache Jena ● Full Apache Project since May 2012 ● SPARQL 1.1 – Query – Update – Protocol – Graph Store Protocol
  • 21. Fuseki – SPARQL Server ● SPARQL server ● RDF native database – ACID transactions – Query timeout ● Deployed live
  • 22. Data Management ● Web UI ● curl / wget ● SOH (SPARQL over HTTP) – Scripts – s-get, s-put, s-post, s-delete, s-query, s-update
  • 23. Online ● http://www.sparql.org/ – Fuseki running on Apache project hardware ● Services – SPARQL query validator – SPARQL update validator – RDF data validator – IRI validator