SPARQL Query Language for RDF Cluj Semantic WEB meetup http://www.meetup.com/Cluj-Semantic-WEB/ presented by  Dia MIRON 17 May 2011
Introduction - SPARQL SPARQL is a query language/engine for RDF graphs.  An RDF graph is a set of triples.  A flexible and extensible way to represent information about WWW resources A concept similar to SQL for data bases. A W3C standard query language to fetch data from distributed Semantic Web data models.  Can query a triple store or data on the Web (at a given URL). 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
SPARQL – a first example prefix sch-ont: <http://education.data.gov.uk/def/school/>  SELECT ?name WHERE { ?school a sch-ont:School;  sch-ont:establishmentName ?name;  sch-ont:districtAdministrative <http://statistics.data.gov.uk/id/local-authority-district/00AA> ; }  ORDER BY ?name   If executed on the UK government's  Open Semantic Database , will return the names of all the schools in the UK in administrative district 00AA, and order the results in alphabetical order ( http://data.gov.uk/sparql ) SPARQL Is Similar To SQL Like SQL, SPARQL selects data from the query data set by using a SELECT statement to determine which subset of the selected data is returned. Also, SPARQL uses a WHERE clause to define graph patterns to find a match for in the query data set.
SPARQL General Form ORDER BY, DISTINCT  etc (Modifiers) e.g. ORDER BY ?name WHERE  (Query Triple Pattern) e.g. WHERE { ?planttype plant:planttype ?name } FROM  (Data Set) e.g. FROM <http://www.linkeddatatools.com/plantsdata/plants.rdf> SELECT  (Result Set) e.q. SELECT ?name PREFIX  (Namespace Prefixes) e.g. PREFIX plant:<http://www.linkeddatatools.com/plants>
Data set Example: triple data containing a variety of shrubs and plants, and their family names
Select All Data PREFIX plants: <http://www.linkeddatatools.com/plants> SELECT * WHERE { ?name plants:family ?family } select all the plant URIs (subjects) and plant family names (literal-type objects) from the data above; the wildcard '*' in SPARQL, similar to SQL, will return all the mapped data in the result set; as we have stated two variables ?name and ?family, the query will return both these declared query variables in our result set, according to the subjects, predicates or objects they're mapped to;
And the results are… 01. <?xml version=&quot;1.0&quot; ?> 02.<sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot; 03.        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;> 04.   <head> 05.      <variable name=&quot;name&quot;/> 06.      <variable name=&quot;family&quot;/> 07.   </head> 08.   <results> 09.      <result> 10.         <binding name=&quot;name&quot;> 11.            <uri>http://www.linkeddatatools.com/plants#magnolia</uri> 12.         </binding> 13.         <binding name=&quot;family&quot;> 14.            <literal>Magnoliaceae</literal> 15.         </binding> 16.      </result> 17.      <result> 18.         <binding name=&quot;name&quot;> 19.            <uri>http://www.linkeddatatools.com/plants#african_lilly</uri> 20.         </binding> 21.         <binding name=&quot;family&quot;> 22.            <literal>Liliaceae</literal> 23.         </binding> 24.      </result> 25.      <result> 26.         <binding name=&quot;name&quot;> 27.            <uri>http://www.linkeddatatools.com/plants#silvertop</uri> 28.         </binding> 29.         <binding name=&quot;family&quot;> 30.            <literal>Aralianae</literal> 31.         </binding> 32.      </result> 33.      <result> 34.         <binding name=&quot;name&quot;> 35.            <uri>http://www.linkeddatatools.com/plants#velvetleaf</uri> 36.         </binding> 37.         <binding name=&quot;family&quot;> 38.            <literal>Malvaceae</literal> 39.         </binding> 40.      </result> 41.      <result> 42.         <binding name=&quot;name&quot;> 43.            <uri>http://www.linkeddatatools.com/plants#manglietia</uri> 44.         </binding> 45.         <binding name=&quot;family&quot;> 46.            <literal>Magnoliaceae</literal> 47.         </binding> 48.      </result> 49.   </results> 50.</sparql>
A more specific query 1.PREFIX plants: <http://www.linkeddatatools.com/plants> 2.SELECT * WHERE 3.{ ?name plants:family &quot;Magnoliaceae“ } ----------------------------------------------------------------------------------------------------------------------- <?xml version=&quot;1.0&quot; ?> <sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot;    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;>  <head>  <variable name=&quot;name&quot;/>  </head>  <results>  <result>  <binding name=&quot;name&quot;>     <uri>http://www.linkeddatatools.com/plants#magnolia</uri>  </binding>  </result>  <result>  <binding name=&quot;name&quot;>  <uri>http://www.linkeddatatools.com/plants#manglietia</uri>  </binding>  </result>  </results> </sparql>
What About CREATE, INSERT, UPDATE? at the moment, they are not implemented; organizations publishing data in a queryable, public SPARQL endpoint will probably in most circumstances not just want anyone writing and making changes to their (valuable) data; SPARUL (SPARQL/Update)  and  SPARQL+  are being developed to address this problem, however a solid contender to fill this gap in functionality is yet to arise,
Basic Graph Pattern  - Multiple Matches Group Graph Pattern  (set of graph patterns) also! Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/>  SELECT ?name ?mbox  WHERE  { ?x foaf:name ?name .  ?x foaf:mbox ?mbox }   @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Johnny Lee Outlaw&quot; .  _:a foaf:mbox <mailto:jlow@example.com> .  _:b foaf:name &quot;Peter Goodguy&quot; .  _:b foaf:mbox <mailto:peter@example.org> . <mailto:peter@example.org> &quot;Peter Goodguy&quot; <mailto:jlow@example.com> &quot;Johnny Lee Outlaw&quot; mbox name
Basic Graph Pattern  - Blank Nodes Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?name  WHERE { ?x foaf:name ?name }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; .  _:b foaf:name &quot;Bob&quot; .  “ Bob” _:d “ Alice“ _:c name x
Value Constraints Data Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/>  PREFIX ns: <http://example.org/ns#>  SELECT ?title ?price  WHERE { ?x ns:price ?price .  FILTER ?price < 30 .  ?x dc:title ?title . }  @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> .  :book1 dc:title &quot;SPARQL Tutorial&quot; .  :book1 ns:price 42 .  :book2 dc:title &quot;The Semantic Web&quot; .  :book2 ns:price 23  .  23 &quot;The Semantic Web&quot;  price title
Optional graph patterns Data Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/>  PREFIX ns: <http://example.org/ns#>  SELECT ?title ?price  WHERE { ?x dc:title ?title .  OPTIONAL { ?x ns:price ?price .  FILTER ?price < 30 }} @prefix dc: <http://purl.org/dc/elements/1.1/> .  @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> .  :book1 dc:title &quot;SPARQL Tutorial&quot; .  :book1 ns:price 42 .  :book2 dc:title &quot;The Semantic Web&quot; . :book2 ns:price 23  .  “ SPARQL Tutorial“ 23 &quot;The Semantic Web&quot;  price title
Multiple Optional Blocks Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/>  SELECT ?name ?mbox ?hpage  WHERE { ?x foaf:name ?name .  OPTIONAL { ?x foaf:mbox ?mbox }.  OPTIONAL { ?x foaf:homepage ?hpage } }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:homepage <http://work.example.org/alice/> .  _:b foaf:name &quot;Bob&quot; .  _:b foaf:mbox <mailto:bob@work.example> .  <mailto:bob@example.com>  “ Bob“ <http://work.example.org/alice/>  “ Alice“ hpage Mbox name
Alternative Graph Patterns Data Query Query Result PREFIX dc10: <http://purl.org/dc/elements/1.0/>  PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?x ?y  WHERE { { ?book dc10:title ?x } UNION { ?book dc11:title ?y } }  @prefix dc10: <http://purl.org/dc/elements/1.0/> . @prefix dc11: <http://purl.org/dc/elements/1.1/> .  _:a dc10:title &quot;SPARQL Query Language Tutorial&quot; .  _:b dc11:title &quot;SPARQL Protocol Tutorial&quot; .  _:c dc10:title &quot;SPARQL&quot; .  _:c dc11:title &quot;SPARQL (updated)&quot; .  y x &quot;SPARQL (updated)&quot;  &quot;SPARQL Query Language Tutorial&quot;  &quot;SPARQL&quot;  &quot;SPARQL Protocol Tutorial&quot;
RDF Dataset RDF data stores may hold multiple RDF graphs: record information about each graph queries that involve information from more than one graph  RDF Dataset  in SPARQL terminology the background graph, which does not have a name, and zero or more named graphs, identified by URI reference  the relationship between named and background graphs: (i) to have information in the background graph that includes provenance information about the named graphs (the application is not directly trusting the information in the named graphs ) (ii) to include the information in the named graphs in the background graph as well.
RDF Dataset- T he Relationship between Named and Background Graphs (I) #  Background graph   @prefix dc: <http://purl.org/dc/elements/1.1/> .  <http://example.org/bob> dc:publisher &quot;Bob&quot; .  <http://example.org/alice> dc:publisher &quot;Alice&quot; .  #  Graph: http://example.org/bob   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Bob&quot; .  _:a foaf:mbox <mailto:bob@oldcorp.example.org> . #  Graph: http://example.org/alice   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:mbox <mailto:alice@work.example.org>  .
RDF Dataset- T he Relationship between Named and Background Graphs (II) #  Background graph   @prefix foaf: <http://xmlns.com/foaf/0.1/>   .  _:x foaf:name &quot;Bob&quot; .  _:x foaf:mbox <mailto:bob@oldcorp.example.org> . _:y foaf:name &quot;Alice&quot; .  _:y foaf:mbox <mailto:alice@work.example.org> .  #  Graph: http://example.org/bob   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Bob&quot; .  _:a foaf:mbox <mailto:bob@oldcorp.example.org> . #  Graph: http://example.org/alice   @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:mbox <mailto:alice@work.example.org>  .
Querying the Dataset # Graph: http://example.org/foaf/aliceFoaf  @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:mbox <mailto:alice@work.example> .  _:a foaf:knows _:b .  _:b rdfs:seeAlso <http://example.org/foaf/bobFoaf> .  <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .  _:b foaf:name &quot;Bob&quot; .  _:b foaf:mbox <mailto:bob@work.example> .  _:b foaf:age 32 .  # Graph: http://example.org/foaf/bobFoaf  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:1 foaf:mbox <mailto:bob@work.example> . _:1 rdfs:seeAlso <http://example.org/foaf/bobFoaf> .  _:1 foaf:age 35 .  <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .
Querying the Dataset  - Accessing Graph Labels PREFIX foaf: <http://xmlns.com/foaf/0.1/>  SELECT ?src ?bobAge  WHERE { GRAPH ?src  { ?x foaf:mbox <mailto:bob@work.example> .  ?x foaf:age ?bobAge } } 35  <http://example.org/foaf/bobFoaf>  32  <http://example.org/foaf/aliceFoaf>  bobAge src
Querying the Dataset  -  Restricting by Graph Label  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  }  } 35 age
Querying the Dataset  -  Restricting via Query Pattern  PREFIX data: <http://example.org/foaf/>  PREFIX foaf: <http://xmlns.com/foaf/0.1/>  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  SELECT ?mbox ?age ?ppd  WHERE  { GRAPH data:aliceFoaf  { ?alice foaf:mbox <mailto:alice@work.example> ; foaf:knows ?whom .  ?whom foaf:mbox ?mbox ;  rdfs:seeAlso ?ppd .  ?ppd a foaf:PersonalProfileDocument . } .  GRAPH ?ppd { ?w foaf:mbox ?mbox ;  foaf:age ?age } }  <http://example.org/foaf/bobFoaf>  35  <mailto:bob@work.example>  ppd age mbox
Query Execution and Ordering  Optional-1 : an  optional pattern that has a common variable with a(more) basic graph pattern(s) must be executed  after the basic graph pattern(s) Optional-2 :  there can't be two optionals with a common variable, if that variable does not occur in a basic graph pattern as well  Constraint : constraints are evaluated after variables are assigned values
Query forms:   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.
CONSTRUCT Examples(I) PREFIX foaf: <http://xmlns.com/foaf/0.1/>  PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>  CONSTRUCT { <http://example.org/person#Alice> vcard:FN ?name }  WHERE { ?x foaf:name ?name }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@example.org> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>. <http://example.org/person#Alice> vcard:FN &quot;Alice&quot; . #extracting a whole graph from the target RDF dataset CONSTRUCT { ?s ?p ?o }  WHERE { GRAPH <http://example.org/myGraph> { ?s ?p ?o } . }
CONSTRUCT Examples(II) accesing a graph conditional on other information contained in the metadata about named graphs in the dataset PREFIX dc: <http://purl.org/dc/elements/1.1/>  PREFIX app: <http://example.org/ns#>  CONSTRUCT { ?s ?p ?o }  WHERE { GRAPH ?g { ?s ?p ?o } .  { ?g dc:publisher <http://www.w3.org/> } .  { ?g dc:date ?date } .  FILTER app:myDate(?date) > &quot;2005-02-8T00:00:00Z&quot;^^xsd:dateTime.  }
DESCRIBE PREFIX ent: <http://myorg.example/employees#> DESCRIBE ?x WHERE { ?x ent:employeeId &quot;1234&quot; }  @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> .  @prefix myOrg: <http://myorg.example/employees#> . _:a myOrg:employeeId &quot;1234&quot; ;  foaf:mbox_sha1sum &quot;ABCD1234&quot; ;  vcard:N [ vcard:Family &quot;Smith&quot; ;  vcard:Given &quot;John&quot; ] .  foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty .
ASK @prefix foaf: <http://xmlns.com/foaf/0.1/> .  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .  _:a foaf:name &quot;Alice&quot; .  _:a foaf:homepage <http://work.example.org/alice/> .  _:b foaf:name &quot;Bob&quot; .  _:b foaf:mbox <mailto:bob@work.example> . PREFIX foaf: <http://xmlns.com/foaf/0.1/>  ASK { ?x foaf:name &quot;Alice&quot; } .
Testing Values Named functions and syntactically constructed operations:  operands: subset of XML Schema DataTypes {xsd:string, xsd:decimal, xsd:double, xsd:dateTime} and types derived from xsd:decimal.  Subset of XPath functions and operators Operands:  xs:string, xs:double, xs:float, xs:decimal, xs:integer,  xs:dateTime  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.
Support for SPARQL SPARQL and Jena module called ARQ that implements SPARQL; also parses queries expressed in RDQL or its own internal language. not yet part of the standard Jena distribution; availbale from either Jena‘s CVS repository or as a self-contained download Twinkle  simple Java interface that wraps the ARQ SPARQL Processor library (the add-on to Jena).  Redland set of free software packages that provide support for RDF, including querying with RDQL and SPARQL using the Rasqal RDF Query Library. .
Contact Romania Dia Miron – Recognos Romania Email:  [email_address] www.recognos.ro USA George Roth – Recognos USA Email:  [email_address] www.recognos.com

From SQL to SPARQL

  • 1.
    SPARQL Query Languagefor RDF Cluj Semantic WEB meetup http://www.meetup.com/Cluj-Semantic-WEB/ presented by Dia MIRON 17 May 2011
  • 2.
    Introduction - SPARQLSPARQL is a query language/engine for RDF graphs. An RDF graph is a set of triples. A flexible and extensible way to represent information about WWW resources A concept similar to SQL for data bases. A W3C standard query language to fetch data from distributed Semantic Web data models. Can query a triple store or data on the Web (at a given URL). 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
  • 3.
    SPARQL – afirst example prefix sch-ont: <http://education.data.gov.uk/def/school/> SELECT ?name WHERE { ?school a sch-ont:School; sch-ont:establishmentName ?name; sch-ont:districtAdministrative <http://statistics.data.gov.uk/id/local-authority-district/00AA> ; } ORDER BY ?name If executed on the UK government's Open Semantic Database , will return the names of all the schools in the UK in administrative district 00AA, and order the results in alphabetical order ( http://data.gov.uk/sparql ) SPARQL Is Similar To SQL Like SQL, SPARQL selects data from the query data set by using a SELECT statement to determine which subset of the selected data is returned. Also, SPARQL uses a WHERE clause to define graph patterns to find a match for in the query data set.
  • 4.
    SPARQL General FormORDER BY, DISTINCT etc (Modifiers) e.g. ORDER BY ?name WHERE (Query Triple Pattern) e.g. WHERE { ?planttype plant:planttype ?name } FROM (Data Set) e.g. FROM <http://www.linkeddatatools.com/plantsdata/plants.rdf> SELECT (Result Set) e.q. SELECT ?name PREFIX (Namespace Prefixes) e.g. PREFIX plant:<http://www.linkeddatatools.com/plants>
  • 5.
    Data set Example:triple data containing a variety of shrubs and plants, and their family names
  • 6.
    Select All DataPREFIX plants: <http://www.linkeddatatools.com/plants> SELECT * WHERE { ?name plants:family ?family } select all the plant URIs (subjects) and plant family names (literal-type objects) from the data above; the wildcard '*' in SPARQL, similar to SQL, will return all the mapped data in the result set; as we have stated two variables ?name and ?family, the query will return both these declared query variables in our result set, according to the subjects, predicates or objects they're mapped to;
  • 7.
    And the resultsare… 01. <?xml version=&quot;1.0&quot; ?> 02.<sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot; 03.        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;> 04.   <head> 05.      <variable name=&quot;name&quot;/> 06.      <variable name=&quot;family&quot;/> 07.   </head> 08.   <results> 09.      <result> 10.         <binding name=&quot;name&quot;> 11.            <uri>http://www.linkeddatatools.com/plants#magnolia</uri> 12.         </binding> 13.         <binding name=&quot;family&quot;> 14.            <literal>Magnoliaceae</literal> 15.         </binding> 16.      </result> 17.      <result> 18.         <binding name=&quot;name&quot;> 19.            <uri>http://www.linkeddatatools.com/plants#african_lilly</uri> 20.         </binding> 21.         <binding name=&quot;family&quot;> 22.            <literal>Liliaceae</literal> 23.         </binding> 24.      </result> 25.      <result> 26.         <binding name=&quot;name&quot;> 27.            <uri>http://www.linkeddatatools.com/plants#silvertop</uri> 28.         </binding> 29.         <binding name=&quot;family&quot;> 30.            <literal>Aralianae</literal> 31.         </binding> 32.      </result> 33.      <result> 34.         <binding name=&quot;name&quot;> 35.            <uri>http://www.linkeddatatools.com/plants#velvetleaf</uri> 36.         </binding> 37.         <binding name=&quot;family&quot;> 38.            <literal>Malvaceae</literal> 39.         </binding> 40.      </result> 41.      <result> 42.         <binding name=&quot;name&quot;> 43.            <uri>http://www.linkeddatatools.com/plants#manglietia</uri> 44.         </binding> 45.         <binding name=&quot;family&quot;> 46.            <literal>Magnoliaceae</literal> 47.         </binding> 48.      </result> 49.   </results> 50.</sparql>
  • 8.
    A more specificquery 1.PREFIX plants: <http://www.linkeddatatools.com/plants> 2.SELECT * WHERE 3.{ ?name plants:family &quot;Magnoliaceae“ } ----------------------------------------------------------------------------------------------------------------------- <?xml version=&quot;1.0&quot; ?> <sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;> <head> <variable name=&quot;name&quot;/> </head> <results> <result> <binding name=&quot;name&quot;> <uri>http://www.linkeddatatools.com/plants#magnolia</uri> </binding> </result> <result> <binding name=&quot;name&quot;> <uri>http://www.linkeddatatools.com/plants#manglietia</uri> </binding> </result> </results> </sparql>
  • 9.
    What About CREATE,INSERT, UPDATE? at the moment, they are not implemented; organizations publishing data in a queryable, public SPARQL endpoint will probably in most circumstances not just want anyone writing and making changes to their (valuable) data; SPARUL (SPARQL/Update) and SPARQL+ are being developed to address this problem, however a solid contender to fill this gap in functionality is yet to arise,
  • 10.
    Basic Graph Pattern - Multiple Matches Group Graph Pattern (set of graph patterns) also! Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox } @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Johnny Lee Outlaw&quot; . _:a foaf:mbox <mailto:jlow@example.com> . _:b foaf:name &quot;Peter Goodguy&quot; . _:b foaf:mbox <mailto:peter@example.org> . <mailto:peter@example.org> &quot;Peter Goodguy&quot; <mailto:jlow@example.com> &quot;Johnny Lee Outlaw&quot; mbox name
  • 11.
    Basic Graph Pattern - Blank Nodes Data Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x ?name WHERE { ?x foaf:name ?name } @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:b foaf:name &quot;Bob&quot; . “ Bob” _:d “ Alice“ _:c name x
  • 12.
    Value Constraints DataQuery Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#> SELECT ?title ?price WHERE { ?x ns:price ?price . FILTER ?price < 30 . ?x dc:title ?title . } @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> . :book1 dc:title &quot;SPARQL Tutorial&quot; . :book1 ns:price 42 . :book2 dc:title &quot;The Semantic Web&quot; . :book2 ns:price 23 . 23 &quot;The Semantic Web&quot; price title
  • 13.
    Optional graph patternsData Query Query Result PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#> SELECT ?title ?price WHERE { ?x dc:title ?title . OPTIONAL { ?x ns:price ?price . FILTER ?price < 30 }} @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix : <http://example.org/book/> . @prefix ns: <http://example.org/ns#> . :book1 dc:title &quot;SPARQL Tutorial&quot; . :book1 ns:price 42 . :book2 dc:title &quot;The Semantic Web&quot; . :book2 ns:price 23 . “ SPARQL Tutorial“ 23 &quot;The Semantic Web&quot; price title
  • 14.
    Multiple Optional BlocksData Query Query Result PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox ?hpage WHERE { ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox }. OPTIONAL { ?x foaf:homepage ?hpage } } @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:a foaf:name &quot;Alice&quot; . _:a foaf:homepage <http://work.example.org/alice/> . _:b foaf:name &quot;Bob&quot; . _:b foaf:mbox <mailto:bob@work.example> . <mailto:bob@example.com> “ Bob“ <http://work.example.org/alice/> “ Alice“ hpage Mbox name
  • 15.
    Alternative Graph PatternsData Query Query Result PREFIX dc10: <http://purl.org/dc/elements/1.0/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?x ?y WHERE { { ?book dc10:title ?x } UNION { ?book dc11:title ?y } } @prefix dc10: <http://purl.org/dc/elements/1.0/> . @prefix dc11: <http://purl.org/dc/elements/1.1/> . _:a dc10:title &quot;SPARQL Query Language Tutorial&quot; . _:b dc11:title &quot;SPARQL Protocol Tutorial&quot; . _:c dc10:title &quot;SPARQL&quot; . _:c dc11:title &quot;SPARQL (updated)&quot; . y x &quot;SPARQL (updated)&quot; &quot;SPARQL Query Language Tutorial&quot; &quot;SPARQL&quot; &quot;SPARQL Protocol Tutorial&quot;
  • 16.
    RDF Dataset RDFdata stores may hold multiple RDF graphs: record information about each graph queries that involve information from more than one graph RDF Dataset in SPARQL terminology the background graph, which does not have a name, and zero or more named graphs, identified by URI reference the relationship between named and background graphs: (i) to have information in the background graph that includes provenance information about the named graphs (the application is not directly trusting the information in the named graphs ) (ii) to include the information in the named graphs in the background graph as well.
  • 17.
    RDF Dataset- The Relationship between Named and Background Graphs (I) # Background graph @prefix dc: <http://purl.org/dc/elements/1.1/> . <http://example.org/bob> dc:publisher &quot;Bob&quot; . <http://example.org/alice> dc:publisher &quot;Alice&quot; . # Graph: http://example.org/bob @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Bob&quot; . _:a foaf:mbox <mailto:bob@oldcorp.example.org> . # Graph: http://example.org/alice @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@work.example.org> .
  • 18.
    RDF Dataset- The Relationship between Named and Background Graphs (II) # Background graph @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:x foaf:name &quot;Bob&quot; . _:x foaf:mbox <mailto:bob@oldcorp.example.org> . _:y foaf:name &quot;Alice&quot; . _:y foaf:mbox <mailto:alice@work.example.org> . # Graph: http://example.org/bob @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Bob&quot; . _:a foaf:mbox <mailto:bob@oldcorp.example.org> . # Graph: http://example.org/alice @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@work.example.org> .
  • 19.
    Querying the Dataset# Graph: http://example.org/foaf/aliceFoaf @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@work.example> . _:a foaf:knows _:b . _:b rdfs:seeAlso <http://example.org/foaf/bobFoaf> . <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument . _:b foaf:name &quot;Bob&quot; . _:b foaf:mbox <mailto:bob@work.example> . _:b foaf:age 32 . # Graph: http://example.org/foaf/bobFoaf @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:1 foaf:mbox <mailto:bob@work.example> . _:1 rdfs:seeAlso <http://example.org/foaf/bobFoaf> . _:1 foaf:age 35 . <http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .
  • 20.
    Querying the Dataset - Accessing Graph Labels PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?src ?bobAge WHERE { GRAPH ?src { ?x foaf:mbox <mailto:bob@work.example> . ?x foaf:age ?bobAge } } 35 <http://example.org/foaf/bobFoaf> 32 <http://example.org/foaf/aliceFoaf> bobAge src
  • 21.
    Querying the Dataset - Restricting by Graph Label 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 } } 35 age
  • 22.
    Querying the Dataset - Restricting via Query Pattern PREFIX data: <http://example.org/foaf/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?mbox ?age ?ppd WHERE { GRAPH data:aliceFoaf { ?alice foaf:mbox <mailto:alice@work.example> ; foaf:knows ?whom . ?whom foaf:mbox ?mbox ; rdfs:seeAlso ?ppd . ?ppd a foaf:PersonalProfileDocument . } . GRAPH ?ppd { ?w foaf:mbox ?mbox ; foaf:age ?age } } <http://example.org/foaf/bobFoaf> 35 <mailto:bob@work.example> ppd age mbox
  • 23.
    Query Execution andOrdering Optional-1 : an optional pattern that has a common variable with a(more) basic graph pattern(s) must be executed after the basic graph pattern(s) Optional-2 : there can't be two optionals with a common variable, if that variable does not occur in a basic graph pattern as well Constraint : constraints are evaluated after variables are assigned values
  • 24.
    Query forms: 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.
  • 25.
    CONSTRUCT Examples(I) PREFIXfoaf: <http://xmlns.com/foaf/0.1/> PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> CONSTRUCT { <http://example.org/person#Alice> vcard:FN ?name } WHERE { ?x foaf:name ?name } @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name &quot;Alice&quot; . _:a foaf:mbox <mailto:alice@example.org> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>. <http://example.org/person#Alice> vcard:FN &quot;Alice&quot; . #extracting a whole graph from the target RDF dataset CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/myGraph> { ?s ?p ?o } . }
  • 26.
    CONSTRUCT Examples(II) accesinga graph conditional on other information contained in the metadata about named graphs in the dataset PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX app: <http://example.org/ns#> CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o } . { ?g dc:publisher <http://www.w3.org/> } . { ?g dc:date ?date } . FILTER app:myDate(?date) > &quot;2005-02-8T00:00:00Z&quot;^^xsd:dateTime. }
  • 27.
    DESCRIBE PREFIX ent:<http://myorg.example/employees#> DESCRIBE ?x WHERE { ?x ent:employeeId &quot;1234&quot; } @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> . @prefix myOrg: <http://myorg.example/employees#> . _:a myOrg:employeeId &quot;1234&quot; ; foaf:mbox_sha1sum &quot;ABCD1234&quot; ; vcard:N [ vcard:Family &quot;Smith&quot; ; vcard:Given &quot;John&quot; ] . foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty .
  • 28.
    ASK @prefix foaf:<http://xmlns.com/foaf/0.1/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . _:a foaf:name &quot;Alice&quot; . _:a foaf:homepage <http://work.example.org/alice/> . _:b foaf:name &quot;Bob&quot; . _:b foaf:mbox <mailto:bob@work.example> . PREFIX foaf: <http://xmlns.com/foaf/0.1/> ASK { ?x foaf:name &quot;Alice&quot; } .
  • 29.
    Testing Values Namedfunctions and syntactically constructed operations: operands: subset of XML Schema DataTypes {xsd:string, xsd:decimal, xsd:double, xsd:dateTime} and types derived from xsd:decimal. Subset of XPath functions and operators Operands: xs:string, xs:double, xs:float, xs:decimal, xs:integer, xs:dateTime 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.
  • 30.
    Support for SPARQLSPARQL and Jena module called ARQ that implements SPARQL; also parses queries expressed in RDQL or its own internal language. not yet part of the standard Jena distribution; availbale from either Jena‘s CVS repository or as a self-contained download Twinkle simple Java interface that wraps the ARQ SPARQL Processor library (the add-on to Jena). Redland set of free software packages that provide support for RDF, including querying with RDQL and SPARQL using the Rasqal RDF Query Library. .
  • 31.
    Contact Romania DiaMiron – Recognos Romania Email: [email_address] www.recognos.ro USA George Roth – Recognos USA Email: [email_address] www.recognos.com