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)

     Subject     Predicate       Object



    주어               술어             목적어
(Resource) (Property, Relation) (Resource, Literal)

URI                   URI              URI
Blank Node                             Literal

       This is the Framework!!!
RDF(Resource Description Framework)

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



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

블로그(Blog), 온라인 매체(RSS), 사람, 친구(FOAF) …etc ~!!!
PingtheSemanticWeb.com is a repository for RDF documents.                      http://pingthesemanticweb.com/




            RDF(Resource Description Framework)
                   These namespaces are used to describe entities in X number of documents




                                                  2009.11.23




           2008.7.16                              2008.11.04                         2009.1.8
Picture
           Music
                                                  Person

                                                        Dictionary
        Region

                                               SPARQL
GRDDL(Gleaning Resource Descriptions from Dialects of Languages)
SPARQL
Simple Protocol And
          RDF Query Language
Simple Protocol
http://semantic.lab.konkuk.ac.kr/rdf/endpoint/sparql?select …
                                                   RDF
                                                   <sparql …>
SELECT ?email                                       <head>
                                                     <variable name=“x”/>
WHERE {                                              <variable name=“mbox”/>
                                                    </head>
  ?user :email ?email.
  ?user :name “umdaejin”;                          <results>
                                                    <result>
}                                                    <binding name=“x”>
                                                       <bnode> r2</bnode>
                                                     </binding>
                                                     <binding name=“mbox”>
                                                       <uri>mailto:bob@work.example.com</uri>
                                                      </binding>
                                                     </result>
&                                                   <results>
                                                   </sparql>




RDF Query Language
RDF 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            Return Variables
WHERE {
?user rdf:type :User.
?user :name ?name.                       SPO Pattern
?user :contact “010-3333-7777”.
}
FROM <http://semantic/users.rdf>            Graph Source
Graph > Query Language > Binding > Protocol

               rdf:type                     SELECT ?name
_person                       foaf:Person
                                            WHERE {
                                            ?user rdf:type :foaf:Person.
                 :contact
                                            ?user :contact “010-3333-7777”.
      :name            “010-3333-7777”
                                            ?user :name ?name.
                                            }
                                            FROM <http://semantic/users.rdf>
          “umdaejin”                        RDF
                                            <sparql xmlns=“http://www.w3.org…”>
                                             <head>
                                              <variable name=“name”/>
                                            </head>

                                            <results>
    ?name = “umdaejin”                       <result>
                                              <binding name=“name”>
                                               <literal> umdaejin</literal>
                                              </binding>
                                            </result>
                                             <results>
                                            </sparql>
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#
          “umdaejin”이란 사람의 “email”은?



               :email
_person                 mrumx@naver.com




      :name
                                      SELECT ?email
                                      WHERE {
                                      ?person :email ?email.
          “umdaejin”
                                      ?person :name “umdaejin”;
                                      }
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은?




               :email
_person                 mrumx@naver.com




      :name


                              SELECT ?email
          umdaejin@en
                              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의 영문이름을 가진 사람의 책제목은?
                  :like
    _person                  Book:book_3



                  :name                    book:name


              “daejin@en”                    “ANT”




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

                     :love
        _a                      _b



foaf:name                                name


        “umdaejin”                       “sunyoung”




    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.
    }
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이고 별명이 “무름스”인 사람이 아는 사람의 이름?


                            foaf:knows
                _a                            _b


foaf:nickname        foaf:name                        foaf:name


“무름스”                    “umdaejin”                “SangWon”




         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.
         }
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
                                       {?people foaf:name ?name . ?people foaf:knows ?name}
   WHERE {                             UNION
       {?people foaf:name ?name .}     {? people naver:name ?name. ?people naver:knows ?name}
       UNION
       {?people naver:name ?name .}
   }//UNON대상 여러가 추가 가능
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세 이하의 사람?
                          foaf:knows
             _a                                   _b


 :age             foaf:name                :age        foaf:name


36                Dongbum                 35             “SangWon”

     PREFIX foaf: <http://xmlns.com/foaf/0.1/>.
     PREFIX : <http://RDFTutorial.net/2009/>.
     SELECT ?name
     WHERE {
         ?_a :age ?age.                ?_a :age ?age.
         FILTER ( ?age >= 35 )         ?_a foaf:knows ?_b.
         ?_a foaf:knows ?_b.           ?_b :age ?b_age;
         ?_b :age ?b_age;                  foaf:name ?name.
              foaf:name ?name.         FILTER ( ?age >= 35 )
         FILTER ( ?b_age <= 35)        FILTER ( ?b_age <= 35)
     }
Solution Sequences and Modifiers
Order
SELECT ?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              _b                _c               _d


     :age            :age              :age             :age


        21              33                26               45




             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                    SELECT ?s ?p ?o
   WHERE {                            WHERE {
                                      ?s ?p ?o.
   ?s ?p ?o.
                                      }
   }                                  LIMIT 5
   LIMIT 10 //10개 solutions 반환        OFFSET 10 //함께 사용 가능
Play #
             나이순으로 정렬후, 결과 2개?
_a              _b               _c                _d


     :age            :age             :age              :age


        21              33               26                45




             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

                                   사람들
                            HTTP
                            SOAP
                            ...



                 Endpoint




                                   우리팀
                                   너네팀
                                   옆팀
Simple Protocol
Request
GET /sparql/?query=EncodedQuery HTTP/1.1                                          * HTTP Binding
Host: www.example                                                                 * SOAP Binding
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/
Simple Protocol
Request
<?xml version="1.0" encoding="UTF-8"?>
     <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/"                  * HTTP Binding
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/
     XMLSchema-instance">                                                                        * SOAP Binding
      <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://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
Update
Ex.
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, DELETE
Existing implementation.
Garlik‟s JXT, IBM‟s Jazz Foundation
Aggregate Functions           Garlik‟s JXT
      Subqueries         Dave Beckett‟s Redland
       Negation                    ARQ
Projection Expressions     Open Anzo‟s Glitter
  Service description            Virtuoso
    Update (REST)                  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

Semantic Web(Web 3.0) SPARQL

  • 1.
    Web 3.0 SPARQL / XML Query Presenter Um Dae jin (mrumx@naver.com) Internet Technology Graduate school of information & Telecommunications in KONKUK University
  • 2.
    Agenda Introduction RDF & SPARQL SPARQuery Language Get the Knowledge Term | Syntax | Pattern | Constraint Simple protocol SPARQL 1.1
  • 3.
  • 4.
  • 5.
    RDF(Resource Description Framework) Resource Description Framework 어떤것을 기술하기 위한 구조(틀)일 뿐!!!  Resource : URI를 갖는 모든것(웹페이지,이미지,동영상 등)  Description : Resource들의 속성, 특성, 관계 기술  Framework : 위의 것들을 기술하기 위한 모델, 언어, 문법
  • 6.
    RDF(Resource Description Framework) Subject Predicate Object 주어 술어 목적어 (Resource) (Property, Relation) (Resource, Literal) URI URI URI Blank Node Literal This is the Framework!!!
  • 7.
    RDF(Resource Description Framework) 우리는 그 틀에 맞취 어떤것들을 기술만 할뿐~!!! 웹상에서 표현될 수 있는 개념들 블로그(Blog), 온라인 매체(RSS), 사람, 친구(FOAF) …etc ~!!!
  • 8.
    PingtheSemanticWeb.com is arepository for RDF documents. http://pingthesemanticweb.com/ RDF(Resource Description Framework) These namespaces are used to describe entities in X number of documents 2009.11.23 2008.7.16 2008.11.04 2009.1.8
  • 9.
    Picture Music Person Dictionary Region SPARQL GRDDL(Gleaning Resource Descriptions from Dialects of Languages)
  • 10.
    SPARQL Simple Protocol And RDF Query Language
  • 11.
    Simple Protocol http://semantic.lab.konkuk.ac.kr/rdf/endpoint/sparql?select … RDF <sparql …> SELECT ?email <head> <variable name=“x”/> WHERE { <variable name=“mbox”/> </head> ?user :email ?email. ?user :name “umdaejin”; <results> <result> } <binding name=“x”> <bnode> r2</bnode> </binding> <binding name=“mbox”> <uri>mailto:bob@work.example.com</uri> </binding> </result> & <results> </sparql> RDF Query Language RDF Query language is the pattern matched SPO(Subject, Predicate, Object) in Graph
  • 12.
    SPARQL is Query Language and a protocol for accessing RDF
  • 13.
    SPA RDF QueryLanguage
  • 14.
  • 15.
    SQL vs. SPARQL SELECTname FROM users WHERE contact=„010-3333-7777‟; SELECT ?name Return Variables WHERE { ?user rdf:type :User. ?user :name ?name. SPO Pattern ?user :contact “010-3333-7777”. } FROM <http://semantic/users.rdf> Graph Source
  • 16.
    Graph > QueryLanguage > Binding > Protocol rdf:type SELECT ?name _person foaf:Person WHERE { ?user rdf:type :foaf:Person. :contact ?user :contact “010-3333-7777”. :name “010-3333-7777” ?user :name ?name. } FROM <http://semantic/users.rdf> “umdaejin” RDF <sparql xmlns=“http://www.w3.org…”> <head> <variable name=“name”/> </head> <results> ?name = “umdaejin” <result> <binding name=“name”> <literal> umdaejin</literal> </binding> </result> <results> </sparql>
  • 17.
    SPARQL BASE <http://example.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIXfoaf:<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.
  • 18.
    Get the Knowledge TERMS Syntax Pattern
  • 19.
    Terms IRI : URIreference 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
  • 20.
    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
  • 21.
    Terms Match :Graph내 SPO가 Query Pattern에 Match되는 상황 Solutions : Match되어 반환된 결과들 ?x = “엄대진” Query Variable : Solutions을 바인딩하기 위한 변수 ?x or $name
  • 22.
    Play# “umdaejin”이란 사람의 “email”은? :email _person mrumx@naver.com :name SELECT ?email WHERE { ?person :email ?email. “umdaejin” ?person :name “umdaejin”; }
  • 23.
    Syntax - RDFTerm 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
  • 24.
    Play # umdaejin의영문이름을 가진 사람의 email은? :email _person mrumx@naver.com :name SELECT ?email umdaejin@en WHERE { ?person :name “umdaejin”@en. ?person :email ?email. }
  • 25.
    Syntax - RDFTerm Syntax IRI <http://example.org/book/book1> BASE <http://example.org/book/> <book1> PREFIX book: <http://example.org/book/> book:book1
  • 26.
    Syntax -Triple PatternSyntax 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 }
  • 27.
    Play # daejin의 영문이름을가진 사람의 책제목은? :like _person Book:book_3 :name book:name “daejin@en” “ANT” 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. }
  • 28.
    Syntax - RDFTerm 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>
  • 29.
    Play # foaf:name이 umdaejin사람이사랑하는 사람 name? :love _a _b foaf:name name “umdaejin” “sunyoung” 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. }
  • 30.
    Syntax ; , ?peoplefoaf: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_" .
  • 31.
    Play # 이름이 umdaejin이고별명이 “무름스”인 사람이 아는 사람의 이름? foaf:knows _a _b foaf:nickname foaf:name foaf:name “무름스” “umdaejin” “SangWon” 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. }
  • 32.
    Pattern Basic Graph Pattern {?peoplefoaf:name “umdaejin".} Group Graph Pattern { {?people foaf:name “umdaejin".} {?people foaf:email “umdaejin@gmail.com".} } //두 패턴이 모두 만족해야 Filter { ?people foaf:name ?name. FILTER regex (?name, “um”) }
  • 33.
    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 } }
  • 34.
    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 {?people foaf:name ?name . ?people foaf:knows ?name} WHERE { UNION {?people foaf:name ?name .} {? people naver:name ?name. ?people naver:knows ?name} UNION {?people naver:name ?name .} }//UNON대상 여러가 추가 가능
  • 35.
    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 이상인 사람
  • 36.
    Play # 나이 35세이상인 사람이 아는 35세 이하의 사람? foaf:knows _a _b :age foaf:name :age foaf:name 36 Dongbum 35 “SangWon” PREFIX foaf: <http://xmlns.com/foaf/0.1/>. PREFIX : <http://RDFTutorial.net/2009/>. SELECT ?name WHERE { ?_a :age ?age. ?_a :age ?age. FILTER ( ?age >= 35 ) ?_a foaf:knows ?_b. ?_a foaf:knows ?_b. ?_b :age ?b_age; ?_b :age ?b_age; foaf:name ?name. foaf:name ?name. FILTER ( ?age >= 35 ) FILTER ( ?b_age <= 35) FILTER ( ?b_age <= 35) }
  • 37.
    Solution Sequences andModifiers Order SELECT ?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
  • 38.
    Play # 나이순으로 정렬? _a _b _c _d :age :age :age :age 21 33 26 45 PREFIX : <http://RDFTutorial.net/2009/>. SELECT ?user WHERE { ?user :age ?age. } ORDER BY ?age.
  • 39.
    Solution Sequences andModifiers Offset SELECT ?s ?p ?o WHERE { ?s ?p ?o. } OFFSET 10 //11번째 부터 solutions 반환 LIMIT SELECT ?s ?p ?o SELECT ?s ?p ?o WHERE { WHERE { ?s ?p ?o. ?s ?p ?o. } } LIMIT 5 LIMIT 10 //10개 solutions 반환 OFFSET 10 //함께 사용 가능
  • 40.
    Play # 나이순으로 정렬후, 결과 2개? _a _b _c _d :age :age :age :age 21 33 26 45 PREFIX : <http://RDFTutorial.net/2009/>. SELECT ?user WHERE { ?user :age ?age. } ORDER BY ?age. LIMIT 2 .
  • 41.
    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" }
  • 42.
  • 43.
    Simple Protocol &RDF Endpoint 사람들 HTTP SOAP ... Endpoint 우리팀 너네팀 옆팀
  • 44.
    Simple Protocol Request GET /sparql/?query=EncodedQueryHTTP/1.1 * HTTP Binding Host: www.example * SOAP Binding 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/
  • 45.
    Simple Protocol Request <?xml version="1.0"encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/" * HTTP Binding xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/ XMLSchema-instance"> * SOAP Binding <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://www.w3.org/TR/rdf-sparql-protocol/
  • 47.
  • 48.
    SPARQL 1.1 Aggregate Functions Subqueries Negation Projection Expressions Query Language Syntax Property paths Commonly used SPARQL functions Basic federated query * WG에서 스팩 조정중이며, 변경될 수 있습니다.
  • 49.
    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
  • 50.
    Subqueries Ex. SELECT ?person ?nameWHERE { :Alice foaf:name ?person . { SELECT ?name WHERE { ?person foaf:name ?name . } LIMIT 1 } } Existing implementation. ARQ, Virtuoso Status. Required
  • 51.
    Negation (1/2) Ex. ex) Identifythe 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
  • 52.
    Negation (2/2) SeRQL (MINUS) SELECTx 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 } }
  • 53.
    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
  • 54.
    Update Ex. 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, DELETE Existing implementation. Garlik‟s JXT, IBM‟s Jazz Foundation
  • 55.
    Aggregate Functions Garlik‟s JXT Subqueries Dave Beckett‟s Redland Negation ARQ Projection Expressions Open Anzo‟s Glitter Service description Virtuoso Update (REST) ARC SeRQL RDF::Query SQL XSPARQL IBM‟s Jazz Foundation * WG에서 스팩 조정중이며, 변경될 수 있습니다.
  • 56.
    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
  • 57.