Ajax(Asynchronous JavaScript and XML) by zwj23860


									                        Chungnam National University
                        DataBase System Lab.

Query Language for RDF

          충남대학교 컴퓨터공학과
        데이터베이스 시스템 연구실
            2010년 2월 1일 월요일
    SPARQL Status

    SPARQL Overview
    SPARQL Feature

    Summary
    References

    Appendix

Chungnam National University   2
DataBase System Lab.
    SPARQL Status
    SPARQL Query Language for RDF
         W3C, http://www.w3.org/TR/2007/WD-rdf-sparql-query-
         Published W3C Working Draft 26 March 2007
    SPARQL Protocol for RDF
         W3C, http://www.w3.org/TR/2006/CR-rdf-sparql-protocol-
         Published W3C Candidate Recommendation 6 April 2006
    SPARQL Query Results XML Format
         W3C, http://www.w3.org/TR/2006/CR-rdf-sparql-XMLres-
         Published W3C Candidate Recommendation 6 April 2006

Chungnam National University                                       3
DataBase System Lab.
    SPARQL Overview
    RDF
         Resource Description Framework
         Flexible and extensible way to represent information about
          WWW resources
         SPARQL Protocol And RDF Query Language
         Query Language + Protocol + XML Results Format
         Product of the RDF Data Access Working Group
         A query language for access and query RDF graphs
         A protocol for issuing queries via HTTP GET, HTTP POST,
          or SOAP
         Perfect for mashing up disparate data sources representable
          as RDF

Chungnam National University                                           4
DataBase System Lab.
    SPARQL Overview
    It provides facilities to:
         Extract information in the form of URIs, blank nodes, plain
          and typed literals
         Extract RDF subgraphs
         Construct new RDF graphs based on information in the
          queried graphs
    Feature
         Matching graph patterns
         Variables – global scope; indicated by ‘?‘ or ‘$‘
         Query terms – based on Turtle syntax
         Terms delimited by "<>" are relative URI references
         Data description format - Turtle

Chungnam National University                                            5
DataBase System Lab.
      SPARQL Query Example

   Find the URL of
   the blog by the
                                   Figure 1. Basic graph structure for a single contributor in bloggers.rdf
   person named
   Jon Foobar                        Listing 1. SPARQL query to find the URL of a contributor's blog

                                   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                                   SELECT ?url
                                   FROM <bloggers.rdf>
                                   WHERE {
                                           ?contributor foaf:name "Jon Foobar" .
                                           ?contributor foaf:weblog ?url .
    Chungnam National University                                                                          6
    DataBase System Lab.
                                Chungnam National University
                                DataBase System Lab.

SPARQL Features

     Graph Patterns
     RDF Dataset
     Result Forms
     Testing Values
     Inference
     Data Virtualization
     Access Multiple Sources
     SPARQL Protocol
     Walkthrough
     Graph Patterns
        Set of Triple Patterns
            Triple Pattern – similar to an RDF Triple (subject, predicate,
             object), but any component can be a query variable; literal
             subjects are allowed
                             ?book dc:title ?title
            Matching a triple pattern to a graph: bindings between
             variables and RDF Terms

{ ?x ?x ?v }                               rdf:type rdf:type rdf:Property

     x                     v
     rdf:type              rdf:Property

 Chungnam National University                                                 8
 DataBase System Lab.
      Graph Pattern - Multiple Matches
              Data @prefix foaf: <http://xmlns.com/foaf/0.1/> .
                   _:a foaf:name "Johnny Lee Outlaw" .
                   _:a foaf:mbox <mailto:jlow@example.com> .
                   _:b foaf:name "Peter Goodguy" .
                   _:b foaf:mbox <mailto:peter@example.org> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>    Query
SELECT ?name ?mbox
                                                         Group Graph Pattern
WHERE                                                    (set of graph patterns)
{ ?x foaf:name ?name .                                   also!
 ?x foaf:mbox ?mbox }

                   Query Result    name              mbox
                                   "Johnny Lee       <mailto:jlow@example.com>
                                   "Peter Goodguy" <mailto:peter@example.org>
    Chungnam National University                                              9
    DataBase System Lab.
      RDF Dataset
      The RDF data model expresses information as a
      Many RDF data stores hold a multiple RDF graphs
      There is one graph which does not have a name,
       called the background graph, and zero or more
       named graphs, identified by URI reference

# Default graph
@prefix dc: <http://purl.org/dc/elements/1.1/> .

<http://example.org/bob> dc:publisher "Bob" .
<http://example.org/alice> dc:publisher "Alice" .

                                            # Named graph: http://example.org/bob
                                            @prefix foaf: <http://xmlns.com/foaf/0.1/> .

                                            _:a foaf:name "Bob" .
  Chungnam National University                                                           10
                                            _:a foaf:mbox <mailto:bob@oldcorp.example.org> .
  DataBase System Lab.
  Querying the Dataset

# Graph: http://example.org/foaf/aliceFoaf
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@work.example> .
_:a foaf:knows _:b .
_:b foaf:name "Bob" .
_:b foaf:mbox <mailto:bob@work.example> .
_:b foaf:age 32 .
_:b foaf:PersonalProfileDocument <http://example.org/foaf/bobFoaf> .

# Graph: http://example.org/foaf/bobFoaf
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:1 foaf:mbox <mailto:bob@work.example> .
_:1 foaf:PersonalProfileDocument <http://example.org/foaf/bobFoaf>.
_:1 foaf:age 35 .

Chungnam National University                                           11
DataBase System Lab.
  Accessing Graph Labels
       PREFIX foaf: <http://xmlns.com/foaf/0.1/>
       PREFIX data: <http://example.org/foaf/>
       SELECT ?src ?age
       WHERE GRAPH ?src
                 { ( ?x foaf:mbox <mailto:bob@work.example> )
                   ( ?x foaf:age ?age )

                                                src                    age
                                 <http://example.org/foaf/aliceFoaf>   32
                                  <http://example.org/foaf/bobFoaf>    35

       PREFIX foaf: <http://xmlns.com/foaf/0.1/>
       PREFIX data: <http://example.org/foaf/>
       SELECT ?age
       WHERE GRAPH data:bobFoaf
                 { ( ?x foaf:mbox <mailto:bob@work.example> )
                   ( ?x foaf:age ?age )
Chungnam National University                                                 12
DataBase System Lab.
    Result Forms
    SPARQL has a number of query forms for
     returning results
         SELECT
              Returns all, or a subset of the variables bound in a query
               pattern match
              Formats : XML or RDF/XML
         CONSTRUCT
              Returns an RDF graph constructed by substituting variables in
               a set of triple templates
         DESCRIBE
              Returns an RDF graph that describes the resources found
         ASK
              Returns whether a query pattern matches or not

Chungnam National University                                                13
DataBase System Lab.
    Testing Values
    Named functions and syntactically constructed
         Operands: subset of XML Schema DataTypes {xsd:string,
          xsd:decimal, xsd:double, xsd:dateTime} and types derived from
    Subset of XQuery 1.0 and XPath 2.0 functions and
         Operands: xs:string, xs:double, xs:float, xs:decimal, xs:integer,
         Additional operators: sop:RDFterm-equal, sop:bound,
          sop:isURI, sop:isBlank, sop:isLiteral, sop:str , sop:lang,
          sop:datatype, sop:logical-or, sop:logical-and
    Type Promotion : xs:double, xs:float, xs:decimal
         Each of the numeric types is promoted to any type higher in the
          above list when used as an argument to function expecting that
          higher type

Chungnam National University                                              14
DataBase System Lab.
    An RDF graph may be backed by inference
         OWL, RDFS, application, rules
    :x rdf:type :C .
    :C rdfs:subClassOf :D .

    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    SELECT ?type
      ?x rdf:type ?type .

    | type |
    | :C |
    | :D |

Chungnam National University                                    15
DataBase System Lab.
    Data Virtualization
    SPARQL as integrator
         Data remains where it is
         Existing applications untouched
         Data appears as RDF, query to native form
    SPARQL to SQL
         Direct mapping of tables
              Semi-automatic generation of mapping
              SquirrelRDF (also does LDAP)
         Modelled: D2RQ
              High-quality mapping, manually developed

Chungnam National University                              16
DataBase System Lab.
    Federated Query
    Single Point of Access
    Inputs:

         Service Description
         Information Directory
         Request
    Outputs:                      Query Broker
         Unified results          SPARQL => SPARQL


                                            Corp       Doc
                                            LDAP       DB

Chungnam National University                                   17
DataBase System Lab.
    Access Multiple Sources
    “Find the name and email addresses of authors of
     a paper”
    Query tech reports first, then go to LDAP for more
    SQL database; LDAP server
       PREFIX dc: <http://purl.org/dc/elements/1.1/>
       PREFIX ldap: <http://ldap.hp.com/people#>
       PREFIX foaf:

       SELECT ?name ?email
         ?doc      dc:title ?title .
         FILTER regex(?title, “SPARQL”) .
         ?doc      dc:creator ?reseacher .
         ?researcher ldap:email      ?email .
         ?researcher ldap:name        ?name
Chungnam National University                           18
DataBase System Lab.
    Access Multiple Sources
    “Find the reports written by the person with email
     address andy.seaborne@hp.com
    Go to LDAP first, then the reports database
         PREFIX dc: <http://purl.org/dc/elements/1.1/>
         PREFIX ldap: <http://ldap.hp.com/people#>
         PREFIX foaf:

         SELECT ?name
           ?doc      dc:title ?title .
           ?doc      dc:creator ?reseacher .
           ?researcher ldap:email <mailto:andy.seaborne@hp.com> .

Chungnam National University                                        19
DataBase System Lab.
    SPARQL as a Protocol
    A way of communication between parties that run
     SPARQL queries
    Defining a way of invoking the service
    Bindings of a transport protocol

Chungnam National University                       20
DataBase System Lab.
    SPARQL Protocol(1)
    WSDL description file:
         Description of the protocol
         Not for human understanding
    HTTP binding:
         Specify how to encode SPARQL queries in URLs with GET
          and POST methods
    SOAP binding:
         Specify the SOAP message format
          (XML message exchange format for queries)

Chungnam National University                                      21
DataBase System Lab.
    SPARQL Protocol(2)
    Interface SparqlQuery
         Only one operation: query
              For transferring string query
         Data types: via XML schema
         Bindings: HTTP / SOAP binding for invokable operations
    A service must support SparqlQuery interface
         Support the bindings as described in the WSDL

Chungnam National University                                       22
DataBase System Lab.
    HTTP Binding Example
    HTTP Binding Get methods
      GET /sparql/?query=EncodedQuery
      HTTP/1.1Host: my.example
      User-agent: sparql-client/0.1

Chungnam National University                     23
DataBase System Lab.
  WSDL Description File Example

  WSDL description file: (HTTP binding part)
  <binding name="queryHttp" interface="tns:SparqlQuery“
   <fault name="MalformedQuery" whttp:zode="400"/>
  <!-- the GET binding for query operation -->
   <operation ref="tns:query" whttp:method="GET"
           whttp:inputSerialization=“…" />

Chungnam National University                              24
DataBase System Lab.
   SOAP Binding Example

HTTP/1.1 200 OK
Date: Wed, 27 Dec 2005 12:48:25 GMT
Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3
Connection: closeContent-Type: application/sparql-results+xml;
<?xml version="1.0"?>
        <sparql xmlns=“…"> … …

 Chungnam National University                                25
 DataBase System Lab.
    Walkthrough Example(1)
    XML File

              <name>Henry Story</name>
                           <name>Tim Bray</name>
                           <name>Jonathan Story</name>

Chungnam National University                             26
DataBase System Lab.
    Walkthrough Example(1)

    [          a       :Person;
               :name "Henry Story";
               :mbox <mailto:hs@insead.edu>;
               :knows [        a :Person;
                               :name "Tim Bray";
                               :mbox <mailto:tb@eg.com       ];
               :knows [        a :Person;
                               :name "Jonathan Story";
                               :mbox <mailto:js@eg.edu> ];

Chungnam National University                                      27
DataBase System Lab.
  Graph Representation

Chungnam National University   28
DataBase System Lab.
    Walkthrough Example(2)
    XML File
                     <name>Jonathan Story</name>
                     <name>Tim Bray</name>

Chungnam National University                              29
DataBase System Lab.
    Walkthrough Example(2)

            [          a :Person;
                       :name "Tim Bray";
                       :mbox <mailto:Tim.Bray@eg.com>
                               :address [
                                       a :Address;
                                       :country "Canada"@en ]
            [          a :Person;
                       :name "Jonathan Story";
                       :mbox <mailto:Jonathan.Story@eg.edu>
                               :address [
                                       a :Address;
                                       :country "France"@en ]

Chungnam National University                                    30
DataBase System Lab.
  Graph Representation

Chungnam National University   31
DataBase System Lab.
  Merge Graph Representation

Chungnam National University   32
DataBase System Lab.
    SPARQL (SPARQL Protocol And RDF Query
     Language) is a query language for getting
     information from RDF graphs
    It provides facilities to:
         Extract information in the form of URIs, bNodes, Plain and
          typed literals
         Extract RDF subgraphs
         Construct new RDF graphs based on information in the
          queried graphs

Chungnam National University                                           33
DataBase System Lab.
    W3C, “SPARQL Query Language for RDF”
     20070326/, 26, March. 2007
    IBM Developerworks, “Search RDF data with
     SPARQL” http://www-
     10, May. 2005
    Oreillynet, “SPARQL: Web 2.0 Meet the Semantic
     _web_20_meet_the_semanti.html, 16, September.
Chungnam National University                         34
DataBase System Lab.
    SPARQL Update
         Future HP proposal to W3C
    { book:newBook dc:title “More about SPARQL” .
      book:newBook dc:creator
        [ foaf:mbox <mailto:alex@example> ;
          foaf:name “Alex Author” ]
    { ?book dc:title ?title ;
          dc:creator ?c }
    { ?book dc:title ?title ;
          dc:creator ?c
      FILTER regex(?title, “first edition”)
Chungnam National University                        35
DataBase System Lab.
   SPARQL: Web 2.0 Meet the Semantic Web
         RDF is pretty foundational to the Semantic Web
         Most Web 2.0 applications and services involve a REST
          protocol or interface
         REST offers a standard set of operations
             GET, PUT, POST, DELETE
         No standard way to execute an arbitrary query
             A Web 2.0 app or service’s dataset
             Get back a representation of that resource

Chungnam National University                                      36
DataBase System Lab.
         SW and Web 2.0 need a data access protocol
              Using WSDL 2.0, SPARQL Protocol for RDF describes a very
               simple web service with one operation, query
              Available with both HTTP and SOAP bindings
                   The way you send SPARQL queries to other sites
                   The way you get back the results
         Imagine having one query language, and one client, which
          lets you arbitrarily slice the data of Web 2.0 sites, all FOAF
          files, all of the RSS 1.0 feeds
         A good SPARQL client implementation in Javascript, along
          with some conventions for building and moving queries
          around in an AJAX-friendly way
              SPARQL over AJAX just by itself is so cool it gives me a

Chungnam National University                                               37
DataBase System Lab.

To top