Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPARQL RDF Query.

Similar presentations


Presentation on theme: "SPARQL RDF Query."— Presentation transcript:

1 SPARQL RDF Query

2 Query RDF: SPARQL The Simple Protocol and RDF Query Language (SPARQL) is a SQL-like language for querying RDF data. For expressing RDF graphs in the matching part of the query, TURTLE syntax is used.

3 A Query Template I want these pieces of information from the subset of the data that meets these conditions. You describe the conditions with triple patterns, which are similar to RDF triples but may include variables to add flexibility in how they match against the data.

4 Craig has two email addresses:

5

6

7 The query to find Craig’s email addresses would then look like this:

8 A SELECT query PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox . } first line defines namespace prefix the last two lines use the prefix to express a RDF graph to be matched Identifiers beginning with question mark ? identify variables In this query, we are looking for resource ?x participating in triples with predicates foaf:name and foaf:mbox and want the objects of these triples

9 PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?url FROM <bloggers.rdf> WHERE { ?contributor foaf:name "Jon Foobar" . ?contributor foaf:weblog ?url . }

10 Data < < "SPARQL Tutorial" . Query SELECT ?title WHERE { < < ?title . } Result “SPARQL Tutorial"

11 The result of a query is a solution sequence, corresponding to the ways in which the query's graph pattern matches the data. There may be zero, one or multiple solutions to a query.

12 Data: @prefix foaf: < . _:a foaf:name "Johnny Lee Outlaw" . _:a foaf:mbox . _:b foaf:name "Peter Goodguy" . _:b foaf:mbox . _:c foaf:mbox . Query: PREFIX foaf: < SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox } Query Result: name mbox "Johnny Lee Outlaw" "Peter Goodguy"

13 SELECT ?x WHERE { ?x < "John Smith" } SELECT ?x ?fname WHERE {?x < ?fname} SELECT ?givenName WHERE { ?y < "Smith" . ?y < ?givenName . } PREFIX vcard: < SELECT ?givenName WHERE { ?y vcard:Family "Smith" . ?y vcard:Given ?givenName . }

14 SPARQL Tutorial - Filters
SPARQL provides an operation to test strings, based on regular expressions.  Syntax is FILTER regex(?x, "pattern" [, "flags"]) PREFIX vcard: < SELECT ?g WHERE { ?y vcard:Given ?g . FILTER regex(?g, "r", "i") } Result: "Rebecca" "Sarah" The flag "i" means a case-insensitive pattern match is done

15 PREFIX info: <http://somewhere/peopleInfo#>
SELECT ?resource WHERE { ?resource info:age ?age . FILTER (?age >= 24) } PREFIX info: < PREFIX vcard: < SELECT ?name ?age WHERE { ?person vcard:FN ?name . OPTIONAL { ?person info:age ?age } } gets the name of a person and also their age if that piece of information is available.

16 PREFIX info: <http://somewhere/peopleInfo#>
PREFIX vcard: < SELECT ?name ?age WHERE { ?person vcard:FN ?name . OPTIONAL { ?person info:age ?age . FILTER ( ?age > 24 ) } }

17 A query to find people described in two named FOAF graphs
PREFIX foaf: < PREFIX rdf: < SELECT ?name FROM NAMED <jon-foaf.rdf> FROM NAMED <liz-foaf.rdf> WHERE { GRAPH <jon-foaf.rdf> { ?x rdf:type foaf:Person . ?x foaf:name ?name . } . GRAPH <liz-foaf.rdf> { ?y rdf:type foaf:Person . ?y foaf:name ?name . }


Download ppt "SPARQL RDF Query."

Similar presentations


Ads by Google