@@ -9464,9 +9464,10 @@ <h4>Aggregate Algebra</h4>
9464
9464
</ol>
9465
9465
9466
9466
<p><b>Special Case:</b> when <code>COUNT</code> is used with the expression
9467
- <code>*</code> the value of F will be the cardinality of the group solution sequence,
9468
- <code>card[Ψ]</code>, or <code>card[Dedup(Ψ)]</code> if the <code>DISTINCT</code>
9469
- keyword is present.</p>
9467
+ <code>*</code>, then F(Ψ) is the cardinality of the group solution sequence,
9468
+ i.e., F(Ψ) = <a href="#defn_Card">Card</a>(Ψ),
9469
+ or F(Ψ) = <a href="#defn_Card">Card</a>(Dedup(Ψ))
9470
+ if the <code>DISTINCT</code> keyword is present.</p>
9470
9471
</div>
9471
9472
<p><i>scalarvals</i> are used to pass values to the underlying set function, bypassing
9472
9473
the mechanics of the grouping. For example, the aggregate expression
@@ -9514,11 +9515,11 @@ <h4>Aggregate Algebra</h4>
9514
9515
<p><b>Definition: AggregateJoin</b></p>
9515
9516
<p>Let S<sub>1</sub>, ..., S<sub>n</sub> be a list of sets, where each set
9516
9517
S<sub>i</sub> contains key to (aggregated) value maps as produced by Aggregate.</p>
9517
- <p>Let K = { key | key in dom(S<sub>j</sub>) for some 1 <= j <= n } be the set of
9518
+ <p>Let K = { key | key in dom(S<sub>j</sub>) for some 1 ≤ j ≤ n } be the set of
9518
9519
keys, then<br>
9519
9520
AggregateJoin(S<sub>1</sub>, ..., S<sub>n</sub>) = { agg<sub>1</sub>→val<sub>1</sub>,
9520
9521
..., agg<sub>n</sub>→val<sub>n</sub> | key in K and key→val<sub>i</sub> in
9521
- S<sub>i</sub> for each 1 <= i <= n }</p>
9522
+ S<sub>i</sub> for each 1 ≤ i ≤ n }</p>
9522
9523
</div>
9523
9524
<p>Flatten is a function which is used to collapse a sequence of lists into a single list.
9524
9525
For example, [(1, 2), (3, 4)] becomes (1, 2, 3, 4).</p>
@@ -9527,6 +9528,11 @@ <h4>Aggregate Algebra</h4>
9527
9528
<p>The Flatten(S) function takes a sequence of lists, S = [(L<sub>1</sub>, L<sub>2</sub>,
9528
9529
...), ...], and returns the list ( x | L in S and x in L ).</p>
9529
9530
</div>
9531
+ <p>Card is a function that returns the cardinality of a sequence or a list of elements (which may be solution mappings or other types of elements, depending on the context).
9532
+ <div class="defn">
9533
+ <p><b>Definition: <span id="defn_Card">Card</span></b></p>
9534
+ <p>Given a sequence or a list |L|, Card(|L|) is the cardinality of |L|.</p>
9535
+ </div>
9530
9536
<section id="setFunctions">
9531
9537
<h5>Set Functions</h5>
9532
9538
<p>The set functions which underlie SPARQL aggregates all have a common signature:
@@ -9558,7 +9564,7 @@ <h5>Count</h5>
9558
9564
<pre class="code nohighlight">xsd:integer Count(sequence S)</pre>
9559
9565
<p>L = Flatten(S)</p>
9560
9566
<p>remove error elements from L</p>
9561
- <p>Count(S) = card[L] </p>
9567
+ <p>Count(S) = <a href="#defn_Card">Card</a>(L) </p>
9562
9568
</div>
9563
9569
</section>
9564
9570
<section id="aggSum">
@@ -9573,10 +9579,10 @@ <h5>Sum</h5>
9573
9579
<pre class="code nohighlight">numeric Sum(sequence S)</pre>
9574
9580
<p>L = Flatten(S)</p>
9575
9581
<p>Sum(S) = Sum(L)</p>
9576
- <p>Sum(L) = op:numeric-add(L<sub>1</sub>, Sum(L<sub>2..n</sub>)) when card[L] >
9582
+ <p>Sum(L) = op:numeric-add(L<sub>1</sub>, Sum(L<sub>2..n</sub>)) if <a href="#defn_Card">Card</a>(L) >
9577
9583
1<br>
9578
- Sum(L) = op:numeric-add(L<sub>1</sub>, 0) when card[L] = 1<br>
9579
- Sum(L) = "0"^^xsd:integer when card[L] = 0</p>
9584
+ Sum(L) = op:numeric-add(L<sub>1</sub>, 0) if <a href="#defn_Card">Card</a>(L) = 1<br>
9585
+ Sum(L) = "0"^^xsd:integer if <a href="#defn_Card">Card</a>(L) = 0</p>
9580
9586
<p>In this way, Sum( (1, 2, 3) ) = op:numeric-add(1, op:numeric-add(2,
9581
9587
op:numeric-add(3, 0))).</p>
9582
9588
</div>
@@ -9588,8 +9594,8 @@ <h5>Avg</h5>
9588
9594
<div class="defn">
9589
9595
<p><b>Definition: <span id="defn_aggAvg">Avg</span></b></p>
9590
9596
<pre class="code nohighlight">numeric Avg(sequence S)</pre>
9591
- <p>Avg(S) = "0"^^xsd:integer, where Count(S) = 0</p>
9592
- <p>Avg(S) = Sum(S) / Count(S), where Count(S) > 0</p>
9597
+ <p>Avg(S) = "0"^^xsd:integer if Count(S) = 0</p>
9598
+ <p>Avg(S) = Sum(S) / Count(S) if Count(S) > 0</p>
9593
9599
</div>
9594
9600
<p>For example, Avg([(1), (2), (3)]) = Sum([(1), (2), (3)])/Count([(1), (2), (3)]) = 6/3 = 2.</p>
9595
9601
</section>
@@ -9605,8 +9611,8 @@ <h5>Min</h5>
9605
9611
<p>L = Flatten(S)</p>
9606
9612
<p>Min(S) = Min(L)</p>
9607
9613
<p>The flattened list L of values is ordered as per the <code>ORDER BY ASC</code> clause.</p>
9608
- <p>Min(L) = L<sub>0 </sub> if card[L] > 0<br>
9609
- Min(L) = error if card[L] = 0</p>
9614
+ <p>Min(L) = L<sub>1 </sub> if <a href="#defn_Card">Card</a>(L) > 0<br>
9615
+ Min(L) = error if <a href="#defn_Card">Card</a>(L) = 0</p>
9610
9616
</div>
9611
9617
</section>
9612
9618
<section id="aggMax">
@@ -9621,8 +9627,8 @@ <h5>Max</h5>
9621
9627
<p>L = Flatten(S)</p>
9622
9628
<p>Max(S) = Max(L)</p>
9623
9629
<p>The flattened list L of values is ordered as per the <code>ORDER BY DESC</code> clause.</p>
9624
- <p>Max(L) = L<sub>0 </sub> if card[L] > 0<br>
9625
- Max(L) = error if card[L] = 0</p>
9630
+ <p>Max(L) = L<sub>1 </sub> if <a href="#defn_Card">Card</a>(L) > 0<br>
9631
+ Max(L) = error if <a href="#defn_Card">Card</a>(L) = 0</p>
9626
9632
</div>
9627
9633
</section>
9628
9634
<section id="aggGroupConcat">
@@ -9633,17 +9639,18 @@ <h5>GroupConcat</h5>
9633
9639
SEPARATOR.</p>
9634
9640
<div class="defn">
9635
9641
<p><b>Definition: <span id="defn_aggGroupConcat">GroupConcat</span></b></p>
9636
- <pre class="code nohighlight">literal GroupConcat(sequence S)</pre>
9637
- <p>If the "separator" scalar argument is absent from GROUP_CONCAT then it is taken to
9638
- be the "space" character, unicode codepoint U+0020.</p>
9642
+ <pre class="code nohighlight">literal GroupConcat(sequence S, function scalarvals)</pre>
9643
+ <p>If the scalarvals argument is absent from GROUP_CONCAT, then scalarvals is taken to
9644
+ be the empty function.</p>
9645
+ <p>|separator| = scalarvals("separator") if scalarvals is defined for the argument "separator"</p>
9646
+ <p>|separator| = the "space" character, unicode codepoint U+0020, if scalarvals is undefined for the argument "separator"</p>
9639
9647
<p>L = Flatten(S)</p>
9640
- <p>GroupConcat(S, scalarvals) = GroupConcat(L, scalarvals("separator"))</p>
9641
- <p>GroupConcat(L, sep) = "", where <span style=
9642
- "font-size: 140%">|</span>L<span style="font-size: 140%">|</span> = 0</p>
9643
- <p>GroupConcat(L, sep) = CONCAT("", L<sub>0</sub>), where
9644
- <span style="font-size: 140%">|</span>L<span style="font-size: 140%">|</span> = 1</p>
9645
- <p>GroupConcat(L, sep) = CONCAT(L<sub>0</sub>, sep, GroupConcat(L<sub>1..n-1</sub>,
9646
- sep)), where <span style="font-size: 140%">|</span>L<span style="font-size: 140%">|</span> > 1</p>
9648
+ <p>GroupConcat(S, scalarvals) = GroupConcat(L, |separator|)</p>
9649
+ <p>GroupConcat(L, sep) = "" if <a href="#defn_Card">Card</a>(L) = 0</p>
9650
+ <p>GroupConcat(L, sep) = CONCAT("", L<sub>1</sub>) if
9651
+ <a href="#defn_Card">Card</a>(L) = 1</p>
9652
+ <p>GroupConcat(L, sep) = CONCAT(L<sub>1</sub>, sep, GroupConcat(L<sub>2..n</sub>,
9653
+ sep)) if <a href="#defn_Card">Card</a>(L) > 1</p>
9647
9654
</div>
9648
9655
<p>For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) = "a.b.c".</p>
9649
9656
</section>
0 commit comments