
Semantic Web: Formalisms, SPARQL, and Query Solutions
Explore the concepts of Semantic Web formalisms, SPARQL query language, and query solutions, including examples and the WHERE clause. Learn about querying techniques and sub-graph matching to retrieve relevant data efficiently in a distributed environment.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
M2 DSC UE2 Semantic Web http://ci.mines-stetienne.fr/cours/2017/dsc-websem/ 4. Querying Maxime Lefran ois maxime.lefrancois@emse.fr Freely adapted from presentations of Lynda Temal, https://fr.linkedin.com/in/lynda-temal-32a206a/fr Which were themselves freely adapted from presentations of Fabien Gandon, Inria. 1
Semantic Web Formalisms Trust 2
SPARQL A common distributed query language SPARQL = SPARQL Protocol and RDF Query Language SPARQL 1.1: W3C Standard 2013 - SPARQL Query Language - SPARQL Update - SPARQL Protocol (over HTTP) 3
One example @prefix foaf: <http://xmlns.com/foaf/0.1/> . @base <http://example.org/> <Alice> foaf:name "Alice" ; foaf:lastName Smith" . <John> foaf:firstName Smith" . _:bn1 foaf:name "Bob" . PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?name WHERE { ?x foaf:name ?name } ?x <http://example.org/Alice> _:a ?name Alice Bob 4
SPARQL Query: four types of queries PREFIX foaf: <http://xmlns.com/foaf/0.1/> ASK WHERE { ?x foaf:name ?name } PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?name WHERE { ?x foaf:name ?name } PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT { ?x a foaf:Person } WHERE { ?x foaf:name ?name } PREFIX foaf: <http://xmlns.com/foaf/0.1/> DESCRIBE ?x WHERE { ?x a foaf:Person } 5
The WHERE clause The simplest where clause consists of a Basic Graph Patterns = a RDF Graph with variables PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * WHERE { ?x foaf:knows ?y . ?y vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue ?tel ] . } 6
Query solutions Search for sub-graphs that match the query -> return values for the different variables (uri, blank node, or literal) @prefix foaf: <http://xmlns.com/foaf/0.1/> . @base <http://example.org/> . <Paul> vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33610..." ] ; foaf:knows <Bob>, <Alex> . <Bob> vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33620..." ] ; foaf:knows <Paul>, <Cathia> . PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?y WHERE { ?x foaf:knows ?y . ?y vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue ?tel ] . <Cathia> vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33630..." ] ; vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33640..." ] . } 7
Query solutions What changes in the query solutions ? @prefix foaf: <http://xmlns.com/foaf/0.1/> . @base <http://example.org/> . <Paul> vcard:hasTelephone [ vcard:hasValue "+33610..." ] ; foaf:knows <Bob>, <Alex> . <Bob> vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33620..." ] ; foaf:knows <Paul>, <Cathia> . PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * WHERE { ?x foaf:knows ?y . ?y vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue ?tel ] . < Cathia > vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33630..." ] ; vcard:hasTelephone [ a vcard:Voice ; vcard:hasValue "+33640..." ] . } 8
SELECT Queries Output of SELECT queries as XML <?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="x"/> <variable name= y"/> <variable name= tel"/> </head> <results> <result> <binding name="x"><uri>http://example.org/Paul</uri></binding> <binding name= y"><uri>http://example.org/Bob</uri></binding> <binding name= tel"><literal>+33620... </literal></binding> </result> </sparql> 9
SELECT Queries Output of SELECT queries as JSON { "head": { "vars": [ "x" , "y" , "tel" ] } , "results": { "bindings": [ { "x": { "type": "uri" , "value": "http://example.org/Paul" } , "y": { "type": "uri" , "value": "http://example.org/Bob" } , "tel": { "type": "literal" , "value": "+33620... " } } , ... ] } } 10
ASK Queries Output of a ASK query as XML <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head></head> <boolean>true</boolean> </sparql> OR <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head></head> <boolean>false</boolean> </sparql> Output of a ASK query as JSON { { "head" : { } , "boolean" : true "head" : { } , "boolean" : false OR } } 11
CONSTRUCT Queries Output of a CONSTRUCT query: RDF (has different serializations) 12