Thanks, Holger. I will check out SWP. On Tuesday, March 18, 2014 5:19:28 PM UTC-7, Holger Knublauch wrote: > > Hi Rich, > > one way of computing and returning multiple values at once is to use magic > properties, but those are limited in that they do not support aggregations > in the SELECT clause. > > But do you really run into performance issues where this would make a > difference? If yes, then using ui:Functions could theoretically be a > solution: > > http://www.topquadrant.com/2013/06/18/defining-sparql-functions-with-swp/ > > These are SPIN functions that have an SWP "script" as body, and in that > script you can implement any sophisticated logic that you like, e.g. to > pre-compute certain values and put them into a temporary graph > (ui:tempGraph), then have the aggregations walk that temporary graph only. > Note that those functions can still only return a single value, but they > could return something like a comma-separated string list... > > Holger > > > On 3/19/2014 9:25, Rich Keller wrote: > > Holger: I have a followup question. Creating a SPIN function that performs > the summation works well for computing a single sum to be passed back as > the function's return value. In my actual case, I'm trying to calculate > multiple sums and return them. While I could write a more general function > (or template) and call it several times to compute several sums, that is > quite inefficient because it will require performing essentially the same > SPARQL Select N times, once for each datatype property I wish to sum over. > > Can you suggest an alternative approach that would be more efficient? > > Thanks for your help, > Rich > > On Tuesday, March 18, 2014 9:25:30 AM UTC-7, Rich Keller wrote: >> >> Thanks Holger. I will try that. Rich >> >> On Monday, March 17, 2014 3:57:32 PM UTC-7, Holger Knublauch wrote: >>> >>> 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]. >>> 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] <javascript:> > To unsubscribe from this group, send email to > [email protected] <javascript:> > 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] <javascript:>. > 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.
