Alison; I'd suggest writing a SPIN function for this.  The function
would be a subclass of spin:Functions, let's call it :mySum.  It would
define one argument (spin:constraint).  Let's call that ?arg1 for
now.  The body of the query would be:

SELECT (SUM(?value) AS ?return)
WHERE
{  ?arg1 example:has_part ?value
}

You can then call it in any SPARQL query.  In your case, you'd pass
example:resource to it, or if in a SPIN rule, I'd expect you want ?
this:
  BIND(:mySum(?this) AS ?sum)

Note you can easily generalize the function to also take a property as
a second argument, then pass example:has_part or whatever to it.

The SPIN page has an example of a SPIN function - see Documentation in
http://www.topquadrant.com/products/SPIN.html.  And the tutorial has a
pretty good section on SPIN functions - see Documentation on the RHS
of the SPIN page..

-- Scott

On Sep 9, 3:42 pm, Alison Callahan <[email protected]> wrote:
> Hello all,
>
> I would like to write a spin:rule that sums integers connected with a
> resource and then connects the sum to the resource. For example, if a
> resource exists such that
>
> example:resource example:has_part "1"^^xsd:integer
> example:resource example:has_part "2"^^xsd:integer
>
> Is it possible to write a spin:rule that would take these numbers, sum them
> and assert
>
> example:resource example:has_sum_value "3"^^xsd:integer
>
> This seems like it would be relatively straightforward, but I don't know to
> handle a case in which it is not known beforehand how many numbers there are
> to be summed.
>
> Any help is appreciated, thanks,
>
> Alison

-- 
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