RE: bc inferencing on optional query patterns

-------- Original Message --------
> From: Steve Harris <>
> Date: 19 August 2004 09:22
> 
> Hi Phil,
> 
> On Thu, Aug 19, 2004 at 07:45:56 +0100, phil@phildawes.net wrote:
> > E.g. take the following query, which gets all http://example.com/foo's
> > props and objects, and if the object is a resource also gets an
> > rdfs:label for it: 
> > 
> > select ?obj, objlabel
> > where    (<http://example.com/foo> ?prop ?obj)
> > OPTIONAL (?obj rdfs:label ?objlabel)
> > 
> > I want to do subproperty inferencing on the optional pattern to return
> > e.g. foaf:name labels (foaf:name is a subproperty of rdfs:label).
> > As in the 3store paper[1], I am using the idiom:
> > 
> > ?subj ?prop ?obj
> > ->
> > ?subj ?tmp ?obj
> > ?tmp SUBPROPERTYOF ?prop
> > 
> > 
> > But that yields:
> > 
> > select ?obj, ?objlabel
> > where    (<http://example.com/foo> ?prop ?obj)
> > OPTIONAL (?obj ?tmp ?objlabel)
> > OPTIONAL (?tmp rdfs:subPropertyOf rdfs:label)
> 
> I think it actually becomes:
> 
> select ?obj, ?objlabel
> where    (<http://example.com/foo> ?prop ?obj)
> OPTIONAL (?obj ?tmp ?objlabel)
>          (?tmp rdfs:subPropertyOf rdfs:label)
> 
> an optional subgraph, c.f. http://www.w3.org/2001/sw/DataAccess/tests/
> but that still breaks the rule of having variables that can only be
> bound 
> in the optional part, but can, I think be expanded to something like:
> [using SQL+RDF and a subset of 3stores schema]

The rule I think is needed is that a variable can't be bound in two separate
OPTIONALs - that causes the non-deterministic behaviour that Phil noted.
Variables can be bound in OPTIONALs (that's the point of them!) and binding
twice in one match is fine.  Its the whole OPTIONAL block that
matches/doesn't match.

	Andy

PS The new syntax is a bit clearer that there is one optional block in that
query.

 SELECT ?obj, ?objlabel
 WHERE  { <http://example.com/foo> ?prop ?obj . }
 OPTIONAL
        { ?obj ?tmp ?objlabel .
          ?tmp rdfs:subPropertyOf rdfs:label }




> 
> SELECT t1.object, t2.object
> FROM triples t1
> LEFT JOIN triples t2 ON
>       (t2.subject = t1.object)
> LEFT JOIN triples t3 ON
>       (t3.subject = t2.predicate AND
>        t3.predicate = <rdfs:subPropertyOf> AND
>        t3.object = <rdfs:label>)
> WHERE t1.subject = <http://example.com/foo>
> 
> - Steve

Received on Tuesday, 24 August 2004 09:50:03 UTC