SPARQL
                    NHN
               kwangsub.kim@gmail.com




                               RDF Tutorial 2009....
RDF             !
               SPARQL               !
                PLAY        !
               SPARQL 1.1           ...
http://delicious.com/kwangsub.kim/bundle:RDFTutorial2009




                http://vocamp.org/wiki/VoCampSeoul2009#Slides...
RDF
       Resource Description Framework
                                                (   )   !


                    ...
Graph             ?




               SPARQL

                      <sparql ...>
                       <head>
          ...
2008-07-16




                                 ...
*http://pingthesemanticweb.com
2008-11-04




                                 ...
*http://pingthesemanticweb.com
2009-01-08




                                 ...
*http://pingthesemanticweb.com
2008-07-16            2009-10-31
                                           2008-11-04
                                   ...
GRDDL     SPARQL
SPARQL
Simple Protocol And RDF Query Language
                 is a query language and a protocol for accessing RDF
      ...
SPA RDF Query Language
Query Language
SQL vs. SPARQL
                                                     Return Variables



SELECT name                       ...
Graph > Query Language > Binding > Protocol

                           rdf:type                       SELECT ?name
      ...
SPARQL

               BASE <http://example.org/>
               PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>...
Terms

               Sytax

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

               NameSpace :Vocabulary                   URI
                    http://www.w3.org/1999/02/22-rdf-syn...
Terms

     Match
      : Graph            SPO   Query Pattern   Match



     Solutions : Match
                ?x = “   ...
Play #
               “   ”              “email” ?


                                    :email
                        _p...
Syntax - RDF Term Syntax
          Literals

          “Hi Korea”   //”Hi Korea”

          “Hi Korea”@en    //

         ...
Play #
                kwangsub                               email   ?


                                :email
         ...
Syntax - RDF Term Syntax
          IRI
          <http://example.org/book/book1>


          BASE <http://example.org/book...
Syntax -Triple Pattern Syntax
          PREFIX, BASE

          PREFIX dc: <http://purl.org/dc/elements/purl.org/>
       ...
Play #
                 kwangsub                                   email   ?


                                       :lik...
Syntax - RDF Term Syntax
          Query Var
                 ?var or $var


          Blank
                 [ :p “v”]. =...
Play .#
               foaf:name      kwangsub.kim                          name?


                              _a      ...
Syntax ; ,
          ;,
          ?people foaf:name ?name ;
                    foaf:mbox ?mbox .


                      ...
Play #
                   kwangsub               “           ”                          ?


                              ...
Pattern
          Basic Graph Pattern
          {?people foaf:name "kwangsub".}



          Group Graph Pattern
         ...
Pattern
          Optional Graph Pattern

               _:a   rdf:type    foaf:Person .
               _:a   foaf:name   ...
Pattern
          Optional Graph Pattern + FILTER
               SELECT ?people ?mbox
               WHERE {
             ...
Constraint
          String Value Constraint

               SELECT ?people, ?name
               WHERE {
                ...
Play #
                      35                               35                 ?

                                      ...
Solution Sequences and Modifiers

          Order
               SELECT ?people, ?name
               WHERE {
             ...
Play #
                                                          ?

                                                      ...
Solution Sequences and Modifiers
          Offset
                SELECT ?s ?p ?o
                WHERE {
                 ...
Play #
                                                 ,        2      ?

                                               ...
Query Form

          ASK
          PREFIX foaf: <http://xmlns.com/foaf/0.1/>
          ASK {
           ?x foaf:name "Ali...
Simple Protocol ARQL
Simple Protocol & RDF Endpoint




                                       HTTP
                                       SOAP...
Simple Protocol
                                                          * HTTP Binding
                                 ...
Simple Protocol
                                                                  * HTTP Binding
Request                  ...
Here is a
                 Semantic Web?
SPARQL 1.1
SPARQL 1.1

                            Aggregate Functions
                                Subqueries
                   ...
Aggregate functions


          Ex. COUNT, MAX, MIN, SUM, AVG
               SELECT COUNT(?person) AS ?alices
            ...
Subqueries

          Ex.
               SELECT ?person ?name WHERE {
                 :Alice foaf:name ?person .
        ...
Negation (1/2)

          Ex.
          ex) Identify the name of people who do not know anyone.
          SELECT ?name
   ...
Negation (2/2)
          SeRQL (MINUS)
          SELECT x
            FROM {x} foaf:givenName {name}
          MINUS
     ...
Project Expressions

          Ex.
               SELECT ?name (?age > 18) AS over 18
               WHERE {
             ...
Update
          Ex.
               INSERT DATA
               {
                 :book1 dc:title “new book”;
            ...
Garlik’s JXT
                         Aggregate Functions                                              Dave Beckett’s Redl...
Links


     http://groups.google.com/group/semanticwebstudy?hl=ko
     http://delicious.com/kwangsub.kim/bundle:RDFTutori...
.




               .
: http://lab.naver.com
                               : http://semantic.lab.naver.com
               NHN          TF




	...
-



http://groups.google.com/group/semanticwebstudy?hl=ko
RDF Tutorial - SPARQL 20091031
Upcoming SlideShare
Loading in...5
×

RDF Tutorial - SPARQL 20091031

5,806

Published on

RDF Tutorial - SPARQL

http://www.onoffmix.com/e/sonagi/1116

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
5,806
On Slideshare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
283
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

RDF Tutorial - SPARQL 20091031

  1. 1. SPARQL NHN kwangsub.kim@gmail.com RDF Tutorial 2009. 10. 31
  2. 2. RDF ! SPARQL ! PLAY ! SPARQL 1.1 !
  3. 3. http://delicious.com/kwangsub.kim/bundle:RDFTutorial2009 http://vocamp.org/wiki/VoCampSeoul2009#Slides http://delicious.com/kwangsub.kim/%23VoCampSeoul2009
  4. 4. RDF Resource Description Framework ( ) ! ! Subject - Predicate - Object ! , (RSS) , (FOAF) ...
  5. 5. 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:bob@work.example.org</uri> </binding> </result> </results> </sparql>
  6. 6. 2008-07-16 ... *http://pingthesemanticweb.com
  7. 7. 2008-11-04 ... *http://pingthesemanticweb.com
  8. 8. 2009-01-08 ... *http://pingthesemanticweb.com
  9. 9. 2008-07-16 2009-10-31 2008-11-04 2009-01-08 200% 200% 4,955,878 16,705,060 7,504,227 8,826,082 *http://pingthesemanticweb.com
  10. 10. GRDDL SPARQL
  11. 11. SPARQL Simple Protocol And RDF Query Language is a query language and a protocol for accessing RDF <sparql ...> Simple Protocol <head> <variable name="x"/> <variable name="mbox"/> </head> http://semantic.lab.naver.com/rdf/endpoint/sparql?select.... <results> <result> <binding name="x"> SELECT ?email <bnode>r2</bnode> WHERE { </binding> <binding name="mbox"> ?user :email ?email. <uri>mailto:bob@work.exampl ?user :name “ ”; </binding> & } </result> </results> </sparql> RDF Query Language Graph SPO (Subject, Predicate, Object) Query Language Pattern Match
  12. 12. SPA RDF Query Language
  13. 13. Query Language
  14. 14. SQL vs. SPARQL Return Variables SELECT name SELECT ?name FROM users WHERE { WHERE contact=‘011-201-0000’; ?user rdf:type :User. ?user :name ?name. ?user :contact “011-201-0000”. SPO Pattern } FROM <http://semantic/users.rdf> Graph Source
  15. 15. Graph > Query Language > Binding > Protocol rdf:type SELECT ?name _person foaf:Person WHERE { :contact ?user rdf:type foaf:Person. “011-201-0000” :name ?user :contact “011-201-0000”. ?user :name ?name. } <http://semantic/users.rdf> FROM <http://semantic/users.rdf> <sparql xmlns=”http://www.w3.org...”> <head> <variable name="name"/> </head> ?name = “ ” <results> <result> <binding name="name"> <literal> </literal> </binding> </result> </results> </sparql>
  16. 16. 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.
  17. 17. Terms Sytax Pattern
  18. 18. 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
  19. 19. 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 : IRI or Blank Node Predicate : IRI Object : IRI or Blank Node or Literal
  20. 20. Terms Match : Graph SPO Query Pattern Match Solutions : Match ?x = “ ” Query Variable : Solutions ?x or $name
  21. 21. Play # “ ” “email” ? :email _person kwangsub.kim@gmail.com :name SELECT ?email WHERE { ?person :email ?email. ?person :name “ ”; }
  22. 22. 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
  23. 23. Play # kwangsub email ? :email _person kwangsub.kim@gmail.com :name kwangsub@en SELECT ?email WHERE { ?person :name “kwangsub”@en. ?person :email ?email. }
  24. 24. Syntax - RDF Term Syntax IRI <http://example.org/book/book1> BASE <http://example.org/book/> <book1> PREFIX book: <http://example.org/book/> book:book1
  25. 25. 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 }
  26. 26. Play # kwangsub email ? :like _person book:book_3 :name book:name kwangsub@en 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. }
  27. 27. 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>
  28. 28. Play .# foaf:name kwangsub.kim name? _a :love _b :name foaf:name kwangsub.kim soomers PREFIX foaf: <http://xmlns.com/foaf/0.1/>. PREFIX : <http://RDFTutorial.net/2009/>. SELECT $name WHERE { ?_a foaf:name “kwangsub.kim”. ?_a :love $_b. $_b <http://RDFTutorial.net/2009/name> $name. }
  29. 29. 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_" .
  30. 30. Play # kwangsub “ ” ? foaf:knows _a _b foaf:nickname foaf:name foaf:name kwangsub SangWon PREFIX foaf: <http://xmlns.com/foaf/0.1/>. SELECT ?name WHERE { ?_a foaf:nickname “ ”; foaf:name “kwangsub”. ?_a foaf:knows ?_b. ?_b foaf:name ?name. }
  31. 31. Pattern Basic Graph Pattern {?people foaf:name "kwangsub".} Group Graph Pattern { {?people foaf:name "kwangsub".} {?people foaf:email "kwangsub.kim@gmail.com".} } // Filter { ?people foaf:name ?name. FILTER regex (?name, “kw”) }
  32. 32. 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 } }
  33. 33. 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}
  34. 34. Constraint String Value Constraint SELECT ?people, ?name WHERE { ?people :name ?name FILTER regex(?name, “^kwan”, “i”) } //kwan Numeric Value Constraint SELECT ?people, ?age WHERE { ?people :age ?age. FILTER (?age > 30) } //30
  35. 35. Play # 35 35 ? foaf:knows _a _b :age foaf:name :age foaf:name 36 Dongbum 35 Haklae 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) }
  36. 36. 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 // ???
  37. 37. Play # ? _d _b _a _c :age :age :age :age 45 33 21 26 PREFIX : <http://RDFTutorial.net/2009/>. SELECT ?user WHERE { ?user :age ?age. } ORDER BY ?age.
  38. 38. 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 10 //10 solutions LIMIT 5 OFFSET 10 //
  39. 39. Play # , 2 ? _d _b _a _c :age :age :age :age 45 33 21 26 PREFIX : <http://RDFTutorial.net/2009/>. SELECT ?user WHERE { ?user :age ?age. } ORDER BY ?age. LIMIT 2 .
  40. 40. 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" }
  41. 41. Simple Protocol ARQL
  42. 42. Simple Protocol & RDF Endpoint HTTP SOAP ... Endpoint
  43. 43. Simple Protocol * HTTP Binding * SOAP Binding Request GET /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/
  44. 44. Simple Protocol * HTTP Binding Request * SOAP Binding <?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://www.w3.org/TR/rdf-sparql-protocol/
  45. 45. Here is a Semantic Web?
  46. 46. SPARQL 1.1
  47. 47. SPARQL 1.1 Aggregate Functions Subqueries Negation Projection Expressions Query Language Syntax Property paths Commonly used SPARQL functions Basic federated query * WG , .
  48. 48. 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
  49. 49. 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
  50. 50. 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
  51. 51. 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 } }
  52. 52. 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
  53. 53. 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
  54. 54. Garlik’s JXT Aggregate Functions Dave Beckett’s Redland Subqueries ARQ Open Anzo’s Glitter Negation Virtuoso Projection Expressions ARC SeRQL Service description RDF::Query Update (REST) SQL XSPARQL IBM’s Jazz Foundation Garlik’s JXT Dave ARQ Open Anzo’s Virtuoso ARC SeRQL RDF::Query SQL XSPARQL IBM’s Jazz Beckett’s Glitter Foundation Redland Aggregation COUNT() O O O O O O SUM() O O O O AVG() O O O O MAX() O O O MIN() O O O Subqueries O O Negation O O O O Project expressions O O O O O O Service description O O O UPDATE O O Protocol O O Enhancements for Update * WG , .
  55. 55. 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
  56. 56. . .
  57. 57. : http://lab.naver.com : http://semantic.lab.naver.com NHN TF
  58. 58. - http://groups.google.com/group/semanticwebstudy?hl=ko
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×