Tuesday, May 02, 2006

Order Dependent SPARQL

Here is an example of what I consider something that can be improved in SPARQL. Using something like FOAF, you have one person that has a nick name and another that has 2 nick names and an email address.

Performing the following query:

SELECT ?name ?alias
WHERE { ?x foaf:name ?name .
OPTIONAL { ?x foaf:nick ?alias }
OPTIONAL { ?x foaf:mbox ?alias }
}

It returns 3 results - Person 1's nick name and Person 2's two nick names.

However if you did this:

SELECT ?name ?alias
WHERE { ?x foaf:name ?name .
OPTIONAL { ?x foaf:mbox ?alias }
OPTIONAL { ?x foaf:nick ?alias }
}

You get a different result - 2 results. Person 1's nick name and Person 2's email address.

Now if you use an operation that is both associative and commutative (like minimum union or disjunction even) you always get 4 results (Person 1's nick name, Person 2's 2 nick names and email address).

This is just a practical example derived from, "A relational algebra for SPARQL".

For those concerned about commercial implementations, it's true that there's no available implementation of minimum union. But it is expressable in SQL (see section 6.7).

No comments: