Re: quick sanity check question on sub-query, service and variable scoping

Hi Gary,
SERVICE blocks and sub-queries have different semantics relating to the
variable scope.

The variables in a sub-query are in a scope disjoint from the enclosing
one, unless they are projected in the SELECT clause.
So in the first example the variable ?time1 in the sub-query is distinct
from the variable ?time1 in the main query.
In this case you are correct, the inner ?time1 won't never be bound.

The variables in a SERVICE blocks instead, share the same scope as the
enclosing query.
So in the second example there is only a ?time1 variable, referenced both
inside and outside the SERVICE block.
In this case ?time1 main perfectly be bound.
Of course, if it is actually bound or not depends on the data.

Best,
Miguel


Il giorno lun 19 ott 2015 alle ore 13:56 Gary King <gwking@metabang.com> ha
scritto:

> Here is a contrived example trying to find when some person has a
> startTime after other people (I did say it was contrived :-)). First with
> sub-query and then with SERVICE:
>
> select distinct * {
>   ?person a ex:Person .
>   ?person ex:startTime ?time1 .
>
>   { select ?otherPerson {
>     ?otherPerson a ex:Person .
>     ?otherPerson ex:startTime ?time2 .
>     FILTER (?time2 > ?time1)
>   } }
> }
>
> select distinct * {
>   ?person a ex:Person .
>   ?person ex:startTime ?time1 .
>
>   service <http://example.com/foo> {
>     ?otherPerson a ex:Person .
>     ?otherPerson ex:startTime ?time2 .
>     FILTER (?time2 > ?time1)
>   }
> }
>
> My belief is that both of these will correctly return no results because
> `?time1` is not bound in either the sub-query or the service call and so
> the filter will uniformly fail.
>
> Correct?
>
> thanks,
>
> --
> Gary Warren King, metabang.com
> Cell: (413) 559 8738
> Fax: (206) 338-4052
> gwkkwg on Skype * garethsan on AIM * gwking on twitter
>
>
>

Received on Monday, 19 October 2015 18:27:23 UTC