I am trying to use 2 columns returned by a magic property (identifiers and 
values, respectively) and to sum the values of like identifiers.

I wrote a recursive SPIN function that does the job if the arguments are 
rdf:Lists (since I can recurse on rdf:List). But the magic property that 
provides the columns is not doing so in the form of rdf:List. So I am 
looking for alternative approaches to solving the problem. Has anyone done 
this kind of thing before? I am provided detailed information below:

The original magic property (below) grouped and summed the results nicely, 
but could not be run as a web service, so we turned to using the 
efunc:getQuantitySet results as input to another magic property that would 
group and sum.

*SELECT*  ?uID (*SUM* (?demand) *AS* ?total)

*WHERE* {

    "test1" *efunc:relevantBuildings* ?resourceID .

    *BIND* (efunc:getLargestModNum(?arg1, "BID_LOAD", ?resourceID) *AS* 
?modNum) .

    ( ?eventID ?modNum ?resourceID "BID_LOAD" ) *efunc:getQuantitySet* ( 
?uID ?demand ) .

}

*GROUP* *BY* ?uID
*ORDER* *BY* (xsd:integer (?uID))

So I defined a new magic property to get just the results of the 
efunc:getQuantitySet magic property but without the GROUP and SUM 
(efunc:getLatestForecasts):

 

*SELECT* *DISTINCT* ?resourceID ?uID ?demand

*WHERE* {

    *?arg1* *efunc:relevantBuildings* ?resourceID .

    *BIND* (efunc:getLargestModNum(*?arg1*, "BID_LOAD", ?resourceID) *AS* 
?modNum) .

    ( ?eventID ?modNum ?resourceID "BID_LOAD" ) *efunc:getQuantitySet* ( 
?uID ?demand ) .

}

 

Which, when executed as follows:

 

*SELECT* ?resourceID ?uID ?demand

*WHERE* {

    *BIND* ("178805" *AS* ?arg1) .

    ?arg1 *efunc:getLatestForecasts* (?resourceID ?uID ?demand) .

}

 

produces content like this:

 

[resourceID]          uID                  demand

 

(s) AAS                (s) 15              (F) 0.055

(s) AAS                (s) 7                (F) 0.093

(s) CIEE               (s) 0                (F) 0.056

(s) CIEE               (s) 8                (F) 0.073
 

Test the sum SPIN function (efunc:sumForecasts) with expected arguments:

 

*SELECT* ?result

*WHERE* {

    *?arg2* rdf:first ?uifirst .

    *?arg2* rdf:rest ?uirest .

    *?arg3* rdf:first ?fcfirst .

    *?arg3* rdf:rest ?fcrest .

    *BIND* (*IF*((*?arg1* = ?uifirst), *IF*((?uirest = rdf:nil), ?fcfirst, (
?fcfirst + efunc:sumForecasts(*?arg1*, ?uirest, ?fcrest, *?arg4*))), *IF*((
*?arg4* != 0), ?fcfirst, *IF*((?uirest != rdf:nil), efunc:sumForecasts(
*?arg1*, ?uirest, ?fcrest, *?arg4*), *?arg4*))) *AS* ?result) .

}

 

Which, when executed as follows:

 

*SELECT* *DISTINCT* ?item ?sum

*WHERE* {

    *BIND* (nmtest:intervalList *AS* ?arg2) .

    *BIND* (nmtest:forecastList *AS* ?arg3) .

    ?arg2 (rdf:rest)*/rdf:first ?item .

    *BIND* (efunc:sumForecasts(?item, ?arg2, ?arg3, 0) *AS* ?sum) .

} *ORDER* *BY* ?item

 

on the following rdf:Lists:

 

nmtest:intervalList: ["0", "0", "1", "2", "2", "3"]

nmtest:forecastList: [0.056, 0.056, 0.054, 0.052, 0.052, 0.4]

 

produces content like this:

 

item            sum

 

(s) 0            0.112

(s) 1            0.054

(s) 2            0.104

(s) 3            0.4

 

It does not seem reasonable to convert the results of efunc:getQuantitySet 
to rdf:List, so I am looking into a Javascript version to take the original 
results of efunc:getQuantitySet and sum them. Any advice would be most 
appreciated.


Jack Hodges, Siemens

-- 
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 topbraid-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to