59
SPARQL NHN 김광섭 [email protected] RDF Tutorial 2009. 10. 31 2009년 10월 31일 토요일

RDF Tutorial - SPARQL 20091031

Embed Size (px)

DESCRIPTION

RDF Tutorial - SPARQL http://www.onoffmix.com/e/sonagi/1116

Citation preview

Page 1: RDF Tutorial - SPARQL 20091031

SPARQLNHN 김광섭

[email protected]

RDF Tutorial 2009. 10. 312009년 10월 31일 토요일

Page 2: RDF Tutorial - SPARQL 20091031

RDF 간단하게!

SPARQL 지루하게!

PLAY 신나게!

SPARQL 1.1 살짝!

2009년 10월 31일 토요일

Page 3: RDF Tutorial - SPARQL 20091031

http://vocamp.org/wiki/VoCampSeoul2009#Slideshttp://delicious.com/kwangsub.kim/%23VoCampSeoul2009

http://delicious.com/kwangsub.kim/bundle:RDFTutorial2009

모아두었습니다

2009년 10월 31일 토요일

Page 4: RDF Tutorial - SPARQL 20091031

RDF

어떤것을 기술하기 위한 구조(틀)일 뿐!

웹상에서 표현될 수 있는 개념들 블로그, 온라인매체 (RSS)사람, 친구 (FOAF)...

Resource Description Framework

Subject - Predicate - Object이것이 그 틀!

우리는 그 틀에 맞춰 어떤것들을 기술만 한뿐!

2009년 10월 31일 토요일

Page 5: RDF Tutorial - SPARQL 20091031

Graph가 만들어지면 그 다음은?

인물

음악

영화

지역

SPARQL

<sparql ...> <head> <variable name="x"/> <variable name="mbox"/> </head>

<results> <result> <binding name="x"> <bnode>r2</bnode> </binding> <binding name="mbox"> <uri>mailto:[email protected]</uri> </binding> </result> </results></sparql>

2009년 10월 31일 토요일

Page 6: RDF Tutorial - SPARQL 20091031

*http://pingthesemanticweb.com

...

2008-07-16

2009년 10월 31일 토요일

Page 7: RDF Tutorial - SPARQL 20091031

*http://pingthesemanticweb.com

...

2008-11-04

2009년 10월 31일 토요일

Page 8: RDF Tutorial - SPARQL 20091031

*http://pingthesemanticweb.com

...

2009-01-08

2009년 10월 31일 토요일

Page 9: RDF Tutorial - SPARQL 20091031

*http://pingthesemanticweb.com

2008-07-16

4,955,878

2008-11-04

7,504,227

200%

2009-01-08

8,826,08216,705,060

200%

2009-10-31

2009년 10월 31일 토요일

Page 10: RDF Tutorial - SPARQL 20091031

SPARQLGRDDL

2009년 10월 31일 토요일

Page 11: RDF Tutorial - SPARQL 20091031

SPARQL

Graph안에서 매치된 SPO (Subject, Predicate, Object) 들을 찾기 위한 Query Language

Simple Protocol And RDF Query Language

Pattern Match

Simple Protocol

RDF Query Language

&

<sparql ...> <head> <variable name="x"/> <variable name="mbox"/> </head>

<results> <result> <binding name="x"> <bnode>r2</bnode> </binding> <binding name="mbox"> <uri>mailto:[email protected]</uri> </binding> </result> </results></sparql>

http://semantic.lab.naver.com/rdf/endpoint/sparql?select....

SELECT ?emailWHERE {

?user :email ?email.?user :name “김광섭”;

}

is a query language and a protocol for accessing RDF

2009년 10월 31일 토요일

Page 12: RDF Tutorial - SPARQL 20091031

SPA RDF Query Language

2009년 10월 31일 토요일

Page 13: RDF Tutorial - SPARQL 20091031

Query Language

2009년 10월 31일 토요일

Page 14: RDF Tutorial - SPARQL 20091031

SQL

SELECT nameFROM usersWHERE contact=‘011-201-0000’;

SELECT ?nameWHERE {

?user rdf:type :User.?user :name ?name.?user :contact “011-201-0000”.

}FROM <http://semantic/users.rdf>

Return Variables

SPO Pattern

Graph Source

vs. SPARQL

2009년 10월 31일 토요일

Page 15: RDF Tutorial - SPARQL 20091031

?name = “김광섭”

Graph

SELECT ?nameWHERE {

?user rdf:type foaf:Person.?user :contact “011-201-0000”.?user :name ?name.

}FROM <http://semantic/users.rdf>

_person foaf:Personrdf:type

“011-201-0000”:name

김광섭

:contact

<sparql xmlns=”http://www.w3.org...”> <head> <variable name="name"/> </head> <results> <result> <binding name="name"> <literal>김광섭</literal> </binding> </result> </results></sparql>

<http://semantic/users.rdf>

> Query Language > Binding > Protocol

2009년 10월 31일 토요일

Page 16: RDF Tutorial - SPARQL 20091031

BASE <http://example.org/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX ex: <properties/1.0#> SELECT DISTINCT $person ?name $age FROM <http://rdf.example.org/personA.rdf> FROM <http://rdf.example.org/personB.rdf> WHERE{

$person a foaf:Person ; foaf:name ?name.

OPTIONAL { $person ex:age $age } . FILTER (!REGEX(?name, “Bob”))

} ORDER BY ASC(?name) LIMIT 10 OFFSET 20

SPARQL

* SPARQL RDF Query Language Reference v1.8 by Dave Beckett.

2009년 10월 31일 토요일

Page 17: RDF Tutorial - SPARQL 20091031

Terms

Sytax

Pattern

알아야 것들

2009년 10월 31일 토요일

Page 18: RDF Tutorial - SPARQL 20091031

Terms

IRI : URI reference within an RDF graph<http://www.w3.org><http://semantic.naver.com/#Movie><abc.rdf> //base URI에 의존foaf:name //prefix이용해 URI표현, PREFIX 정의#x00 (X) //UNICODE문자 내에 허용

Datatype IRI : datatype URI<http://www.w3.org/2001/XMLSchema#string><http://www.w3.org/2001/XMLSchema#integer>

Plain Literal : lexical form, optionally language tag, @ko“Semantic web” , “김광섭”@ko

Typed Literal : lexical form, datatype URI“30”^^xsd:integer“kwangsub”^^http://www.w3.org/2001/XMLSchema#string

Blank node : dummy node, node들간의 연결표현용, 무작위생성_:a, _n06968595988

2009년 10월 31일 토요일

Page 19: RDF Tutorial - SPARQL 20091031

NameSpace : Vocabulary가 있는 URIhttp://www.w3.org/1999/02/22-rdf-syntax-ns#http://purl.org/dc/elements/1.1/http://xmlns.com/foaf/0.1/

Prefix : URI의 경로를 대표하는 접두어rdf, dc, foaf

Terms

RDF Graph : A Set of RDF Triples

RDF Triple : S-P-OSubject : IRI or Blank NodePredicate : IRIObject : IRI or Blank Node or Literal

2009년 10월 31일 토요일

Page 20: RDF Tutorial - SPARQL 20091031

Match : Graph내 SPO가 Query Pattern에 Match되는 상황

Terms

Solutions : Match되어 반환된 결과들

Query Variable : Solutions을 바인딩하기 위한 변수

?x = “김광섭”

?x or $name

2009년 10월 31일 토요일

Page 21: RDF Tutorial - SPARQL 20091031

SELECT ?emailWHERE {

?person :email ?email.?person :name “김광섭”;

}

“김광섭”이란 사람의 “email”은?

Play #

_person [email protected]:email

:name

김광섭

2009년 10월 31일 토요일

Page 22: RDF Tutorial - SPARQL 20091031

“Hi Korea” //”Hi Korea”

Literals

“Hi Korea”@en //영어임을 명시

“Hi Korea”^^xsd:string //문자열임을 명시 etc. integer, boolean

1 == “1”^^xsd:integer

true == “true”^^xsd:boolean

1.3 == “1.3”^^xsd:decimal

Syntax - RDF Term Syntax

2009년 10월 31일 토요일

Page 23: RDF Tutorial - SPARQL 20091031

SELECT ?emailWHERE {

?person :name “kwangsub”@en.?person :email ?email.

}

kwangsub의 영문이름을 가진 사람의 email은?

Play #

_person [email protected]:email

:name

kwangsub@en

2009년 10월 31일 토요일

Page 24: RDF Tutorial - SPARQL 20091031

Syntax - RDF Term Syntax

<http://example.org/book/book1>

IRI

BASE <http://example.org/book/><book1>

PREFIX book: <http://example.org/book/>book:book1

2009년 10월 31일 토요일

Page 25: RDF Tutorial - SPARQL 20091031

PREFIX dc: <http://purl.org/dc/elements/purl.org/>SELECT ?titleWHERE { <http://example.org/book/book> dc:title ?title }

PREFIX, BASE

Syntax -Triple Pattern Syntax

PREFIX dc: <http://purl.org/dc/elements/1.1/>PREFIX : <http://example.org/book/>

SELECT $titleWHERE { :book1 dc:title $title }

BASE <http://example.org/book/>PREFIX dc: <http://purl.org/dc/elements/1.1/>

SELECT $titleWHERE { <book1> dc:title $title }

2009년 10월 31일 토요일

Page 26: RDF Tutorial - SPARQL 20091031

BASE <http://RDFTutorial.net/2009/>PREFIX book: <http://example.org/book/>SELECT ?book_nameWHERE {

?person :like book:book_3.book:book_3 book:name ?book_name.

}

kwangsub의 영문이름을 가진 사람의 email은?

Play #

_person :like

:name

kwangsub@en

book:book_3

book:name

개미

2009년 10월 31일 토요일

Page 27: RDF Tutorial - SPARQL 20091031

Query Var

?var or $var

Syntax - RDF Term Syntax

Blank

[ :p “v”]. == [] :p “v”.

_b57 :p “v”. //기본예Unique Blank - 다른 IRI과 연결용

[ foaf:name ?name ; foaf:mbox <mailto:[email protected]>] //확장예

_b11 foaf:name ?name_b11 foaf:mbox <mailto:[email protected]>

;은 S에 PO를 연속해서 붙일 수 있다.

2009년 10월 31일 토요일

Page 28: RDF Tutorial - SPARQL 20091031

PREFIX foaf: <http://xmlns.com/foaf/0.1/>.PREFIX : <http://RDFTutorial.net/2009/>.SELECT $nameWHERE {

?_a foaf:name “kwangsub.kim”.?_a :love $_b.$_b <http://RDFTutorial.net/2009/name> $name.

}

foaf:name이 kwangsub.kim사람이 사랑하는 사람 name?

Play .#

_b

soomers

:name

_a

foaf:name

kwangsub.kim

:love

2009년 10월 31일 토요일

Page 29: RDF Tutorial - SPARQL 20091031

?people foaf:name ?name ; foaf:mbox ?mbox .

; ,

Syntax ; ,

?people foaf:name ?name .?people foaf:mbox ?mbox .

우린 같아요~

?people foaf:nick "Alice" , "Alice_" .

?people foaf:nick "Alice" .?people foaf:nick "Alice_" .

우린 같아요~

2009년 10월 31일 토요일

Page 30: RDF Tutorial - SPARQL 20091031

PREFIX foaf: <http://xmlns.com/foaf/0.1/>.SELECT ?nameWHERE {

?_a foaf:nickname “바야바”; foaf:name “kwangsub”.?_a foaf:knows ?_b.?_b foaf:name ?name.

}

이름이 kwangsub이고 별명이 “바야바”인 사람이 아는 사람의 이름?

Play #

_bfoaf:knows

foaf:name

SangWon

_a

바야바

foaf:nicknamefoaf:name

kwangsub

2009년 10월 31일 토요일

Page 31: RDF Tutorial - SPARQL 20091031

Basic Graph Pattern

Pattern

Group Graph Pattern

{?people foaf:name "kwangsub".}

{{?people foaf:name "kwangsub".}{?people foaf:email "[email protected]".}

} //두 패턴이 모두 만족해야

{?people foaf:name ?name.FILTER regex (?name, “kw”)

}

Filter

2009년 10월 31일 토요일

Page 32: RDF Tutorial - SPARQL 20091031

Pattern

Optional Graph Pattern

_:a rdf:type foaf:Person ._:a foaf:name "Alice" ._:a foaf:mbox <mailto:[email protected]> ._:a foaf:mbox <mailto:[email protected]> .

_:b rdf:type foaf:Person ._:b foaf:name "Bob" .

SELECT ?name ?mboxWHERE {

?people foaf:name ?name . OPTIONAL { ?people foaf:mbox ?mbox } }

2009년 10월 31일 토요일

Page 33: RDF Tutorial - SPARQL 20091031

Pattern

Optional Graph Pattern + FILTER

SELECT ?people ?mboxWHERE {

?people foaf:name ?name . OPTIONAL { ?people foaf:mbox ?mbox . FILTER regex(?mbox, “@gmail”)} } //OPTIONAL을 여러개 추가 가능

Alternative Graph Pattern

SELECT ?people ?mboxWHERE {

{?people foaf:name ?name .}UNION{?people naver:name ?name .}

}//UNON대상 여러가 추가 가능{?people foaf:name ?name . ?people foaf:knows ?name}UNION{? people naver:name ?name. ?people naver:knows ?name}

2009년 10월 31일 토요일

Page 34: RDF Tutorial - SPARQL 20091031

String Value Constraint

Constraint

Numeric Value Constraint

SELECT ?people, ?nameWHERE {

?people :name ?name FILTER regex(?name, “^kwan”, “i”) } //kwan으로 시작하는 사람

SELECT ?people, ?ageWHERE {

?people :age ?age. FILTER (?age > 30) } //30 이상인 사람

2009년 10월 31일 토요일

Page 35: RDF Tutorial - SPARQL 20091031

PREFIX foaf: <http://xmlns.com/foaf/0.1/>.PREFIX : <http://RDFTutorial.net/2009/>.SELECT ?nameWHERE {

?_a :age ?age.FILTER ( ?age >= 35 )?_a foaf:knows ?_b.?_b :age ?b_age; foaf:name ?name.FILTER ( ?b_age <= 35)

}

나이 35세 이상인 사람이 아는 35세 이하의 사람?

Play #

_bfoaf:knows

foaf:name

Haklae

_a

36

:agefoaf:name

Dongbum 35

:age

?_a :age ?age.?_a foaf:knows ?_b.?_b :age ?b_age; foaf:name ?name.FILTER ( ?age >= 35 )FILTER ( ?b_age <= 35)

2009년 10월 31일 토요일

Page 36: RDF Tutorial - SPARQL 20091031

Order

Solution Sequences and Modifiers

SELECT ?s ?p ?oWHERE {

?s ?p ?o} //모든 SPO반환ORDER BY ?o // ???

SELECT ?people, ?nameWHERE {

?people :name ?name}ORDER BY ?name //기본 오름차순 A-Z, DESC(?name)

2009년 10월 31일 토요일

Page 37: RDF Tutorial - SPARQL 20091031

PREFIX : <http://RDFTutorial.net/2009/>.SELECT ?userWHERE {

?user :age ?age.}ORDER BY ?age.

나이순으로 정렬?

Play #

_b_a

:age

21

:age

33

_c

:age

26

_d

:age

45

2009년 10월 31일 토요일

Page 38: RDF Tutorial - SPARQL 20091031

Offset

Solution Sequences and Modifiers

SELECT ?s ?p ?oWHERE { ?s ?p ?o.}OFFSET 10 //11번째 부터 solutions 반환

LIMIT

SELECT ?s ?p ?oWHERE { ?s ?p ?o.}LIMIT 10 //10개 solutions 반환

SELECT ?s ?p ?oWHERE { ?s ?p ?o.}LIMIT 5OFFSET 10 //함께 사용 가능

2009년 10월 31일 토요일

Page 39: RDF Tutorial - SPARQL 20091031

PREFIX : <http://RDFTutorial.net/2009/>.SELECT ?userWHERE {

?user :age ?age.}ORDER BY ?age.LIMIT 2 .

Play #

_b_a

:age

21

:age

33

_c

:age

26

_d

:age

45

나이순으로 정렬후, 결과 2개?

2009년 10월 31일 토요일

Page 40: RDF Tutorial - SPARQL 20091031

ASK

Query Form

PREFIX foaf: <http://xmlns.com/foaf/0.1/>ASK { ?x foaf:name "Alice"; :age ?age. FILTER ( ?age > 20)}

DESCRIBE

PREFIX ent: <http://org.example.com/employees#>DESCRIBE ?x WHERE { ?x ent:employeeId "1234" }

2009년 10월 31일 토요일

Page 41: RDF Tutorial - SPARQL 20091031

Simple Protocol ARQL

2009년 10월 31일 토요일

Page 42: RDF Tutorial - SPARQL 20091031

Endpoint

우리팀너네팀옆팀

Simple Protocol & RDF Endpoint

HTTPSOAP

...

2009년 10월 31일 토요일

Page 43: RDF Tutorial - SPARQL 20091031

GET /sparql/?query=EncodedQuery HTTP/1.1Host: www.exampleUser-agent: my-sparql-client/0.1

Request

<sparql ...> <head> <variable name="x"/> <variable name="mbox"/> </head>

<results> <result> <binding name="x"> <bnode>r2</bnode> </binding> <binding name="mbox"> <uri>mailto:[email protected]</uri> </binding> </result> </results></sparql>

Response

Simple Protocol

* http://www.w3.org/TR/rdf-sparql-protocol/

* HTTP Binding* SOAP Binding

2009년 10월 31일 토요일

Page 44: RDF Tutorial - SPARQL 20091031

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <query-request xmlns="http://www.w3.org/2005/09/sparql-protocol-types/#"> <query>SELECT ?z {?x ?y ?z . FILTER regex(?z, 'Harry')}</query> </query-request> </soapenv:Body> </soapenv:Envelope>

Request

<sparql ...> <head> <variable name="x"/> <variable name="mbox"/> </head>

<results> <result> <binding name="x"> <bnode>r2</bnode> </binding> <binding name="mbox"> <uri>mailto:[email protected]</uri> </binding> </result> </results></sparql>

Response

Simple Protocol

* http://www.w3.org/TR/rdf-sparql-protocol/

* HTTP Binding* SOAP Binding

2009년 10월 31일 토요일

Page 45: RDF Tutorial - SPARQL 20091031

Here is a Semantic Web?

2009년 10월 31일 토요일

Page 46: RDF Tutorial - SPARQL 20091031

SPARQL 1.1

2009년 10월 31일 토요일

Page 47: RDF Tutorial - SPARQL 20091031

Aggregate Functions

Subqueries

Negation

Projection Expressions

Query Language Syntax

Property paths

Commonly used SPARQL functions

Basic federated query

SPARQL 1.1

* WG에서 스팩 조정중이며, 변경될 수 있습니다.

2009년 10월 31일 토요일

Page 48: RDF Tutorial - SPARQL 20091031

Aggregate functions

Ex.SELECT COUNT(?person) AS ?alicesWHERE {

?person :name “Alice” .}

Existing implementation. Garlik’s JXT, Dave Beckett’s Redland, ARQ, Open Anzo’s Glitter, Virtuoso, ARC

Status. Required

COUNT, MAX, MIN, SUM, AVG

2009년 10월 31일 토요일

Page 49: RDF Tutorial - SPARQL 20091031

Subqueries

Ex.SELECT ?person ?name WHERE {

:Alice foaf:name ?person .{

SELECT ?name WHERE {?person foaf:name ?name .

} LIMIT 1}

}

Existing implementation. ARQ, Virtuoso

Status. Required

2009년 10월 31일 토요일

Page 50: RDF Tutorial - SPARQL 20091031

Negation (1/2)

Ex.ex) Identify the name of people who do not know anyone.SELECT ?nameWHERE {

?x foaf:givenName ?name .OPTION { ?x foaf:knows ?who } .FILTER (!BOUND(?who))}

Existing implementation. RDF::QUERY (unsaid keyword), SeRQL (MINUS keyword), ARQ (NOT EXIST keyword), SQL

Status. Required

2009년 10월 31일 토요일

Page 51: RDF Tutorial - SPARQL 20091031

Negation (2/2)

SeRQL (MINUS)

SELECT xFROM {x} foaf:givenName {name}

MINUSSELECT x

FROM {x} foaf:givenName {name} ;foaf:knows {who}

USING NAMESPACE foaf = <http://xmlns.com/foaf/0.1/>

UNSAID

PREFIX foaf: <http://xmlns.com/foaf/0.1/>SELECT ?xWHERE {

?x foaf:givenName ?nameUNSAID { ?x foaf:knows ?who }

}

2009년 10월 31일 토요일

Page 52: RDF Tutorial - SPARQL 20091031

Project Expressions

Ex.

SELECT ?name (?age > 18) AS over 18WHERE {

?person :name ?name ; :age ?age .

}

Existing implementation. Garlik’s JXT, Dave Beckett’s Redland, ARQ, Virtuoso, Open Anzo’s Glitter SPARQL Engine, XSPARQL

Status. Required

2009년 10월 31일 토요일

Page 53: RDF Tutorial - SPARQL 20091031

UpdateEx.INSERT DATA{ :book1 dc:title “new book”; dc:creator “someone”.}

DELETE { ?book ?p ?v }WHERE{ ?book dc:date ?date . FILTER ( ?date < “2001-01-01T00:00:00^^xsd:dateTime ) ?book ?p ?v.}

Existing implementation. ARQ, Virtuoso

Status. Required

Update with HTTP PUT, DELETEExisting implementation. Garlik’s JXT, IBM’s Jazz Foundation

2009년 10월 31일 토요일

Page 54: RDF Tutorial - SPARQL 20091031

Garlik’s JXT Dave Beckett’s Redland

ARQ Open Anzo’s Glitter

Virtuoso ARC SeRQL RDF::Query SQL XSPARQL IBM’s Jazz Foundation

Aggregation COUNT()

SUM()

AVG()

MAX()

MIN()

Subqueries

Negation

Project expressions

Service description

UPDATE

Protocol Enhancements for Update

O O O O O O

O O O O

O O O O

O O O

O O O

O O

O O O O

O O O O O O

O O O

O O

O O

* WG에서 스팩 조정중이며, 변경될 수 있습니다.

Aggregate FunctionsSubqueriesNegation

Projection ExpressionsService description

Update (REST)

Garlik’s JXT Dave Beckett’s Redland

ARQ Open Anzo’s Glitter

Virtuoso ARC

SeRQL RDF::Query

SQL XSPARQL

IBM’s Jazz Foundation

2009년 10월 31일 토요일

Page 55: RDF Tutorial - SPARQL 20091031

Links

http://groups.google.com/group/semanticwebstudy?hl=ko

http://delicious.com/kwangsub.kim/bundle:RDFTutorial2009

SPARQL 이해(IBM DevWorks) : http://www.ibm.com/developerworks/kr/library/tutorial/x-sparql/

SPARQL Working Group :http://www.w3.org/2009/sparql/wiki/Main_Page

2009년 10월 31일 토요일

Page 56: RDF Tutorial - SPARQL 20091031

수고하셨습니다.

감사합니다.2009년 10월 31일 토요일

Page 57: RDF Tutorial - SPARQL 20091031

네이버랩 : http://lab.naver.com시맨틱영화검색 : http://semantic.lab.naver.comNHN 시맨틱웹TF

2009년 10월 31일 토요일

Page 58: RDF Tutorial - SPARQL 20091031

2009년 10월 31일 토요일

Page 59: RDF Tutorial - SPARQL 20091031

시맨틱웹스터디 모임http://groups.google.com/group/semanticwebstudy?hl=ko

시맨틱웹컨퍼런스 - 기업초청

2009년 10월 31일 토요일