SPARQLing Queries

Bijan Parsia

The University of Manchester

The (HTML) Web

Querying the (HTML) Web

The (XML) Web

Querying the (XML) Web

The Semantic Web

Querying the Semantic Web

SPARQL

Desiderata (1)

  1. Semantically well-specified
    1. Related to the queried formalism
    2. Clear and unambiguous
    3. Complete (cover all corner cases)
    4. Closed (thus freely compositional)
    5. Sensible metalogical properties
  2. Usable
    1. Syntax and constructs should be usable
    2. Sufficient expressivity for applications
    3. Results should not mislead
  3. Implementable
    1. Preferably without too much change to existing systems and techniques

Desiderata (2)

  1. Modular semantics
    1. Core
      • There are (at least) 6 semantics for RDF graphs:
        • Simple/RDF/RDFS + datatype variants
        • OWL Lite/DL/Full
      • With non-obvious relationships
    2. Algebra
      • Manipulation of tables
      • Should be (largely) independent of core
    3. Tension with closure
  2. Predicable answers
  3. Various syntaxes
    1. Directly human usable; familiar to SQL users
    2. XML syntax (for interchange and Web services)

RDF Syntax (Turtle)

Example Turtle

  @prefix rdf:
    <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
  @prefix xsd:
    <http://www.w3.org/2001/XMLSchema#>.
  @prefix : <http://www.ex.org/>.

  :mary rdf:type <http://www.ex.org/Gardener>.
  :mary :worksFor :ElJardinHaus.
  :mary :idNumber "12345"^^xsd:integer.
  :mary :name "Dalileh Jones"@en.
  _:john :worksFor :ElJardinHas.
  _:john :idNumber "54321"^^xsd:integer.

RDF Semantics

Simple Interpretations

RDF(D) Interpretations

What is a Query?

RDF Graphs as Queries

Graph Patterns

Graph Patterns

BGPs and Tables

Variables and Bindings

Considerations


(Non-)Distinguished example

SELECT ?lover
WHERE { ?lover :loves ?beloved}
?lover
:sally
WHERE { ?lover :loves _:beloved}
?lover
:bob
:sally

Semi-distinguished example

SELECT ?lover ?beloved
WHERE { ?lover :loves ?beloved}
?lover ?beloved
:bob _:G1
_:G1 :bob
_:G2 :sally
:sally :sheevah

Oedipus Example

SELECT ?x FROM <http://www.mindswap.org/ontologies/oedipus>
WHERE { ?x ns:hasChild
          [ rdf:type ns:Patricide;
            ns:hasChild ?y].
            ?y rdf:type ns:NotPatricide.}
NO RESULTS
WHERE { ?x ns:hasChild
          [ rdf:type ns:Patricide;
            ns:hasChild
              [ rdf:type ns:NotPatricide]]}
x
:IOKASTE
(This relies on a set of OWL DL axioms in the background.)
(Example from the Description Logic Handbook, chapter 2.)

Oedipus in Detail

Diagram explaining OWL file: http://www.mindswap.org/ontologies/oedipus Case 1: Assuming Polyneikes is a parricide, then Thersandros is a non-parricidal grandchild of IokasteCase 2: Polyneikes is a nonparricidal grandchild of Iokaste (via the parricidal Oedipus)

Reasoning by cases

Thoughts and Implications

Scoping

Table Scoped

Table Scoped

Data BGPs Tables Results
_:x p a.
_:x q a.
_:x p _:y.
_:y q b.
{?sub p ?obj}
?sub ?obj
_:g1/_:x a
_:g1/_:x _:g2/_:y
?sub ?obj
_:f1/_:x a
_:f1/_:x _:f2/_:y
_:f3/_:x a
_:f4/_:y b
{?sub q ?obj}
?sub ?obj
_:g3/_:x a
_:g4/_:y b

No co-reference between _:f2 and _:f4
    i.e., we don't know from the answer set that something (_:x) is related to something (_:y) that is related to b.
    i.e., essentially we split the data into two graphs: the p-related and the q-related.

Query Scoped


Query Scoped

Data BGPs Tables Results
_:x p a.
_:x q a.
_:x p _:y.
_:y q b.
{?sub p ?obj}
?sub ?obj
_:x a
_:x _:y
?sub ?obj
_:x a
_:x _:y
_:x a
_:y b
{?sub q ?obj}
?sub ?obj
_:x a
_:y b
The second row is distinguishable from the first and third by the co-reference.

Answer Redundancy

The Default Case (core)

Equating Answers

Source Leanness

Lean graph Query
(with proj)
Normal Result Source Lean
:bijan :loves :mochi.
:bijan :eats :mochi.
_:aFool :hates :mochi.
_:aFool :wants :mochi.
SELECT ?x ?y
    {?x ?p ?y}
?x ?y
:bijan :mochi
:bijan :mochi
_:aFool :mochi
_:aFool :mochi
?x ?y
:bijan :mochi
_:aFool :mochi

Pairwise Subsumption

Non-lean graph Query
(with projection)
Normal Result Source Lean
:bijan :loves :mochi.
_:aFool :loves :mochi.
_:aFool :wants :mochi.
SELECT ?x ?y
    {?x ?p ?y}
?x ?y
:bijan :mochi
_:aFool :mochi
_:aFool :mochi
?x ?y
:bijan :mochi

Answer Set Leanness

Non-lean graph Query
(with projection)
Normal Result Source Lean
:bijan :loves :mochi.
:bijan :loves _:stuff
_:aFool :loves _:x.
_:x :wants :mochi.
SELECT ?x ?y
    {?x ?p ?y}
?x ?y
:bijan :mochi
:bijan _:stuff
_:aFool _:x
_:x :mochi
?x ?y
:bijan :mochi
_:aFool _:x
_:x :mochi

Relation to DISTINCT

What do the Answers Mean?

A Bit about Value Testing

Other bits

Thoughts

Links