@@ -9474,9 +9474,10 @@ <h4>Aggregate Algebra</h4>
9474
9474
</ol>
9475
9475
9476
9476
<p><b>Special Case:</b> when <code>COUNT</code> is used with the expression
9477
- <code>*</code> the value of F will be the cardinality of the group solution sequence,
9478
- <code>card[Ψ]</code>, or <code>card[Dedup(Ψ)]</code> if the <code>DISTINCT</code>
9479
- keyword is present.</p>
9477
+ <code>*</code>, then F(Ψ) is the cardinality of the group solution sequence,
9478
+ i.e., F(Ψ) = <a href="#defn_Card">Card</a>(Ψ),
9479
+ or F(Ψ) = <a href="#defn_Card">Card</a>(Dedup(Ψ))
9480
+ if the <code>DISTINCT</code> keyword is present.</p>
9480
9481
</div>
9481
9482
<p><i>scalarvals</i> are used to pass values to the underlying set function, bypassing
9482
9483
the mechanics of the grouping. For example, the aggregate expression
@@ -9537,6 +9538,11 @@ <h4>Aggregate Algebra</h4>
9537
9538
<p>The Flatten(S) function takes a sequence of lists, S = [(L<sub>1</sub>, L<sub>2</sub>,
9538
9539
...), ...], and returns the list ( x | L in S and x in L ).</p>
9539
9540
</div>
9541
+ <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).
9542
+ <div class="defn">
9543
+ <p><b>Definition: <span id="defn_Card">Card</span></b></p>
9544
+ <p>Given a sequence or a list |L|, Card(|L|) is the cardinality of |L|.</p>
9545
+ </div>
9540
9546
<section id="setFunctions">
9541
9547
<h5>Set Functions</h5>
9542
9548
<p>The set functions which underlie SPARQL aggregates all have a common signature:
@@ -9568,7 +9574,7 @@ <h5>Count</h5>
9568
9574
<pre class="code nohighlight">xsd:integer Count(sequence S)</pre>
9569
9575
<p>L = Flatten(S)</p>
9570
9576
<p>remove error elements from L</p>
9571
- <p>Count(S) = card[L] </p>
9577
+ <p>Count(S) = <a href="#defn_Card">Card</a>(L) </p>
9572
9578
</div>
9573
9579
</section>
9574
9580
<section id="aggSum">
@@ -9583,10 +9589,10 @@ <h5>Sum</h5>
9583
9589
<pre class="code nohighlight">numeric Sum(sequence S)</pre>
9584
9590
<p>L = Flatten(S)</p>
9585
9591
<p>Sum(S) = Sum(L)</p>
9586
- <p>Sum(L) = op:numeric-add(L<sub>1</sub>, Sum(L<sub>2..n</sub>)) when card[L] >
9592
+ <p>Sum(L) = op:numeric-add(L<sub>1</sub>, Sum(L<sub>2..n</sub>)) when <a href="#defn_Card">Card</a>(L) >
9587
9593
1<br>
9588
- Sum(L) = op:numeric-add(L<sub>1</sub>, 0) when card[L] = 1<br>
9589
- Sum(L) = "0"^^xsd:integer when card[L] = 0</p>
9594
+ Sum(L) = op:numeric-add(L<sub>1</sub>, 0) when <a href="#defn_Card">Card</a>(L) = 1<br>
9595
+ Sum(L) = "0"^^xsd:integer when <a href="#defn_Card">Card</a>(L) = 0</p>
9590
9596
<p>In this way, Sum( (1, 2, 3) ) = op:numeric-add(1, op:numeric-add(2,
9591
9597
op:numeric-add(3, 0))).</p>
9592
9598
</div>
@@ -9615,8 +9621,8 @@ <h5>Min</h5>
9615
9621
<p>L = Flatten(S)</p>
9616
9622
<p>Min(S) = Min(L)</p>
9617
9623
<p>The flattened list L of values is ordered as per the <code>ORDER BY ASC</code> clause.</p>
9618
- <p>Min(L) = L<sub>0</sub> if card[L] > 0<br>
9619
- Min(L) = error if card[L] = 0</p>
9624
+ <p>Min(L) = L<sub>0</sub> if <a href="#defn_Card">Card</a>(L) > 0<br>
9625
+ Min(L) = error if <a href="#defn_Card">Card</a>(L) = 0</p>
9620
9626
</div>
9621
9627
</section>
9622
9628
<section id="aggMax">
@@ -9631,8 +9637,8 @@ <h5>Max</h5>
9631
9637
<p>L = Flatten(S)</p>
9632
9638
<p>Max(S) = Max(L)</p>
9633
9639
<p>The flattened list L of values is ordered as per the <code>ORDER BY DESC</code> clause.</p>
9634
- <p>Max(L) = L<sub>0</sub> if card[L] > 0<br>
9635
- Max(L) = error if card[L] = 0</p>
9640
+ <p>Max(L) = L<sub>0</sub> if <a href="#defn_Card">Card</a>(L) > 0<br>
9641
+ Max(L) = error if <a href="#defn_Card">Card</a>(L) = 0</p>
9636
9642
</div>
9637
9643
</section>
9638
9644
<section id="aggGroupConcat">
@@ -9648,12 +9654,11 @@ <h5>GroupConcat</h5>
9648
9654
be the "space" character, unicode codepoint U+0020.</p>
9649
9655
<p>L = Flatten(S)</p>
9650
9656
<p>GroupConcat(S, scalarvals) = GroupConcat(L, scalarvals("separator"))</p>
9651
- <p>GroupConcat(L, sep) = "", where <span style=
9652
- "font-size: 140%">|</span>L<span style="font-size: 140%">|</span> = 0</p>
9657
+ <p>GroupConcat(L, sep) = "", where <a href="#defn_Card">Card</a>(L) = 0</p>
9653
9658
<p>GroupConcat(L, sep) = CONCAT("", L<sub>0</sub>), where
9654
- <span style="font-size: 140%">|</span>L<span style="font-size: 140%">|</span> = 1</p>
9659
+ <a href="#defn_Card">Card</a>(L) = 1</p>
9655
9660
<p>GroupConcat(L, sep) = CONCAT(L<sub>0</sub>, sep, GroupConcat(L<sub>1..n-1</sub>,
9656
- sep)), where <span style="font-size: 140%">|</span>L<span style="font-size: 140%">|</span> > 1</p>
9661
+ sep)), where <a href="#defn_Card">Card</a>(L) > 1</p>
9657
9662
</div>
9658
9663
<p>For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) = "a.b.c".</p>
9659
9664
</section>
0 commit comments