W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > July to September 2007

optional/manifest#dawg-optional-complex-4

From: Lee Feigenbaum <lee@thefigtrees.net>
Date: Fri, 17 Aug 2007 01:52:49 -0400
Message-ID: <46C537B1.6040103@thefigtrees.net>
To: 'RDF Data Access Working Group' <public-rdf-dawg@w3.org>

We ran out of time in the telecon to examine this test in detail to 
determine why we are not passing it, so I promised this email.

default graph (complex-data-2.ttl)

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix foaf:       <http://xmlns.com/foaf/0.1/> .
@prefix ex:        <http://example.org/things#> .
@prefix xsd:        <http://www.w3.org/2001/XMLSchema#> .

_:a rdf:type foaf:Person ;
     foaf:name "Eve" ;
     ex:empId "9"^^xsd:integer .

_:b rdf:type foaf:Person ;
     foaf:name "Alice" ;
     ex:empId "29"^^xsd:integer ;
     ex:healthplan ex:HealthPlanD.

_:c rdf:type foaf:Person ;
     foaf:name "Fred" ;
     ex:empId "27"^^xsd:integer .

_:e foaf:name "Bob" ;
     ex:empId "23"^^xsd:integer ;
     ex:healthplan ex:HealthPlanC.

_:f foaf:name "Bob" ;
     ex:empId "30"^^xsd:integer;
     ex:healthplan ex:HealthPlanB.

_:g rdf:type foaf:Person;
     ex:ssn "000000000";
     foaf:name   "Bert";
     ex:department "DeptA" ;
     ex:healthplan ex:HealthPlanA.

named graph (complex-data-1.ttl)

@prefix foaf:       <http://xmlns.com/foaf/0.1/> .

<tag:alice@example:foafUri>
     foaf:mbox   <mailto:alice@example.net>;
     foaf:name   "Alice";
     foaf:nick   "WhoMe?";
     foaf:depiction   <http://example.com/alice.png> .

<tag:bert@example:foafUri>
     foaf:mbox   <mailto:bert@example.net> ;
     foaf:nick   "BigB" ;
     foaf:name   "Bert" .

<tag:eve@example:foafUri>
     foaf:mbox   <mailto:eve@example.net> ;
     foaf:firstName   "Eve" .

<tag:john@example:foafUri>
     foaf:mbox   <mailto:john@example.net> ;
     foaf:nick   "jDoe";
     foaf:isPrimaryTopicOf <http://example.com/people/johnDoe>

query:

PREFIX  foaf:   <http://xmlns.com/foaf/0.1/>
PREFIX    ex:   <http://example.org/things#>
SELECT ?name ?plan ?dept ?img
WHERE
{
     ?person foaf:name ?name
     { ?person ex:healthplan ?plan } UNION { ?person ex:department ?dept}
     OPTIONAL {
         ?person a foaf:Person
         GRAPH ?g {
             [] foaf:name ?name;
                foaf:depiction ?img
         }
   }
}

analysis:

Let's do the UNION first. The result of the UNION is pairs of persons 
and plans and of persons and depts (one solution per line):

?person=_:b, ?plan=ex:HealthPlanD, ?dept=unbound
?person=_:e, ?plan=ex:HealthPlanC, ?dept=unbound
?person=_:f, ?plan=ex:HealthPlanB, ?dept=unbound
?person=_:g, ?plan=ex:HealthPlanA, ?dept=unbound
?person=_:g, ?plan=unbound, ?dept="DeptA"

This gets conjoined with ?person foaf:name ?name, which simply adds a 
name to each row:

?person=_:b,?plan=ex:HealthPlanD,?dept=unbound,?name="Alice"
?person=_:e,?plan=ex:HealthPlanC,?dept=unbound,?name="Bob"
?person=_:f,?plan=ex:HealthPlanB,?dept=unbound,?name="Bob"
?person=_:g,?plan=ex:HealthPlanA,?dept=unbound,?name="Bert"
?person=_:g,?plan=unbound,?dept="DeptA",?name="Bert"

Now, the RHS of the optional. The two parts of the RHS share no 
variables in common, so we can take their cross product. The lone triple 
pattern has solutions:

?person=_:a
?person=_:b
?person=_:c
?person=_:g

And the GRAPH clause has solution:

?g=<complex-data-1.ttl>,?name="Alice",?img=<http://example.com/alice.png>

for a (simple) cross product of:

?person=_:a,?g=<complex-data-1.ttl>,?name="Alice",?img=<http://example.com/alice.png>
?person=_:b,?g=<complex-data-1.ttl>,?name="Alice",?img=<http://example.com/alice.png>
?person=_:c,?g=<complex-data-1.ttl>,?name="Alice",?img=<http://example.com/alice.png>
?person=_:g,?g=<complex-data-1.ttl>,?name="Alice",?img=<http://example.com/alice.png>

Now, we need to extend those solutions from above (the LHS) that are 
compatible with these from the RHS. The solutions with ?person=_:e and 
?person=_:f are both incompatible with all of these, so remain 
unchanged. The two _:g rows from the LHS are also unchanged since the 
name is a mismatch. Only the _:b row gets extended.

?person=_:b,?plan=ex:HealthPlanD,?dept=unbound,?name="Alice",?g=<complex-data-1.ttl>,?img=<http://example.com/alice.png>
?person=_:e,?plan=ex:HealthPlanC,?dept=unbound,?name="Bob"
?person=_:f,?plan=ex:HealthPlanB,?dept=unbound,?name="Bob"
?person=_:g,?plan=ex:HealthPlanA,?dept=unbound,?name="Bert"
?person=_:g,?plan=unbound,?dept="DeptA",?name="Bert"


...which we then project out to:

?plan=ex:HealthPlanD,?dept=unbound,?name="Alice",?img=<http://example.com/alice.png>
?plan=ex:HealthPlanC,?dept=unbound,?name="Bob"
?plan=ex:HealthPlanB,?dept=unbound,?name="Bob"
?plan=ex:HealthPlanA,?dept=unbound,?name="Bert"
?plan=unbound,?dept="DeptA",?name="Bert"

Three of these solutions match what's already there, but the other two 
don't. The 4th solution as Chimezie wrote it down involves "Bert" and 
both a health plan and a department which doesn't make sense to me since 
only one or the other can be bound by the UNION in a single query.

Now, Eric's alternative answer to this is:

<<<
algae fails:
   - "Bert"|"DeptA"|<http://example.org/things#HealthPlanA>|NULL
   + "Bert"|NULL|<http://example.org/things#HealthPlanA>|NULL
   + "Bert"|"DeptA"|NULL|NULL
 >>>

Which matches exactly. Checking in ARQ also matches this. (Though 
Glitter seems to have a bug. :-) )

Based on this analysis and implementation evidence, I'm checking in an 
updated version of the results. Please let me know what you think; we'll 
look at approving Chimezie's tests on Tuesday, along with others that 
remain. (A full recap to be posted to the list before Tuesday, of course.)

Lee
Received on Friday, 17 August 2007 05:52:59 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:37 GMT