0

For the following data.ttl file:

A SAVINGS_1 200
A SAVINGS_2 300
A SAVINGS_3 370
A EMAIL emailidone
B SAVINGS_1 400
B SAVINGS_2 300
B SAVINGS_3 100
B EMAIL emailidtwo
C SAVINGS_1 200
C SAVINGS_2 600

The query:

SELECT ?NAME ?SAVINGS_1_VALUE ?SAVINGS_2_VALUE ?SAVINGS_3_VALUE WHERE { 
                                                                  ?NAME SAVINGS_1 ?SAVINGS_1_VALUE .
                                                                  ?NAME SAVINGS_2 ?SAVINGS_2_VALUE .
                                                                  ?NAME SAVINGS_3 ?SAVINGS_3_VALUE .
                                                                  ?NAME EMAIL ?email . }

Gives Output:

NAME  SAVINGS_1_VALUE  SAVINGS_2_VALUE  SAVINGS_3_VALUE
 A      200                 300              370
 B      400                 300              100
     

Is there a way to calculate the MAXIMUM of SAVINGS_1, SAVINGS_2 and SAVINGS_3 for individuals A, B and C who also has EMAIL using JENA ARQ Processor?

The expected query output would be

Expected Query output: NAME  SAVINGS_1_VALUE  SAVINGS_2_VALUE   SAVINGS_3_VALUE  MAXIMUM
                         A      200                 300              370           370
                         B      400                 300              100           400
                     
                     

MAX() function takes in only one argument, it can calculate the maximum of ?SAVINGS_1_VALUE or maximum of ?SAVINGS_2_VALUE and so on. Is there a way to evaluate maximum of ?SAVINGS_1_VALUE, ?SAVINGS_2_VALUE, ?SAVINGS_3_VALUE projections and add the result as another column? If the existing Jena Processor is not able to achieve this then what could be possible extension points to achieve this? Custom Aggregators also seem to evaluate on individual variable expression.

Note: There are multiples of variable expressions on which I want to evaluate this! So bind (if ... Is not an option for me to achieve this!

Adrika
  • 51
  • 2
  • why do you need an aggregate? Don't think too complicated: `BIND(if(?SAVINGS_1_VALUE > ?SAVINGS_2_VALUE, if(?SAVINGS_1_VALUE > ?SAVINGS_3_VALUE, ?SAVINGS_1_VALUE, ?SAVINGS_3_VALUE), ?SAVINGS_2_VALUE) as ?MAXIMUM)` - Note, this is untested as you didn't provide the data in proper Turtle format and I'm too lazy to convert your data – UninformedUser Sep 30 '20 at 06:22
  • What if there is 100s of such savings value. Bind if is not an option for the data I am trying to implement this on! Is there any other way that the existing processor can handle this? – Adrika Sep 30 '20 at 07:50
  • I don't see why BIND is not an option, it's clearly the most obvious and probably most efficient way ... and if you have 100s of saving values, you have to add 100s of projection variables and 100s of triple patterns, i.e. 100s of joins during evaluation - sounds weird. – UninformedUser Sep 30 '20 at 08:10
  • Anyways, you could try the `UNION` of all values and then `GROUP BY` the NAME, maybe just use `VALUES` like this and do the grouping stuff . For example, `VALUES ?p {SAVINGS_1 SAVINGS_2 ... SAVINGS_N} ?NAME ?p ?v . }` would give you all values bound to a single variable. But, then you have to use group by on all your projections variables ... – UninformedUser Sep 30 '20 at 08:12
  • Note, at some point, SPARQL isn't really good at visualizing data and in that case doing the post-processing on client side might be more promising. – UninformedUser Sep 30 '20 at 08:13
  • Thank you for your reply. I know there might be 100s of projections but writing a nested if inside bind will not be straightforward for the user. I will try the next option though. – Adrika Sep 30 '20 at 11:55

0 Answers0