On 28/09/12 02:17, Yuhan Zhang wrote:
Hi all,

I'm trying to perform a dot product between two values, and sum them up.
Here's the query:

select ?v ( sum(?s1 * ?s2)  AS ?ss)
where {
  { <http://onescreen.com/video#2389800> <
http://onescreen.com/video_freebase#/american_football> ?s1 . ?v <
http://onescreen.com/video_freebase#/american_football>  ?s2 }
  UNION
  { <http://onescreen.com/video#2389800> <
http://onescreen.com/video_freebase#/american_football/football_player> ?s1
. ?v <http://onescreen.com/video_freebase#/american_football/football_player>
  ?s2 }
} group by ?v order by DESC (?ss) limit 100


However, instead of sum(?s1 * ?s2) , I'd like to have something like
sum(?s1 * min(?s1*?s2) ) , to multiple ?s2 but not more than ?s1. and I

sum(?s1 * min(?s1, ?s2) ) presumably

reached syntax error, as min function meant to be used to aggregate across
columns within one variable.

so, my question is, is this calculation possible to achieve easily from
sparql?  sum(?s1 * min(?s1*?s2) ) ? How should I make this happen?


Thank you.

Yuhan


Two ways:

1/
IF(?s1<?s2, ?s1, ?s2)

SPARQL IF returns values.


2/
See
http://jena.apache.org/documentation/query/library-function.html

PREFIX afn <http://jena.hpl.hp.com/ARQ/function#>
afn:min(?s1, ?s2)


MIN is only an aggregation function and you can't directly put aggregation inside an aggregation because the outer aggregator executes the expression for each row as it goes along but that expression contains something that was calculated using every row of the group. You can do it with a subquery.

        Andy


Reply via email to