120 likes | 197 Views
SPARQL : Simple Protocol and RDF Query Language. Speaker : 簡學群 Date : 2012 / 11 / 20. INTRODUCTION.
E N D
SPARQL :Simple Protocol andRDF Query Language Speaker : 簡學群 Date : 2012 / 11 / 20
Slides created by 簡學群, NCHU MIS 103 INTRODUCTION • SPARQL (Simple Protocol and RDF Query Language) defines standard query language and data access protocol which is used with RDF data model and it works for every data source which can be mapped to RDF which uses SPARQL to retrieve data. • SPARQL is to the Semantic Web (and, really, the Web in general) what SQL is to relational databases.
Slides created by 簡學群, NCHU MIS 103 WHY SPARQL ? (2/3) • SPARQL saves development time and cost by allowing client applications to work with only the data they're interested in. • Eq. 查詢城市的人口、面積、房價,以判斷是否人口密度跟房價有關係。 • SPARQL is the only Semantic Query Language that is an official W3C Recommendation, and as such, has the greatest chance of actual standardization as the Semantic web grows.
Slides created by 簡學群, NCHU MIS 103 ANATOMY of a QUERY
Slides created by 簡學群, NCHU MIS 103 EXAMPLE - RDF <f:emp rdf:about="http://www.cems.uwe.ac.uk/empdept/emp/7499"> <f:EmpNordf:datatype="http://www.w3.org/2001/XMLSchema#string"> 7499 </f:EmpNo> <f:Salrdf:datatype="http://www.w3.org/2001/XMLSchema#integer"> 1600 </f:Sal> <f:HireDaterdf:datatype="http://www.w3.org/2001/XMLSchema#date"> 1998-08-15 </f:HireDate> <f:Mgrrdf:resource="http://www.cems.uwe.ac.uk/empdept/emp/7698"/> <f:MgrNo>7698</f:MgrNo> <f:Dept>Sales</f:Dept> <foaf:surname >ALLEN</foaf:surname> <f:Job>SALESMAN</f:Job> </f:emp>
Slides created by 簡學群, NCHU MIS 103 EXAMPLE - List the names of all employees PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX f: <http://www.cems.uwe.ac.uk/empdept/concept/> PREFIX xs: <http://www.w3.org/2001/XMLSchema#> SELECT ?name WHERE { ?emprdf:type f:emp. ?empfoaf:surname ?name. } ORDER BY ?name subject predicate In SQL : SELECT name FROM employee ORDER BY name object
Slides created by 簡學群, NCHU MIS 103 EXAMPLE - List the employees' name, salary, department, job SELECT ?name ?sal?dept ?job WHERE { ?emprdf:typef:emp. ?empfoaf:surname ?name. ?emp f:Sal ?sal. ?emp f:Dept ?dept. ?emp f:Job ?job. } In SQL : SELECT name, sal, dept, job FROM employee
Slides created by 簡學群, NCHU MIS 103 EXAMPLE - List the top 5 employees by salary SELECT ?ename ?sal WHERE { ?emprdf:type f:emp. ?empfoaf: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 EXAMPLE - List the employees' name, salary, department, job SELECT ?ename ?mname WHERE { ?emprdf:type f:emp. ?emp f:Mgr ?mgr. ?empfoaf:surname?ename. ?mgrfoaf:surname?mname. } In SQL : SELECT emp.name, mgr.name FROM employee emp, employee mgr WHERE emp.mgr_id = mgr.emp_id
Slides created by 簡學群, NCHU MIS 103 EXAMPLE - List the names of employees whose surname contains "AR" in Sales SELECT ?ename WHERE { ?emprdf:typef:emp. ?empf:Dept "Sales". ?empfoaf:surname?ename. FILTER (regex(?ename, "AR")) } In SQL : SELECT name FROM employee WHERE dept=“Sales” AND name LIKE “%AR%”
Slides created by 簡學群, NCHU MIS 103 TOOLS • Twinkle: • http://www.ldodds.com/projects/twinkle/ • Virtuoso SPARQL Query Editor (web based) • http://dbpedia.org/sparql • SPARQL Engine • http://sourceforge.net/projects/sparql/
Slides created by 簡學群, NCHU MIS 103 TOOLS - TWINQL