Hi Rich,

in general, nested sub-selected do not see the bindings of variables from the outer query. If you want to perform an aggregation, try turning the inner SELECT into a SPIN function where you can explicitly pass the required arguments. E.g. the spin:body of that function ex:myCount would be

            SELECT ((SUM(?hourlyCount)) AS ?dailyCount)
            WHERE {
?arg1 :xday ?day . #Should bind ?day to the :xday value for the specific instance over which the rule is firing
                ?hourly :day ?day .
                ?hourly :count ?hourlyCount .
            }

where ?arg1 is substituted with ?this when you call it in the rule:

CONSTRUCT {
        ?this :xcount ?dailyCount .
    }
    WHERE {
        BIND (ex:myCount(?this) AS ?dailyCount) .
    }

HTH
Holger


On 3/18/2014 8:37, Rich Keller wrote:
Hi. I have been having trouble with a SPIN rule I've constructed to aggregate a set of values. It seems as if the variable ?*this* is not being bound properly, and I wonder if this is due to my SPARQL formulation or to TBC.

Here is the problem. Conceptually, there are counts of a particular phenomenon occurring on a given day during a given hour: <day, hour, count>. The rule's task is to sum the counts for each hour, and assign that sum to the count for the appropriate day. The SPIN rule is defined for a 'Daily' object (representing a day); the counts are assigned to 'Hourly' objects (representing an hour of a particular day).

I assumed that the aggregation function SUM (in the rule below) would sum over only the counts for a single day, because I constrained the variable ?day using ?*this*. However, the results indicate that the day was not constrained because the sum for each day is the same: the grand total of all counts over all days. Perhaps I do not understand the scoping rules for ?*this* within the SPARQL expression.

Any guidance would be appreciated! When I execute the SELECT clause alone in the SPARQL Query Editor, substituting a specific 'Daily' instance for ?*this*, I do get the desired sum for the hours in that day.

Thanks,
Rich


:Daily a owl:Class ;
    spin:rule
    "CONSTRUCT {
        ?this :xcount ?dailyCount .
    }
    WHERE {
        {
            SELECT ((SUM(?hourlyCount)) AS ?dailyCount)
            WHERE {
?this :xday ?day . #Should bind ?day to the :xday value for the specific instance over which the rule is firing
                ?hourly :day ?day .
                ?hourly :count ?hourlyCount .
            }
        } .
    }"

:D1 a :Daily;
    :xday 1 .

:D2 a :Daily;
    :xday 2 .


:Hourly a owl:Class .

:H1D1 a :Hourly;
    :count      10 ;
    :hour  1 ;
    :day        1 .

:H2D1 a :Hourly;
    :count      10 ;
    :hour  2 ;
    :day        1 .

:H3D1 a :Hourly;
    :count      10 ;
    :hour  3 ;
    :day        1 .

:H1D2 a :Hourly;
    :count      10 ;
    :hour  1 ;
    :day        2 .

:H2D2 a :Hourly;
    :count      10 ;
    :hour  2 ;
    :day        2 .

----------------

Inference Result:

:D1 :xcount 50
:D2 :xcount 50

Expected Result:

:D1 :xcount 30
:D2 :xcount 20
--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL Web Pages 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 Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary 
Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL 
Web Pages 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 Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to