- From: Seaborne, Andy <andy.seaborne@hp.com>
 - Date: Sun, 19 Sep 2004 14:04:01 +0100
 - To: Steve Harris <S.W.Harris@ecs.soton.ac.uk>
 - Cc: public-rdf-dawg@w3.org
 
Steve Harris wrote:
> On Fri, Sep 17, 2004 at 02:42:37AM -0700, Rob Shearer wrote:
> 
>>A user wishes to find all the people who are either of type dog owner or own a
 >> pet who is  a dog.  The common case of no inferencing this is a pretty
 >> realistic  query.)
It does seem to be a reasonable query.  The contrast we have is between 
the implementation view and the application writer view.  I'd like to see 
queries express what the app writer wants.
 >> Some sample data:
>>
>>Rob type Person
>>Eddie type Person
>>Eddie type DogOwner
>>Mitch type Person
>>Mitch hasPet Fido
>>Fido type  Dog
>>
>>query
>>
>>select $x
>>where ($x type  Person)
>>      (($x type DogOwner) OR
>>       (($x hasPet $y) ($y type Dog))
>>
>>Is this query correct?
> 
> 
> Looks good to me, an OPTIONAL equivalent would be:
> 
> SELECT $x
> WHERE ($x type Person)
> OPTIONAL ($x type $typeA)
> OPTIONAL ($x hasPet $y) ($y type $typeB)
> AND $typeA = DogOwner || $typeB == Dog
Steve,
Would I be right in assuming the AND filters everything from the 
WHERE/OPTIONAL/OPTIONAL?
I'm curious as to what happens when expressions involve unbound variables?
Suppose unbound causes a evaluation error and the query solutiuon is 
rejected (this is the usual model for 3-state to 2-state logic - undef 
becomes false, any expression involving undef is undefined itself).  [I 
would strongly prefer the rule here that does depend on evaluation context 
wherever possible.]
If the data is just:
Rob type Person
Mitch type Person
Mitch hasPet Fido
Fido type Dog
then one query solution is:
   ?x=Mitch ; ?y=Fido ; ?typeB=Dog   // second optional clause
then the expression
    ?typeA = DogOwner || ?typeB == Dog
and has ?typeA undefined.
I think there would need to be a guard function "defined(?x)".  The 
shortest expression I came up with is:
AND ( defined($typeA) && $typeA == DogOwner )
     ||
     ( defined($typeB) && $typeB == Dog )
This is really testing for which branch the solution when down.
It took a while to work out (maybe my brian isn't in gear) - I wrote out 
all the cases and reduced the larger expression.
And that suggests:
SELECT $x
WHERE ($x type Person)
       [ ($x type $typeA) AND $typeA = DogOwner ]
       [ ($x hasPet $y) ($y type $typeB) AND $typeB == Dog ]
AND defined($typeA) || defined($typeB)
working by having a test to see that the query went down at least one 
branch.  That is the sort of thing a query optimizer might do with the 
original OR if the language had OR with the implementation changing to 
OPTIONAL as a query plan possibility.
I find the OR query more natural because it was more directly what the 
question was.
	Andy
> 
> [OT note] I found using $'s for this query quite distracting.
Certainly a case for one or (as in XOR!) the other
> 
> - Steve
> 
Received on Sunday, 19 September 2004 13:04:34 UTC