Actually, since Gerrit wants just the resource with the latest date, a
SPIN function may be a better route to go.  The function body would
be:

SELECT ?lastEvent
WHERE {
    ?lastEvent a events:InteractionEvent .
    ?lastEvent events:generatedBy ?arg1 .
    ?lastEvent events:inXSDDateTime ?last .
}
ORDER BY DESC (?last)
LIMIT 1

...where ?arg1 is passed as a parameter.  Then the spin:rule would be:

CONSTRUCT {
    ?this events:hasLastEvent ?lastEvent .
}
WHERE {
    BIND (events:getMaxDateRsc(?this) AS ?lastEvent) .
}

-- Scott

On Jan 4, 1:50 pm, Holger Knublauch <[email protected]> wrote:
> Hi Gerrit,
>
> I am pretty sure that the pre-binding mechanism of SPARQL is not defined for 
> sub-selects. ?this is bound by the SPIN engine when the surrounding query 
> executes, but this isn't propagated into the sub-query by definition. See
>
> http://www.w3.org/TR/sparql11-query/#subqueries
>
> "Note that only variables projected out of the subquery will be visible, or 
> in scope to the outer query."
>
> The work-around is to turn the sub-select into a magic property, where you 
> pass in ?this as an argument.
>
> HTH
> Holger
>
> On Jan 4, 2012, at 9:03 PM, Gerrit wrote:
>
>
>
>
>
>
>
> > I'm trying to implement a SPIN rule that will find the last event in a
> > set of events:
>
> > CONSTRUCT {
> >    ?this events:hasLastEvent ?lastEvent .
> > }
> > WHERE {
> >        SELECT ?lastEvent
> >        WHERE {
> >            ?lastEvent a events:InteractionEvent .
> >            ?lastEvent events:generatedBy ?this .
> >            ?lastEvent events:inXSDDateTime ?last .
> >        }
> >        ORDER BY DESC (?last)
> >        LIMIT 1
> > }
>
> > It seems that the SELECT sub-query is evaluated once for ?this, and
> > then used for all other instances of ?this, that results in for
> > example
>
> > events:lamp1 events:hasLastEvent events:event1234
> > events:lamp2 events:hasLastEvent events:event1234
>
> > while events:event1234 is not even related to events:lamp2. The reason
> > why I think this is caused by the ?this keyword in the sub-query, is
> > that executing this query in SPARQL View provides the correct result.
>
> > --
> > You received this message because you are subscribed to the Google
> > Group "TopBraid Suite Users", the topics of which include TopBraid Composer,
> > TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
> > To post to this group, send email to
> > [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/topbraid-users?hl=en

-- 
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include TopBraid Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

Reply via email to