semantic web(web 3.0) sparql

Post on 11-May-2015

3.560 Views

Category:

Technology

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

Semantic Web(Web 3.0) SPARQL

TRANSCRIPT

Web 3.0

SPARQL / XML Query

Presenter Um Dae jin (mrumx@naver.com)Internet Technology

Graduate school of information & Telecommunications in KONKUK University

Agenda

Introduction

RDF & SPARQL

SPAR Query Language

Get the Knowledge

Term | Syntax | Pattern | Constraint

Simple protocol

SPARQL 1.1

Introduction

RDF, SPARQL

RDF(Resource Description Framework)

Resource Description Framework

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

Resource : URI를 갖는 모든것(웹페이지,이미지,동영상 등)

Description : Resource들의 속성, 특성, 관계 기술

Framework : 위의 것들을 기술하기 위한 모델, 언어, 문법

RDF(Resource Description Framework)

Object

This is the Framework!!!

주어 술어 목적어

(Resource) (Property, Relation) (Resource, Literal)

PredicateSubject

URI URI URI

Blank Node Literal

RDF(Resource Description Framework)

우리는 그 틀에 맞취 어떤것들을 기술만 할뿐~!!!

웹상에서 표현될 수 있는 개념들

블로그(Blog), 온라인 매체(RSS), 사람, 친구(FOAF) …etc ~!!!

RDF(Resource Description Framework)

PingtheSemanticWeb.com is a repository for RDF documents. http://pingthesemanticweb.com/

These namespaces are used to describe entities in X number of documents

2008.7.16 2008.11.04 2009.1.8

2009.11.23

SPARQL

Music

Person

Picture

RegionDictionary

GRDDL(Gleaning Resource Descriptions from Dialects of Languages)

Simple Protocol And

RDF Query Language

SPARQL

RDF<sparql …>

<head>

<variable name=“x”/>

<variable name=“mbox”/>

</head>

<results>

<result>

<binding name=“x”>

<bnode> r2</bnode>

</binding>

<binding name=“mbox”>

<uri>mailto:bob@work.example.com</uri>

</binding>

</result>

<results>

</sparql>

Simple Protocolhttp://semantic.lab.konkuk.ac.kr/rdf/endpoint/sparql?select …

SELECT ?email

WHERE {

?user :email ?email.

?user :name “umdaejin”;

}

&

RDF Query LanguageRDF Query language is the pattern matched SPO(Subject, Predicate, Object) in Graph

SPARQL is

Query Language and

a protocol for accessing RDF

SPA RDF Query Language

Query Language

SQL vs. SPARQL

SELECT name

FROM users

WHERE contact=„010-3333-7777‟;

SELECT ?name

WHERE {

?user rdf:type :User.

?user :name ?name.

?user :contact “010-3333-7777”.

}

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

Return Variables

SPO Pattern

Graph Source

Graph > Query Language > Binding > Protocol

foaf:Person_person

“010-3333-7777”

“umdaejin”

rdf:type

:contact

:name

SELECT ?name

WHERE {

?user rdf:type :foaf:Person.

?user :contact “010-3333-7777”.

?user :name ?name.

}

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

RDF<sparql xmlns=“http://www.w3.org…”>

<head>

<variable name=“name”/>

</head>

<results>

<result>

<binding name=“name”>

<literal> umdaejin</literal>

</binding>

</result>

<results>

</sparql>

?name = “umdaejin”

SPARQL

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 RDF Query Language Reference V1.8 by Dave Beckett.

Get the Knowledge

TERMS Syntax Pattern

Terms

IRI : URI reference within an RDF graph<http://www.w3.org>

<http://semantic.konkuk.ac.kr/#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

“daejin”^^http://www.w3.org/2001/XMLSchema#string

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

Terms

NameSpace : Vocabulary가 있는 URI

http://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

RDF Graph : A Set of RDF Triples

RDF Triple : S-P-O

Subject : URI, Qname, Blank Node, Literal, Variable

Predicate : URI, Qname, Blank node, Variable

Object : URI, Qname, Blank node, Literal, Variable

Terms

Match

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

Solutions : Match되어 반환된 결과들

?x = “엄대진”

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

?x or $name

Play#

SELECT ?email

WHERE {

?person :email ?email.

?person :name “umdaejin”;

}

“umdaejin”이란 사람의 “email”은?

mrumx@naver.com_person

“umdaejin”

:email

:name

Syntax - RDF Term Syntax

Literals

“Hi Korea” //”Hi Korea”

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

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

1 == “1”^^xsd:integer

true == “true”^^xsd:boolean

1.3 == “1.3”^^xsd:decimal

Play #

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

mrumx@naver.com_person

umdaejin@en

:email

:name

SELECT ?email

WHERE {

?person :name “umdaejin”@en.

?person :email ?email.

}

Syntax - RDF Term Syntax

IRI

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

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

<book1>

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

book:book1

Syntax -Triple Pattern Syntax

PREFIX, BASE

PREFIX dc: <http://purl.org/dc/elements/purl.org/>

SELECT ?title

WHERE { <http://example.org/book/book> dc:title ?title }

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

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

SELECT $title

WHERE { :book1 dc:title $title }

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

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

SELECT $title

WHERE { <book1> dc:title $title }

Play #

daejin의 영문이름을 가진 사람의 책제목은?

BASE <http://RDFTutorial.net/2009/>

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

SELECT ?book_name

WHERE {

?person :like book:book_3.

book:book_3 book:name ?book_name.

}

_person

“ANT”“daejin@en”

:like

book:name:name

Book:book_3

Syntax - RDF Term Syntax

Query Var

?var or $var

Blank

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

Unique Blank - 다른 IRI과 연결용

_b57 :p “v”. //기본 예

[ foaf:name ?name ;

foaf:mbox <mailto:ss@c.com>] / / 확장 예

_b11 foaf:name ?name ;은 S에 PO를 연속해서 붙일 수 있다.

_b11 foaf:mbox <mailto:ss@c.com>

Play #

foaf:name이 umdaejin사람이 사랑하는 사람 name?

PREFIX foaf: <http://xmlns.com/foaf/0.1/>.

PREFIX : <http://RDFTutorial.net/2009/>.

SELECT $name

WHERE {

?_a foaf:name “umdaejin”.

?_a :love $_b.

$_b <http://RDFTutorial.net/2009/name> $name.

}

_a

“sunyoung”“umdaejin”

:love

namefoaf:name

_b

Syntax ; ,

?people foaf:name ?name ;

foaf:mbox ?mbox .

우린 같아요~

?people foaf:name ?name .

?people foaf:mbox ?mbox .

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

우린 같아요~

?people foaf:nick "Alice" .

?people foaf:nick "Alice_" .

Play #

이름이 umdaejin이고 별명이 “무름스”인 사람이 아는 사람의 이름?

PREFIX foaf: <http://xmlns.com/foaf/0.1/>.

SELECT ?name

WHERE {

?_a foaf:nickname “무름스”;

foaf:name “umdaejin”.

?_a foaf:knows ?_b.

?_b foaf:name ?name.

}

_a

“SangWon”“umdaejin”

foaf:knows

foaf:namefoaf:name

_b

“무름스”

foaf:nickname

Pattern

Basic Graph Pattern

{?people foaf:name “umdaejin".}

Group Graph Pattern

{

{?people foaf:name “umdaejin".}

{?people foaf:email “umdaejin@gmail.com".}

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

Filter

{

?people foaf:name ?name.

FILTER regex (?name, “um”)

}

Pattern

Optional Graph Pattern

_:a rdf:type foaf:Person .

_:a foaf:name "Alice" .

_:a foaf:mbox <mailto:alice@example.com> .

_:a foaf:mbox <mailto:alice@work.example> .

_:b rdf:type foaf:Person .

_:b foaf:name "Bob" .

SELECT ?name ?mbox

WHERE {

?people foaf:name ?name .

OPTIONAL { ?people foaf:mbox ?mbox }

}

Pattern

Optional Graph Pattern + FILTER

SELECT ?people ?mbox

WHERE {

?people foaf:name ?name .

OPTIONAL { ?people foaf:mbox ?mbox .

FILTER regex(?mbox, “@gmail”)}

} //OPTIONAL을 여러개 추가 가능

Alternative Graph Pattern

SELECT ?people ?mbox

WHERE {

{?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}

Constraint

String Value Constraint

SELECT ?people, ?name

WHERE {

?people :name ?name

FILTER regex(?name, “^um”, “i”)

} //이름이 um으로 시작하는 사람

Numeric Value Constraint

SELECT ?people, ?age

WHERE {

?people :age ?age.

FILTER (?age > 30)

} //나이가 30 이상인 사람

Play #

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

PREFIX foaf: <http://xmlns.com/foaf/0.1/>.

PREFIX : <http://RDFTutorial.net/2009/>.

SELECT ?name

WHERE {

?_a :age ?age.

FILTER ( ?age >= 35 )

?_a foaf:knows ?_b.

?_b :age ?b_age;

foaf:name ?name.

FILTER ( ?b_age <= 35)

}

_a

“SangWon”Dongbum

foaf:knows

foaf:namefoaf:name

_b

36

:age

35

:age

?_a :age ?age.

?_a foaf:knows ?_b.

?_b :age ?b_age;

foaf:name ?name.

FILTER ( ?age >= 35 )

FILTER ( ?b_age <= 35)

Solution Sequences and Modifiers

OrderSELECT ?people, ?name

WHERE {

?people :name ?name

}

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

SELECT ?s ?p ?o

WHERE {

?s ?p ?o

} //모든 SPO반환

ORDER BY ?o

Play #

나이순으로 정렬?

_a

21

:age

_b

33

:age

_c

26

:age

_d

45

:age

PREFIX : <http://RDFTutorial.net/2009/>.

SELECT ?user

WHERE {

?user :age ?age.

}

ORDER BY ?age.

Solution Sequences and Modifiers

Offset

SELECT ?s ?p ?o

WHERE {

?s ?p ?o.

}

OFFSET 10 //11번째 부터 solutions 반환

LIMIT

SELECT ?s ?p ?o

WHERE {

?s ?p ?o.

}

LIMIT 10 //10개 solutions 반환

SELECT ?s ?p ?o

WHERE {

?s ?p ?o.

}

LIMIT 5

OFFSET 10 //함께 사용 가능

Play #

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

_a

21

:age

_b

33

:age

_c

26

:age

_d

45

:age

PREFIX : <http://RDFTutorial.net/2009/>.

SELECT ?user

WHERE {

?user :age ?age.

}

ORDER BY ?age.

LIMIT 2 .

Query Form

ASK

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" }

Simple Protocol ARQL

Simple Protocol & RDF Endpoint

Endpoint

HTTP

SOAP

...

우리팀너네팀옆팀

사람들

Simple Protocol

RequestGET /sparql/?query=EncodedQuery HTTP/1.1

Host: www.example

User-agent: my-sparql-client/0.1

Response<sparql ...>

<head>

<variable name="x"/>

<variable name="mbox"/>

</head>

<results>

<result>

<binding name="x">

<bnode>r2</bnode>

</binding>

<binding name="mbox">

<uri>mailto:bob@work.example.org</uri>

</binding>

</result>

</results>

</sparql>

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

* HTTP Binding

* SOAP Binding

Simple ProtocolRequest

<?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>

Response

<sparql ...>

<head>

<variable name="x"/>

<variable name="mbox"/>

</head>

<results>

<result>

<binding name="x">

<bnode>r2</bnode>

</binding>

<binding name="mbox">

<uri>mailto:bob@work.example.org</uri>

</binding>

</result>

</results>

</sparql>

* HTTP Binding

* SOAP Binding

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

SPARQL 1.1

SPARQL 1.1

Aggregate Functions

Subqueries

Negation

Projection Expressions

Query Language Syntax

Property paths

Commonly used SPARQL functions

Basic federated query

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

Aggregate functions

Ex. COUNT, MAX, MIN, SUM, AVG

SELECT COUNT(?person) AS ?alices

WHERE {

?person :name “Alice” .

}

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

Status. Required

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

Negation (1/2)

Ex.

ex) Identify the name of people who do not know anyone.

SELECT ?name

WHERE {

?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

Negation (2/2)

SeRQL (MINUS)

SELECT x

FROM {x} foaf:givenName {name}

MINUS

SELECT 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 ?x

WHERE {

?x foaf:givenName ?name

UNSAID { ?x foaf:knows ?who }

}

Project Expressions

Ex.

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

WHERE {

?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

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

Aggregate Functions

Subqueries

Negation

Projection Expressions

Service 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

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

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

Thanks

top related