Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:

Similar presentations


Presentation on theme: "SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:"— Presentation transcript:

1 SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link: http://www.w3.org/TR/rdf-sparql-query/http://www.w3.org/TR/rdf-sparql-query/

2 5. Named Graphs

3 Named Graphs Every SPARQL query runs against: –At least the default graph –One or more named graphs –Or merged set of default and all named graphs *Derived from http://www.w3.org/TR/rdf-sparql-query -Section 8.2

4 Named Graph Concepts Set of triples with an identifier –No relation required to URIs in the set –Identifier must be IRI Generally URI with no spaces (and some other characters) Name/IRI can (obviously) also be a URI –Often associated with concept of a file i.e. graph in a file Not a required structure –A triple may be in any number of graphs If file-based, then appearing in multiple files In a persistent store, triple is likely replicated with a different graph identifier with each copy

5 Named Graph Aggregation Graphs at a single SPARQL endpoint –Endpoints may aggregate as they see fit May query other/remote SPARQL endpoints for knowledge May provide whatever graph name they wish –SPARQL does not define the mechanism that requests aggregation of multiple endpoints Nor does it define whether or not they are considered a named graph SPARQL allows selection of graphs based on their name (within the local system)

6 SPARQL Named Graph Keywords –FROM contains an IRI that indicates a graph to be used to form the default graph In this case, the named graph lose its identity in the query –FROM NAMED provide a named graph in the RDF Dataset The name of the graph can be part of the query If no FROM clause, then default graph is empty –GRAPH For the WHERE clause to specify or find out the graph name fulfilling a query

7 Simple Annotated Example PREFIX foaf: PREFIX dc: SELECT ?who ?g ?mbox FROM FROM NAMED WHERE { ?g dc:publisher ?who. GRAPH ?g { ?x foaf:mbox ?mbox } } Replace default graph with dft.ttl Add two named graphs to the set of graphs Find who published the graph* Find graphs using the mbox property. *The default graph has no identifier (so is never the answer).

8 Usage Query Effects ConstructNumber of Occurrences Effect FROMOneReplaces Default Graph FROMMore than oneMerged together and replaces Default Graph FROM NAMED N/AAdded to triple set “along-side” default graph (i.e. maintaining named identity)

9 Example Using GRAPH for Restriction PREFIX foaf: PREFIX data: SELECT ?nick FROM NAMED WHERE { GRAPH data:bobFoaf { ?x foaf:mbox. ?x foaf:nick ?nick } } Only query bobFoaf for this info*. *The default graph has no identifier (so it is never the restriction).

10 6. Unsupported Functionality

11 Data Modification Some proposed standards, but generally considered a bad idea Proposals –SPARQL Update SPARUL or SPARQL+ Adds CREATE DELETE, DROP, and INSERT

12 Subqueries No specific subquery support, but does support nested subgraphs in a query Subquery –Nested SELECT within a WHERE Nested subgraphs –Can nest graph patterns inside other graph patterns

13 Aggregation No count, min, max, avg, or sum SPARQL+ proposes such Full list of SPARQL issues maintained: –http://www.w3.org/2001/sw/DataAccess/issues

14 7. Other Features

15 Other Query Forms ASK –Test whether or not a query pattern has a solution –Just returns whether or not a solution exists PREFIX foaf: / ASK { ?x foaf:name "Alice" ; foaf:mbox } -> true / false (in XML form)

16 Other Query Forms DESCRIBE –returns a single result RDF graph (i.e. tripes file) containing RDF data about resources –The SPARQL service decides how much/what to return (whatever the service providers considers to be useful) PREFIX foaf: DESCRIBE ?x ?y WHERE {?x foaf:knows ?y}

17 Sorting SyntaxDescription LIMIT Limit the number of rows of output OFFSET Skip the number of rows of output ORDER BY ORDER BY ASC()/DESC() Sort the output by variable – default is ascending PREFIX table: SELECT ?name WHERE { ?element table:name ?name; table:atomicWeight ?weight. } ORDER BY DESC(?weight) LIMIT 10 OFFSET 10

18 7. Summary Features Summarized from: http://thefigtrees.net/lee/sw/sparql-faq

19 SPARQL Benefits Implicit join syntax –Does not require explicit joins that specify the relationship between differently structured data All relationships are of a fixed size Data lives in a single graph Strong support for querying semi-structured and ragged data –i.e. data with an unpredictable and unreliable structure –Variables may occur in the predicate position to query unknown relationships –OPTIONAL keyword provides support for querying relationships that may or may not occur in the data (a la SQL left joins)

20 More SPARQL Benefits Query disparate data sources (not sharing a single native representation) in a single query –Join heterogeneous data at a higher level than that of the native structure of the data –Mappings can be performed on the fly –Overcomes the different structures used by different database vendors! Query in a networked, web environment –Pairing of a default graph and zero or more named graphs –SPARQL endpoint may join information from multiple data sources accessible across different Web sites Can use NAMED or NAMED GRAPH to indicate remote graphs to include

21 SPARQL Drawbacks Relatively Young –At least compared to XPath or SQL Immature –Query optimization still a research topic Lack of support for transitive/ hierarchical queries –Really for known/explicit levels or hierarchy


Download ppt "SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:"

Similar presentations


Ads by Google