Ontology Web ngữ nghĩa - SPARQL (HUST)

LI
lienhejb
0 téléchargements
14
0

Contenu du document

Page 1

9/28/2011 Truy vấn dữ liệu „ Tối quan trọng – trong việc sử dụng dữ liệu Ngôn ngữ truy vấấn RDFRDF „ Cho phép tổng hợp dữ liệu trong các kho ngữ nghĩa SPARQL chứa khác nhau „ Cho phép các dữ liệu được lựa chọn có thể được …… ssửử ddụụng lng lạạii … biểu diễn lại „ XML và SPARQL 2 Cơ bản về SPARQL Cú pháp Turtle „ Thực hiện các truy vấn phức tạp trên dữ „ Turtle = Terse RDF Triple Language liliệệu RDF phân tánu RDF phân tán „„ HHỗỗ trtrợợ namespacenamespace „ W3C recommendation 2008 „ Cho phép gom nhóm các bộ ba theo Subject Ví dụ: “Tìm cặp tài nguyên (a,b), sao cho „ Ký pháp tắt cho tập nhiều phần tử „ tồn tại x là cha của a và b là anh của x" …… KKếết qut quảả mongmong đợđợi: ci: cặặp bácp bác – cháucháu „ Cú pháp Turtle (N-triples) 3 4 goupee.com fb.com/groups/goupee 1

Page 2

9/28/2011 Cú pháp SPARQL: Triple prefixes „ Triple đơn „ Cú pháp: …… subjbjectt predidicatte objbjectt . …… @@prefifix abbbbr: <URI><URI> :john rdf:label "John" . @prefix rdf: http://www.w3.org/1999/02/22- „ Triple ghép rdf-syntax-ns# … subject predicate object ; predicate object … :john:john rdf:label "John" ; rdf:type ex:Person ; ex:homePage http://example.org/johnspage/ . 5 6 Định danh Biến „ URI „ ?x ?name ?test … httpp://www.w3.orgg/1999/02/22-rdf- syntax-ns# „ Qname (Qualified name) … namespace-abbr? :localname „ Literal PREFIX foaf: <http://xmlns.com/foaf/0.1/> … "John" SELECT ?mbox WHERE …… truetrue … "Hello"@en-GB { ?x foaf:name "Johnny Lee Outlaw" . … "1.4"^^xsd:decimal ?x foaf:mbox ?mbox } 7 8 goupee.com fb.com/groups/goupee 2

Page 3

9/28/2011 Nút trắng Nút trắng „ Đơn: „ _:b c:speed ?v „„ [] ho[] hoặặcc _:x:x … :john ex:hasFather [] . … :john ex:hasFather _:x . „ làm subject: „ ?x c:speed [ ] „ [ predicate object ; predicate object ... ] . [ ex:hasName "John"] . „ Nút trắắng tương đương với một biếến không được thể hiện trong kết quả truy [ ex:authorOf :lotr ; ex:hasName "Tolkien"] . vấn 9 10 Nút trắng Tập nhiều đối tượng ?x c:speed [ rdf:value ?val ; „ ( object1… objectn ) c:unitc:unit 'km/hkm/h' ]] … :doc1 ex:hasAuthor (:john :mary) . „ Tương đương : „ Tương đương với :doc1 ex:hasAuthor ?x c:speed?x c:speed _:b:b <c:Car> [[ rdf:first :jjohn; <c:speed dfd rdf:parseTType=‘R‘Resource’’> rdf:rest [ rdf:first :mary; _:b rdf:value ?val <rdf:value>100</rdf:value> <c:unit>km/h</c:unit> rdf:rest rdf:nil ] _:b c:unit 'km/h' </c:speed> ] . </c:Car> 11 12 goupee.com fb.com/groups/goupee 3

Page 4

9/28/2011 Bộ ba Cú pháp SPARQL subject property object ?x c:firstName ?y . ??x c:llastNtName ??z. <http://soict.hut.edu.vn/dungct> foaf:name ?name ֞ ?x foaf:name 'Dung' ?x c:firstName ?y ; ?x ?p 'Dung' c:lastName ?z _:b1 foaf:age 33 13 14 Cú pháp SPARQL Cú pháp SELECT ?x c:name “Hoang” . „ Ấn định số thể hiện liên quan đến một ??x c:name “Mi h”“Minh” . thuthuộộc tínc tín cơ chế Prefix – viết tắt URI ֞ PREFIX dc: http://purl.org/dc/elements/1.1/ SELECT ?title ?x c:name “Hoang” , “Minh” WHERE { <http://example org/book/book1> dc:title ?title } }WHERE { <http://example.org/book/book1> dc:title ?title } } Các biến trả về Mẫu truy vấn 15 16 goupee.com fb.com/groups/goupee 4

Page 5

9/28/2011 SELECT WHERE „ Lựa chọn các biến „ Mẫu đồ thị đối sánh „ TTậập cáác bbộộ bba „ Biến: ?x ?title ?name … { (subject predicate object .)* } „ Subject: URI, Qname, nút trắng, Literal, „ Cú pháp Biến „ SELECT var1, var2,… var3 „„ Predicate: URI QName nút trPredicate: URI, QName, nút trắắng bing, biếếnn …SELECT ?name „ Object: như Subject …SELECT ?x,?title 17 18 Mẫu đồ thị (truy vấn) Ví dụ „ Thông qua kết nối ký hiệu Æ truy vấn đồ ththịị con RDFcon RDF VD: SELECT ?p ?o „ WHERE {subject ?p ?o} „ Kết quả: trả về các cặp p. o thỏa mãn SELECT ?cat ?val WHERE { ?x rdf:value ?val. ?x categgoryy ?cat }} [["Total Members",100],["Total Members",200],…, ["Full Members",10],…] 19 20 goupee.com fb.com/groups/goupee 5

Page 6

9/28/2011 Ví dụ Ví dụ SELECT ?cat ?val SELECT ?cat ?val ?uri WHERE { ?x rdf:value ?val. { WHERE { ?x rdf:value ?val. ?x category ?cat. ?x category ?cat. FILTER(?val>=200). } ?al contains ?x. ?al linkTo ?uri } [["Total Members", 200],… ] [["Total Members", 100, http:// ],… ] 21 22 Ví dụ OPTIONAL SELECT * WHERE { ?x :hasCreated ?doc?x :hasCreated ?doc . OPTIONAL { SELECT ?cat ?val ?uri ?x :isMemberOf ?org WHERE { ?x rdf:value ?val. } ?x category ?cat. OPTIONAL ?al contains ?x. } ?al linkTo ?uri } hasCreated: Bắt buộc isMemberOf: tùy chọn [["Total Members",100,http://...], …, ["Full Members",20, ],…,] 23 24 goupee.com fb.com/groups/goupee 6

Page 7

9/28/2011 OPTIONAL OPTIONAL lồng nhau :John :hasCreated :d1 SELECT * WHERE { :John :hasCreated :d2:John :hasCreated :d2 ?x :hasCreated ?doc .?x :hasCreated ?doc . :Jack :hasCreated :d3 OPTIONAL { :Jack :isMemberOf :club ?x :isMemberOf ?org OPTIONAL {?org :name ?name} „ Kết quả } „ (1) x = :John ; doc = :d1 ; org = unbound } „ (2) x = :John ; doc = :d2 ; org = unbound „ (3) x = :Jack ; doc = :d3 ; org = :club 25 26 OPTIONAL lồng nhau OPTIONAL lồng nhau SELECT * WHERE { :John :hasCreated :d1 SELECT * WHERE { :John :hasCreated :d2 :John :hasCreated :d1 ?x :hasCreated ?doc . :Jack :hasCreated :d3 ?x :hasCreated ?doc .?x :hasCreated ?doc . :John :hasCreated :d2 OPTIONAL { :Jack :isMemberOf :club :Jack :hasCreated :d3 :Jack :isMemberOf :assoc OPTIONAL { ?x :isMemberOf ?org :assoc :name ‘ASPTT’ :Jack :isMemberOf :club OPTIONAL {?org :name ?name} ?x :age ?age . :Jim :hasCreated :d4 } ?x :isMemberOf ?org :Jim :isMemberOf :assoc } } :Jim :age 45 Kết quả: } (1)(1) x = :J hJohn ; ddoc = :d1d1 ; org = unbboundd ; name = unbboundd (2) x = :John ; doc = :d2 ; org = unbound ; name = unbound (3) x = :Jack ; doc = :d3 ; org = :club ; name = unbound age và isMemberOf phải cùng xuất hiện trong kết quả nếu (4) x = :Jack ; doc = :d3 ; org = :assoc ; name = ‘ASPTT’ có mặt. 27 28 goupee.com fb.com/groups/goupee 7

Page 8

9/28/2011 OPTIONAL lồng nhau OPTIONAL lồng nhau SELECT * WHERE { :John :hasCreated :d1 SELECT * WHERE { :John :hasCreated :d1 ?x :hasCreated ?doc . :John :hasCreated :d2 ?x :hasCreated ?doc . :John :hasCreated :d2 :Jack :hasCreated :d3 :Jack :hasCreated :d3:Jack :hasCreated :d3 OPTIONAL { OPTIONAL { ?x :age ?age } :Jack :isMemberOf :club ?x :age ?age . :Jack :isMemberOf :club OPTIONAL{ ?x :isMemberOf ?org} :Jim :hasCreated :d4 ?x :isMemberOf ?org :Jim :hasCreated :d4 } :Jim :isMemberOf :assoc :Jim :isMemberOf :assoc :Jim :age 45 } } } :Jim :age 45 Kết quả: Kết quả: (( )1) x = :John ;; doc = :d1 ;; orgg = unbound ;; agge = unbound (1)(1) x = :J hJohn ; ddoc = :d1d1 ; org = unbboundd ; age = unbboundd (2) x = :John ; doc = :d2 ; org = unbound ; age = unbound (2) x = :John ; doc = :d2 ; org = unbound ; age = unbound (3) x = :Jack ; doc = :d3 ; org = club ; age = unbound (3) x = :Jack ; doc = :d3 ; org = unbound ; age = unbound (4) x = :Jim ; doc = :d4 ; org = :assoc ; age = 45 (4) x = :Jim ; doc = :d4 ; org = :assoc ; age = 45 29 30 Lọc kết quả Cú pháp lọc „ FILTER (?age >= 7 && ?age <= 77) „ EXP ::= TERM | EXP OPER EXP | (EXP) „„ So sánh :So sánh : < << <= = >>= >> !!= „„ TERM ::= VAR | CST | FUNTERM ::= VAR | CST | FUN „ Toán tử : + * / - „ CST ::= URI | Literal Logic : && (and) || (or) ! „ OPER ::= < <= = >= > + - * / && || ! „ (not) „ FUN ::= NAME( EXP*) „„ Hàm :Hàm : isBlank(?x)isBlank(?x) my:fun(?y)my:fun(?y) 31 32 goupee.com fb.com/groups/goupee 8

Page 9

9/28/2011 Kiểu dữ liệu - hàm Hàm „ 1 = 1.0 „ isURI(?x) „ ‘1’^^‘1’^^xsdd:iintteger = „ iisLitLiteral(?l(?y)) ‘1.0’^^xsd:decimal „ isBlank(?z) „ bound(?t) „ “engineer” != “engineer”@en „„ ““engiineer”” = sttr(“(“engiineer”@”@en)) 33 34 Kiểm tra điều kiện Xử lý kết quả „ lang(?x) = ‘en’ „ SELECT * WHERE ……engiineer@@en -> t> true „ SELECT DISTINCT ?SELECT DISTINCT ?x ??y WHEREWHERE …kỹ sư@vn -> false ORDER BY ?x DESC(?y) „ „ LIMIT 10 „ datatype(?y)= xsd:string OFFSET 10 „ „„ ! (?x ||! (?x || ?y &&?y && ?z)?z) 35 36 goupee.com fb.com/groups/goupee 9

Page 10

9/28/2011 DISTINCT DISTINCT select distinct ?x ?z select distinct ?x ?z where {{ :Jules :friend :Jim whhere {{ :Jim :friend :Jack ?x :friend ?y ?x :friend ?y ?y :friend ?z :Jules :friend :James :James :friend :Jack ?y :friend ?z } } „ Kết quả Không trả vềề 2 lầần giá trị của x, z như ……((11) x = :Jules ; z = :Jack) x = :Jules ; z = :Jack „ nhau 37 38 Không DISTINCT ORDER BY Select ?x ?z select ?pers ?date :Jim :author :d2 where {{ :Jules :friend :Jim where {where { :Jack :author :d1 ?x :friend ?y :Jim :friend :Jack ?pers :author ?doc :d2 :date 2008-01-01 :Jules :friend :James :d1 :date 2007-12-31 ?y :friend ?z ?doc :date ?date :James :friend :Jack } } „ Kết quả order by ?date ……(1) x = :Jules ; z = :Jack(1) x = :Jules ; z = :Jack Kếết quả: …(2) x = :Jules ; z = :Jack (1) pers = :Jim ; date = 2007-12-31 (2) pers = :Jack ; date = 2008-01-01 39 40 goupee.com fb.com/groups/goupee 10

Page 11

9/28/2011 ORDER BY LIMIT/OFFSET select ?doc ?date :Jim :author :d2 select * where { where {where { :Jack :author :d1 :Jack :author :d3 PATTERNPATTERN ?pers :author ?doc :d2 :date 2008-01-01 } ?doc :date ?date :d1 :date 2007-12-31 } :d3 :date 2007-12-31 LIMIT 20 order by ?date desc(?doc) Chỉ hiện tốối đa 20 kếết quả Kết quả: 1) doc = :d3 ; date = 2007-12-31 (2) doc = :d1 ; date = 2007-12-31 (3) doc = :d2 ; date = 2008-01-01 41 42 LIMIT/OFFSET Một số bài tập select * where { „ Viết query chuyển đổi ngôn ngữ nhãn cuả PATTERNPATTERN khái nikhái niệệm person tm person từừ titiếếng Anh sang ting Anh sang tiếếngng } Pháp – nếu có. LIMIT 20 select ?label where OFFSET 10 ?x rdfs:label ?l@@en ?l = "person" Chỉ hiện tối đa 20 kết quả, sau 10 kết quả ?x rdfs:label ?label@fr đầu (Các kết quả từ 11-30) 43 44 goupee.com fb.com/groups/goupee 11

Page 12

9/28/2011 Lấy lớp cha của 1 tài nguyên Thực hành truy vấn SPARQL „ Cho 1 resource – xác định lớp cha của lớp „ Sparqler ttươươngng ứứng vng vớới resourcei resource đđóó ……htthttp:////sparqll.org//sparqll ht.htmll „ OpenLink's Virtuoso select ?class where http://lod.openlinksw.com/sparql … ?x rdf:type ?c …Chọn "Retrieve remote RDF data for all ?c rdfs:subClassOf ?class?c rdfs:subClassOf ?class missingg source ggrapphs" 45 46 SPARQL OpenLink Virtuoso 47 48 goupee.com fb.com/groups/goupee 12

Page 13

9/28/2011 Dữ liệu RDF Truy vấn 1 „ Tự tạo ontology – up lên một địa chỉ URI „ Truy vấn 1: Tìm tất cả tên người „ O t lOntology FOAFFOAF củủa TiTim BBerners LLee: trong contact FOAF trêntrong contact FOAF trên …http://www.w3.org/People/Berners-Lee/card PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE {WHERE { ?person foaf:name ?name . } 49 50 Truy vấn 2 Truy vấn 3 „ Tìm tất cả những người trong contact của „ Tìm các homepage của những người mà foaf có tên vàfoaf có tên và địđịa cha chỉỉ mailmail TBL (TBL (http://www w3 org/People/Bernershttp://www.w3.org/People/Berners- „ Sử dụng * Lee/card) biết PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * WHERE { ?person foaf:name ?name . ?person foaf:mbox ?email . } 51 52 goupee.com fb.com/groups/goupee 13

Page 14

9/28/2011 Bài tập PREFIX foaf: <http://xmlns.com/foaf/0.1/> Cho dữ liệu sau PREFIX card:PREFIX card: <http://www.w3.org/People/Bernershttp://www.w3.org/People/Berners-Lee/card#Lee/card#> SELECT ?homepage FROM <http://www.w3.org/People/Berners-Lee/card> WHERE { card:i foaf:knows ?known . Cho biết kết quả trả về bởi câu SPARQL ?known foaf:homepage ?homepage . } 53 54 Bài tập Bài tập Cho dữ liệu sau Cho CSDL RDF sau Vẽ đồ thị RDF. Cho biết kết quả trả về bởi câu SPARQL Cho biết kết quả trả về bởi câu SPARQL 55 56 goupee.com fb.com/groups/goupee 14

Affichage des 14 premières pages. Téléchargez le document pour le voir en entier.

Commentaires (0)

Se connecter pour rejoindre la discussion

Aucun commentaire pour le moment. Soyez le premier !