> Background:  ?this is a :DataSet and it  has a :records object property, 
> range :Record and a :numberOfRecords computed via a spin rule. :Record has 
> properties :rate (xsd:float), :time (xsd:dateTime), and :cumulative 
> (xsd:float).  Each :Records has :rate and :time values assigned.  The :Record 
> :index starts at 1 for the earliest time.  The first :record (:index =1 ) has 
> a :cumulative value 0.
> 
> CONSTRUCT {
>  ?record2 :cumulative ?cumulative2 }
> WHERE {
>      ?this :numberRecords ?N
>      ?j tops:for (2 N ) .
>       LET ( ?i := ?j -1) 
>       ?record1 :index ?i .
>       ?record1 ^:records ?this.
>       ?record1 :time ?t1 .
>       ?record1 :cumulative ?cumulative1
>       ?record2 :index ?j .
>       ?record2 ^:records ?this.
>        ?record2  :time ?t2 .
>        ?record2 :rate ?rate2 .
>        LET (?cumulative2 := (?cumulative1 + (?rate2 * 
> datetime:daysBetween(?t1, ?t2)))) .
> }
> 
> We are concerned about 2 things 1) the scalability of this kind query up to 
> 10,000 records, 2) how to generalize this for arbitrary windows, and 3) the 
> index could become a problem.  That is why we are investigating other ways to 
> do it.

Hi Arthur,

without knowing details, the above solution indeed does not look efficient, 
especially because it relies on the chaining of SPIN rules in an "outer" loop. 
Also you are required to store intermediate values in records, while in reality 
you seem to be more interested in the end result. An alternative that should 
work already is to use recursive SPIN functions like I am doing in the SPIN 
Result Sets implementation (see last email). This is very geeky stuff but works 
- basically the idea is to have something like

        function step(n)
            ... FILTER (n > 0) .
            ... LET (?result := ?cumulative + step(n-1)

Those approaches require the definition of SPIN functions, and are limited by 
potential stack overflows for very large data sets (because of the recursion at 
the end adds to the stack). Doing such aggregations will become significantly 
easier with the upcoming release and the SPIN Result Sets support (via 
SPARQLMotion). If you start using JavaScript you could as well just drop the 
use of RDF and SPARQL altogether, as you would work on entirely different data 
structures that have no way back (i.e. it is not possible to call SPARQL or RDF 
functions from JavaScript, so anything like a daysBetween function would need 
to be coded in JS, etc etc).

A side question: your use of inverse property paths (^) is for readability 
only? You could of course also write ?this :records ?record2 etc.

Holger

-- 
You received this message because you are subscribed to the Google Groups 
"TopBraid Composer Users" group.
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-composer-users?hl=en.

Reply via email to