Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPARQL : Simple Protocol and RDF Query Language 第一版整理人 : 簡學群 Date : 2014 / 12.

Similar presentations


Presentation on theme: "SPARQL : Simple Protocol and RDF Query Language 第一版整理人 : 簡學群 Date : 2014 / 12."— Presentation transcript:

1 SPARQL : Simple Protocol and RDF Query Language 第一版整理人 : 簡學群 Date : 2014 / 12

2 INTRODUCTION SPARQL (Simple Protocol and RDF Query Language) defines standard query language for RDF data model ▫SPARQL 1.0: 01/2008 ▫SPARQL 1.1: 03/2013 SPARQL is to the Semantic Web (and, really, the Web in general) what SQL is to relational databases. Slides created by 簡學群, NCHU MIS 103

3 WHY SPARQL ? (2/3) SPARQL is the only Semantic Query Language that is an official W3C Recommendation Explore data by querying unknown relationships Pull values from structured and semi-structured data Slides created by 簡學群, NCHU MIS 103

4 ANATOMY of a QUERY Slides created by 簡學群, NCHU MIS 103

5 複習一下 – Query Pattern (?s, ?p, ?o)  查詢所有的 triples (?s, foaf:name, “Eric”)  查詢所有的 subjects ,只要該 subject 擁有 foaf:name 的 predicate ,以及 “Eric” 的 object (?s, foaf:name, ?o)  查詢所有的 subjects 和 object ,只要該 subject 和 object 間的 predicate 是 foaf:name (http://web.nchu.edu.tw/~jlu, ?p, “Eric)  查詢所有 subject 是 http://web.nchu.edu.tw/~jlu 且 object 是 “Eric” 的 predicate 總共有八種型態 雖然 SPARQL 的變數前加上?,但是變數的涵義卻跟以上的說 明相同 Slides created by 簡學群, NCHU MIS 103

6 EXAMPLE - RDF 7499 ALLEN 1600 300 1998-08- 15 7698 ALLEN SALESMAN Slides created by 簡學群, NCHU MIS 103 Source: http://en.wikibooks.org/wiki/XQuery/SPARQL_Tutorial

7 EXAMPLE - RDF emp EmpNo Slides created by 簡學群, NCHU MIS 103

8 EXAMPLE - RDF Accounting 10 Slides created by 簡學群, NCHU MIS 103

9 EXAMPLE – RDF Graph Slides created by 簡學群, NCHU MIS 103 rdf:type f:EmpNo rdfs:label f:Sal f:Comm f:HireDate f:Mgrf:MgrNof:Dept f:Job foaf:surname

10 EXAMPLE - List all employee numbers PREFIX foaf: PREFIX rdf: PREFIX rdfs: PREFIX f: PREFIX xs: SELECT ?number WHERE { ?person f:EmpNo ?number. } subject predicate object Slides created by 簡學群, NCHU MIS 103 注意 object 的資料型態

11 EXAMPLE - List the subject who EmpNo is “7499” PREFIX foaf: PREFIX rdf: PREFIX rdfs: PREFIX f: PREFIX xs: SELECT ?number WHERE { ?person f:Sal ?number. } Slides created by 簡學群, NCHU MIS 103

12 EXAMPLE - List the subject whose EmpNo is “7499” PREFIX foaf: PREFIX rdf: PREFIX rdfs: PREFIX f: PREFIX xs: SELECT ?person WHERE { ?person f:EmpNo “7499”. } Slides created by 簡學群, NCHU MIS 103 List the subject whose Sal is 1100 ?person f:Sal 1100

13 EXAMPLE - List the subject whose Sal is greater than 2000 PREFIX foaf: PREFIX rdf: PREFIX rdfs: PREFIX f: PREFIX xs: SELECT ?person WHERE { ?person f:Sal ?sal. FILTER (?sal > 2000) } Slides created by 簡學群, NCHU MIS 103

14 EXAMPLE - List the names of all employees PREFIX foaf: PREFIX rdf: PREFIX rdfs: PREFIX f: PREFIX xs: SELECT ?name WHERE { ?emp rdf:type f:emp. ?emp foaf:surname ?name. } ORDER BY ?name Slides created by 簡學群, NCHU MIS 103 這一行可以不要

15 EXAMPLE - List the names of all employees’ name and sal PREFIX foaf: PREFIX rdf: PREFIX rdfs: PREFIX f: PREFIX xs: SELECT ?name ?sal WHERE { ?emp? foaf:surname ?name; f:Sal ?sal. } ORDER BY ?name Slides created by 簡學群, NCHU MIS 103 注意分號和句點的差異

16 EXAMPLE - List the employees' name, salary, department, job SELECT ?name ?sal ?dno ?job WHERE { ?emp rdf:type f:emp; foaf:surname ?name; f:Sal ?sal; f:Dept ?dept; f:Job ?job. ?dept f:DeptNo ?dno. } Slides created by 簡學群, NCHU MIS 103

17 EXAMPLE - List the top 5 employees by salary SELECT ?ename ?sal WHERE { ?emp rdf:type f:emp. ?emp foaf:surname ?ename. ?emp f:Sal ?sal. } ORDER BY DESC(?sal) LIMIT 5 In SQL : SELECT name, sal FROM employee ORDER BY sal DESC LIMIT 5 Slides created by 簡學群, NCHU MIS 103

18 EXAMPLE - List the employees' name and their manager SELECT ?ename ?mname WHERE { ?emp f:Mgr ?mgr; foaf:surname ?ename. ?mgr foaf:surname ?mname. } Slides created by 簡學群, NCHU MIS 103

19 EXAMPLE - List the names of employees whose surname contains "AR" in Sales SELECT ?ename WHERE { ?emp rdf:type f:emp. ?emp f:Dept "Sales". ?emp foaf:surname ?ename. FILTER (regex(?ename, "AR")) } Slides created by 簡學群, NCHU MIS 103

20 EXAMPLE - List the homepage of anyone known by Tim Berners-Lee. PREFIX foaf: PREFIX card: SELECT ?homepage FROM WHERE { card:i foaf:knows ?known. ?known foaf:homepage ?homepage. } Slides created by 簡學群, NCHU MIS 103

21 EXAMPLE - List the launches in October 1968. PREFIX space: PREFIX xsd: SELECT * WHERE { ?launch space:launched ?date FILTER ( ?date > "1968-10-01"^^xsd:date && ?date < "1968-10-30"^^xsd:date ) } Slides created by 簡學群, NCHU MIS 103

22 TOOLS Slides created by 簡學群, NCHU MIS 103 Twinkle: ▫http://www.ldodds.com/projects/twinkle/http://www.ldodds.com/projects/twinkle/ Virtuoso SPARQL Query Editor (web based) ▫http://dbpedia.org/sparqlhttp://dbpedia.org/sparql SPARQL Engine ▫http://sourceforge.net/projects/sparql/

23 TOOLS - TWINKLE Slides created by 簡學群, NCHU MIS 103


Download ppt "SPARQL : Simple Protocol and RDF Query Language 第一版整理人 : 簡學群 Date : 2014 / 12."

Similar presentations


Ads by Google