Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPARQL AN RDF Query Language. SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX.

Similar presentations


Presentation on theme: "SPARQL AN RDF Query Language. SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX."— Presentation transcript:

1 SPARQL AN RDF Query Language

2 SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX abc: SELECT ?capital ?country WHERE { ?x abc:cityname ?capital ; abc:isCapitalOf ?y. ?y abc:countryname ?country ; abc:isInContinent abc:Africa. }

3 SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX abc: SELECT ?capital ?country WHERE { ?x abc:cityname ?capital ; abc:isCapitalOf ?y. ?y abc:countryname ?country ; abc:isInContinent abc:Africa. }

4 SPARQL History Several RDF query languages were developed prior to SPARQL W3C RDF Data Access Working Group (DAWG) worked out SPARQL 2005-2008 Became a W3C recommendation in January 2008 with key documents: – http://www.w3.org/TR/rdf-sparql-query/ http://www.w3.org/TR/rdf-sparql-query/ – http://www.w3.org/TR/rdf-sparql-protocol/ http://www.w3.org/TR/rdf-sparql-protocol/ – http://www.w3.org/TR/rdf-sparql-XMLres/ Implementations for multiple programming languages available

5 SPARQL Query Forms SELECT – Returns all, or a subset of, the variables bound in a query pattern match. ASK – Returns a boolean indicating whether a query pattern matches or not. DESCRIBE – Returns an RDF graph that describes the resources found. CONSTRUCT – Returns an RDF graph constructed by substituting variables in a set of triple templates.

6 It’s Turtles all the way down Turtle (Terse RDF Triple Language ): − An RDF serialization − Triple representation of − Human-friendly alternative to RDF/XML @prefix person:. @prefix foaf:. Person:A foaf:name “Jek". Person:A foaf:mbox. Person:B foaf:name “Yuan". _:b foaf:name “Jeff". _:b foaf:mbox. A "hello world" of queries SELECT ?name WHERE { ?x foaf:name ?name } ------------- | name | ======== | “Jek” | | ”Yuan” | | ”Jeff” | ------------- “Jek” Blank Node

7 Matching RDF Literals @prefix dt:. @prefix ns:. @prefix :. @prefix xsd:. :x ns:p "cat"@en. :y ns:p "42"^^xsd:integer. :z ns:p "abc"^^dt:specialDatatype. SELECT ?v WHERE { ?v ?p "cat" } --------- | v | ===== SELECT ?v WHERE { ?v ?p "cat“@en } ---------------------------------- | v | =================== |http://example.org/ns#x | ---------------------------------- SELECT ?v WHERE { ?v ?p 42 } ---------------------------------- | V | =================== |http://example.org/ns#y | ---------------------------------- SELECT ?v WHERE { ?v ?p "abc dt:specialDatatype} ---------------------------------- | V | =================== |http://example.org/ns#z | ----------------------------------

8 Filter @prefix dc:. @prefix stock:. @prefix inv:. stock:book1 dc:title "SPARQL Query Language Tutorial". stock:book1 dc:edition “First” stock:book1 inv:price 10. stock:book1 inv:quantity 3. stock:book2 dc:title "SPARQL Query Language (2nd ed)". stock:book2 inv:price 20 ; inv:quantity 5. stock:book3 dc:title "Applying XQuery“; dc:edition “Second”. stock:book3 inv:price 20 ; inv:quantity 8. PREFIX dc: PREFIX stock: PREFIX inv: SELECT ?book ?title WHERE { ?book dc:title ?title. ?book inv:price ?price. FILTER ( ?price < 15 ) ?book inv:quantity ?num. FILTER ( ?num > 0 ) } --------------------------------------------------------------------- | book | title | ======================================= | stock:book1 | "SPARQL Query Language Tutorial" | ---------------------------------------------------------------------

9 Other Solution Modifiers PREFIX foaf: SELECT ?name WHERE { ?x foaf:name ?name } ORDER BY ?name PREFIX foaf: SELECT DISTINCT ?name WHERE { ?x foaf:name ?name } ORDER BY ?name LIMIT 5 OFFSET 10

10 ASK @prefix foaf:. _:a foaf:name “Jek". _:a foaf:homepage. _:b foaf:name "Bob". _:b foaf:mbox. PREFIX foaf: ASK { ?x foaf:name “Jek" } Yes true

11 DESCRIBE PREFIX books: PREFIX dc: DESCRIBE ?book WHERE { ?book dc:title "Harry Potter and the Prisoner Of Azkaban" } Joanna Rowling J.K. Rowling Harry Potter and the Prisoner Of Azkaban

12 Describes’s results? The DAWG did not reach a consensus on what describe should return Possibilities include – All triples where the variable bindings are mentioned – All triples where the bindings are the subject – Something else What is useful might depend on the application or the amount of data involved So it was left to the implementation

13 CONSTRUCT @prefix foaf:. _:a foaf:givenname "Alice". _:a foaf:family_name "Hacker". _:b foaf:firstname "Bob". _:b foaf:surname "Hacker". PREFIX foaf: PREFIX vcard: CONSTRUCT { ?x vcard:N _:v. _:v vcard:givenName ?gname. _:v vcard:familyName ?fname } WHERE { { ?x foaf:firstname ?gname } UNION { ?x foaf:givenname ?gname }. { ?x foaf:surname ?fname } UNION { ?x foaf:family_name ?fname }.} @prefix vcard:. _:v1 vcard:N _:x. _:x vcard:givenName "Alice". _:x vcard:familyName "Hacker". _:v2 vcard:N _:z. _:z vcard:givenName "Bob". _:z vcard:familyName "Hacker".

14 On construct Having a result form that produces an RDF graph is a good idea It enables on to construct systems by using the output of one SPARQL query as the data over which another query works This kind of capability was a powerful one for relational databases

15 Optional Pattern Matching Data: @prefix foaf:. @prefix rdf:. _:a rdf:type foaf:Person. _:a foaf:name "Alice". _:a foaf:mbox. _:b rdf:type foaf:Person. _:b foaf:name "Bob". Query: PREFIX foaf: SELECT ?name ?mbox WHERE { ?x foaf:name ?name. OPTIONAL { ?x foaf:mbox ?mbox } } namembox „Alice“ „Alice“ „Bob“ Query Result:

16 RDF Dataset RDF data stores may hold multiple RDF graphs: – record information about each graph – queries that involve information from > one graph – RDF Dataset in SPARQL terminology – the background graph, which doen’t have a name, & 0 or more named graphs, identified by URI reference Use cases: – (i) to have information in the background graph that includes provenance information about the named graphs (the application is not directly trusting the information in the named graphs ) – (ii) to include the information in the named graphs in the background graph as well

17 RDF Named graphs Having multiple RDF graphs in a single document/repository and naming them with URIs Provides useful additional functionality built on top of the RDF Recommendations SPARQL queries can involve several graphs, a background one and multiple named ones, e.g.: SELECT ?who ?g ?mbox FROM FROM NAMED WHERE { ?g dc:publisher ?who. GRAPH ?g { ?x foaf:mbox ?mbox } }

18 Example (I) # Background graph @prefix dc:. dc:publisher "Bob". dc:publisher "Alice". # Graph: http://example.org/bob @prefix foaf:. _:a foaf:name "Bob". _:a foaf:mbox. # Graph: http://example.org/alice @prefix foaf:. _:a foaf:name "Alice". _:a foaf:mbox.

19 Example(II) # Background graph @prefix foaf:. _:x foaf:name "Bob". _:x foaf:mbox. _:y foaf:name "Alice". _:y foaf:mbox. # Graph: http://example.org/bob @prefix foaf:. _:a foaf:name "Bob". _:a foaf:mbox. # Graph: http://example.org/alice @prefix foaf:. _:a foaf:name "Alice". _:a foaf:mbox.

20 Querying the Dataset # Graph: http://example.org/foaf/aliceFoaf @prefix foaf:. @prefix rdf:. @prefix rdfs:. _:a foaf:name "Alice". _:a foaf:mbox. _:a foaf:knows _:b. _:b rdfs:seeAlso. rdf:type foaf:PersonalProfileDocument. _:b foaf:name "Bob". _:b foaf:mbox. _:b foaf:age 32. # Graph: http://example.org/foaf/bobFoaf @prefix foaf:. @prefix rdf:. @prefix rdfs:. _:1 foaf:mbox. _:1 rdfs:seeAlso. _:1 foaf:age 35. rdf:type foaf:PersonalProfileDocument.

21 Accessing Graph Labels PREFIX foaf: SELECT ?src ?bobAge WHERE { GRAPH ?src { ?x foaf:mbox. ?x foaf:age ?bobAge } } srcbobAge 32 35

22 Restricting by Graph Label PREFIX foaf: PREFIX data: SELECT ?age WHERE { GRAPH data:bobFoaf { ?x foaf:mbox. ?x foaf:age ?age } } age 35

23 Restricting via Query Pattern PREFIX data: PREFIX foaf: PREFIX rdf: PREFIX rdfs: SELECT ?mbox ?age ?ppd WHERE { GRAPH data:aliceFoaf { ?alice foaf:mbox ; foaf:knows ?whom. ?whom foaf:mbox ?mbox ; rdfs:seeAlso ?ppd. ?ppd a foaf:PersonalProfileDocument. }. GRAPH ?ppd { ?w foaf:mbox ?mbox ; foaf:age ?age } } mboxageppd 35

24 More Features RDF Dataset - Collection of RDF Graphs use FROM http://planetrdf.com/bloggers.rdfhttp://planetrdf.com/bloggers.rdf use FROM NAMED

25 Limitation of SPARQL SPARQL has many limitations, including – No Insert, Update, Delete queries – No aggregation functions These and many other features are being evaluated for inclusion in a future recommendation, see – http://www.w3.org/2009/sparql/wiki/Category:Features


Download ppt "SPARQL AN RDF Query Language. SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX."

Similar presentations


Ads by Google