Skip to content

Commit 092d14f

Browse files
authored
Merge pull request #110 from w3c/Multiplicity
introduces a function called multiplicity to replace card[Ω](μ)
2 parents cefbd53 + 376e0c6 commit 092d14f

File tree

1 file changed

+64
-40
lines changed

1 file changed

+64
-40
lines changed

spec/index.html

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,8 +3916,8 @@ <h4>DISTINCT</h4>
39163916
<h4>REDUCED</h4>
39173917
<p>While the <code>DISTINCT</code> modifier ensures that duplicate solutions are
39183918
eliminated from the solution set, <code>REDUCED</code> simply permits them to be
3919-
eliminated. The cardinality of any set of variable bindings in a <code>REDUCED</code>
3920-
solution set is at least one and not more than the cardinality of the solution set with
3919+
eliminated. The multiplicity of any solution in a <code>REDUCED</code>
3920+
solution set is at least one and not more than the multiplicity of the solution within the solution set with
39213921
no <code>DISTINCT</code> or <code>REDUCED</code> modifier. For example, using the data
39223922
above, the query</p>
39233923
<div class="queryGroup">
@@ -9005,7 +9005,7 @@ <h4>Converting Solution Modifiers</h4>
90059005
<li>Limit</li>
90069006
</ul>
90079007
<p>Step: ToList</p>
9008-
<p>ToList turns a multiset into a sequence with the same elements and cardinality. There is
9008+
<p>ToList turns a multiset into a sequence with the same elements and multiplicities. There is
90099009
no implied ordering to the sequence; duplicates need not be adjacent.</p>
90109010
<blockquote>
90119011
<p>Let M := ToList(Pattern)</p>
@@ -9067,15 +9067,15 @@ <h3>Basic Graph Patterns</h3>
90679067
<a href="https://en.wikipedia.org/w/index.php?title=Multiset">multiset</a>,
90689068
also known as a <i>bag</i>. A multiset is an
90699069
unordered collection of elements in which each element may appear more than once. It is
9070-
described by a set of elements and a cardinality function giving the number of occurrences of
9071-
each element from the set in the multiset.</p>
9072-
<p>Write μ for solution mappings.</p>
9073-
<p>Write μ<sub>0</sub> for the mapping such that dom(μ<sub>0</sub>) is the empty set.</p>
9074-
<p>Write Ω<sub>0</sub> for the multiset consisting of exactly the empty mapping
9075-
μ<sub>0,</sub> with cardinality 1. This is the join identity.</p>
9076-
<p>Write μ(x) for the solution mapping variable x to RDF term t : { (x, t) }</p>
9077-
<p>Write Ω(x) for the multiset consisting of exactly μ(?x-&gt;t), that is, { { (x, t) } }
9078-
with cardinality 1.</p>
9070+
described by a set of elements and a function giving the multiplicity of each of these
9071+
elements (i.e., the number of times the element is contained in the multiset).</p>
9072+
<p>Write <var>μ</var> for solution mappings.</p>
9073+
<p>Write <var>μ<sub>0</sub></var> for the mapping such that <var>dom</var>(<var>μ<sub>0</sub></var>) is the empty set.</p>
9074+
<p>Write <var>Ω<sub>0</sub></var> for the multiset consisting of exactly the empty mapping
9075+
<var>μ<sub>0</sub></var>, with multiplicity 1. This is the join identity.</p>
9076+
<p>Write <var>μ</var>(<var>x</var>) for the solution mapping variable <var>x</var> to RDF term <var>t</var> : { (<var>x</var>, <var>t</var>) }.</p>
9077+
<p>Write <var>Ω</var>(<var>x</var>) for the multiset consisting of exactly <var>μ</var>(<var>?x</var>-&gt;<var>t</var>), that is, <code>{ { (x, t) } }</code>
9078+
with multiplicity 1.</p>
90799079
<div class="defn">
90809080
<p><b>Definition: <span id="defn_algCompatibleMapping">Compatible Mappings</span></b></p>
90819081
<p>Two solution mappings μ<sub>1</sub> and μ<sub>2</sub> are compatible if, for every
@@ -9087,8 +9087,15 @@ <h3>Basic Graph Patterns</h3>
90879087
<p>If μ<sub>1</sub> and μ<sub>2</sub> are compatible then μ<sub>1</sub> ∪ μ<sub>2</sub> is
90889088
also a mapping. Write merge(μ<sub>1</sub>, μ<sub>2</sub>) for μ<sub>1</sub> ∪
90899089
μ<sub>2</sub></p>
9090-
<p>Write card[Ω](μ) for the cardinality of solution mapping μ in a multiset of mappings
9091-
Ω.</p>
9090+
<div class="defn">
9091+
<p><b>Definition: <span id="defn_Multiplicity">Multiplicity</span></b></p>
9092+
<p>Given a multiset&nbsp;<var>Ω</var> of solution mappings and a solution
9093+
mapping&nbsp;<var>μ</var>, we write <var>multiplicity</var>(<var>μ</var>&nbsp;|&nbsp;<var>Ω</var>)
9094+
to denote the number of times <var>μ</var> appears in <var>Ω</var>.</p>
9095+
<p>Similarly, given a solution sequence&nbsp;<var>Ψ</var> and a solution
9096+
mapping&nbsp;<var>μ</var>, we write <var>multiplicity</var>(<var>μ</var>&nbsp;|&nbsp;<var>Ψ</var>)
9097+
to denote the number of times <var>μ</var> appears in <var>Ψ</var>.</p>
9098+
</div>
90929099
<section id="BGPsparql">
90939100
<h4>SPARQL Basic Graph Pattern Matching</h4>
90949101
<p>A basic graph pattern is matched against the active graph for that part of the query.
@@ -9111,8 +9118,9 @@ <h4>SPARQL Basic Graph Pattern Matching</h4>
91119118
<p>μ is a <b>solution</b> for BGP from G when there is a pattern instance mapping P such
91129119
that P(BGP) is a subgraph of G and μ is the restriction of P to the query variables in
91139120
BGP.</p>
9114-
<p>card[Ω](μ) = card[Ω](number of distinct RDF instance mappings, σ, such that P = μ(σ)
9115-
is a pattern instance mapping and P(BGP) is a subgraph of G).</p>
9121+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Ω ) =
9122+
number of distinct RDF instance mappings, σ, such that P = μ(σ)
9123+
is a pattern instance mapping and P(BGP) is a subgraph of G.</p>
91169124
</div>
91179125
<p>If a basic graph pattern is the empty set, then the solution is Ω<sub>0</sub>.</p>
91189126
</section>
@@ -9380,7 +9388,8 @@ <h3>SPARQL Algebra</h3>
93809388
<p>Let Ω be a multiset of solution mappings and expr be an expression. We define:</p>
93819389
<p>Filter(expr, Ω) = { μ | μ in Ω and expr(μ) is an expression that has an
93829390
effective boolean value of true }</p>
9383-
<p>card[Filter(expr, Ω)](μ) = card[Ω](μ)</p>
9391+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Filter(expr, Ω) )
9392+
= <a href="#defn_Multiplicity">multiplicity</a>( μ | Ω )</p>
93849393
<blockquote>
93859394
Note that evaluating an <code>exists(pattern)</code> expression uses the dataset and
93869395
active graph, D(G). See the <a href="#defn_evalFilter">evaluation of filter</a>.
@@ -9392,24 +9401,25 @@ <h3>SPARQL Algebra</h3>
93929401
<p>Join(Ω<sub>1</sub>, Ω<sub>2</sub>) = { merge(μ<sub>1</sub>, μ<sub>2</sub>) |
93939402
μ<sub>1</sub> in Ω<sub>1</sub> and μ<sub>2</sub> in Ω<sub>2</sub>, and μ<sub>1</sub> and
93949403
μ<sub>2</sub> are compatible }</p>
9395-
<p>card[Join(Ω<sub>1</sub>, Ω<sub>2</sub>)](μ) =<br>
9404+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Join(Ω<sub>1</sub>, Ω<sub>2</sub>) ) =<br>
93969405
&nbsp;&nbsp;&nbsp; for each merge(μ<sub>1</sub>, μ<sub>2</sub>), μ<sub>1</sub> in
93979406
Ω<sub>1</sub> and μ<sub>2</sub> in Ω<sub>2</sub> such that μ = merge(μ<sub>1</sub>,
93989407
μ<sub>2</sub>),<br>
93999408
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum over (μ<sub>1</sub>, μ<sub>2</sub>),
9400-
card[Ω<sub>1</sub>](μ<sub>1</sub>)*card[Ω<sub>2</sub>](μ<sub>2</sub>)</p>
9409+
<a href="#defn_Multiplicity">multiplicity</a>( μ<sub>1</sub> | Ω<sub>1</sub> ) * <a href="#defn_Multiplicity">multiplicity</a>( μ<sub>2</sub> | Ω<sub>2</sub> )</p>
94019410
</div>
94029411
<p>It is possible that a solution mapping μ in a Join can arise in different solution
9403-
mappings, μ<sub>1</sub> and μ<sub>2</sub> in the multisets being joined. The cardinality
9404-
of&nbsp; μ is the sum of the cardinalities from all possibilities.</p>
9412+
mappings, μ<sub>1</sub> and μ<sub>2</sub> in the multisets being joined. The multiplicity
9413+
of&nbsp; μ is the sum of the multiplicities from all possibilities.</p>
94059414
<div class="defn">
94069415
<p><b>Definition: <span id="defn_algDiff">Diff</span></b></p>
94079416
<p>Let Ω<sub>1</sub> and Ω<sub>2</sub> be multisets of solution mappings and expr be an
94089417
expression. We define:</p>
94099418
<p>Diff(Ω<sub>1</sub>, Ω<sub>2</sub>, expr) = { μ | μ in Ω<sub>1</sub> such that ∀ μ′ in
94109419
Ω<sub>2</sub>, either μ and μ′ are not compatible or μ and μ' are compatible and
94119420
expr(merge(μ, μ')) does not have an effective boolean value of true }</p>
9412-
<p>card[Diff(Ω<sub>1</sub>, Ω<sub>2</sub>, expr)](μ) = card[Ω<sub>1</sub>](μ)</p>
9421+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Diff(Ω<sub>1</sub>, Ω<sub>2</sub>, expr) ) =
9422+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ω<sub>1</sub> )</p>
94139423
</div>
94149424
<p>The evaluation of expr(merge(μ, μ')) does not have an effective boolean
94159425
value of true if it evaluates to false or if it raises an error.</p>
@@ -9420,26 +9430,29 @@ <h3>SPARQL Algebra</h3>
94209430
expression. We define:</p>
94219431
<p>LeftJoin(Ω<sub>1</sub>, Ω<sub>2</sub>, expr) = Filter(expr, Join(Ω<sub>1</sub>,
94229432
Ω<sub>2</sub>)) ∪ Diff(Ω<sub>1</sub>, Ω<sub>2</sub>, expr)</p>
9423-
<p>card[LeftJoin(Ω<sub>1</sub>, Ω<sub>2</sub>, expr)](μ) = card[Filter(expr,
9424-
Join(Ω<sub>1</sub>, Ω<sub>2</sub>))](μ) + card[Diff(Ω<sub>1</sub>, Ω<sub>2</sub>,
9425-
expr)](μ)</p>
9433+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | LeftJoin(Ω<sub>1</sub>, Ω<sub>2</sub>, expr) ) =
9434+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Filter(expr,Join(Ω<sub>1</sub>, Ω<sub>2</sub>)) ) +
9435+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Diff(Ω<sub>1</sub>, Ω<sub>2</sub>,
9436+
expr) )</p>
94269437
</div>
94279438

94289439
<div class="defn">
94299440
<p><b>Definition: <span id="defn_algUnion">Union</span></b></p>
94309441
<p>Let Ω<sub>1</sub> and Ω<sub>2</sub> be multisets of solution mappings. We define:</p>
94319442
<p>Union(Ω<sub>1</sub>, Ω<sub>2</sub>) = { μ | μ in Ω<sub>1</sub> or μ in Ω<sub>2</sub>
94329443
}</p>
9433-
<p>card[Union(Ω<sub>1</sub>, Ω<sub>2</sub>)](μ) = card[Ω<sub>1</sub>](μ) +
9434-
card[Ω<sub>2</sub>](μ)</p>
9444+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Union(Ω<sub>1</sub>, Ω<sub>2</sub>) ) =
9445+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ω<sub>1</sub> ) +
9446+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ω<sub>2</sub> )</p>
94359447
</div>
94369448
<div class="defn">
94379449
<p><b>Definition: <span id="defn_algMinus">Minus</span></b></p>
94389450
<p>Let Ω<sub>1</sub> and Ω<sub>2</sub> be multisets of solution mappings. We define:</p>
94399451
<p>Minus(Ω<sub>1</sub>, Ω<sub>2</sub>) = { μ | μ in Ω<sub>1</sub> . ∀ μ' in
94409452
Ω<sub>2</sub>, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint
94419453
}</p>
9442-
<p>card[Minus(Ω<sub>1</sub>, Ω<sub>2</sub>)](μ) = card[Ω<sub>1</sub>](μ)</p>
9454+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Minus(Ω<sub>1</sub>, Ω<sub>2</sub>) ) =
9455+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ω<sub>1</sub> )</p>
94439456
</div>
94449457
<p>The additional restriction on dom(μ) and dom(μ') is added because otherwise if there is
94459458
a solution mapping in Ω<sub>2</sub> that has no variables in common with the solution
@@ -9457,45 +9470,55 @@ <h3>SPARQL Algebra</h3>
94579470
<p>Extend(Ω, var, expr) = { Extend(μ, var, expr) | μ in Ω }</p>
94589471
</div>
94599472
<p>Write [ x | C ] for a sequence of elements where C is a condition on x.</p>
9460-
<p>Write card[L](x) to be the cardinality of x in L.</p>
94619473
<div class="defn">
94629474
<p><b>Definition: <span id="defn_algToList">ToList</span></b></p>
94639475
<p>Let Ω be a multiset of solution mappings. We define:</p>
9464-
<p>ToList(Ω) = a sequence of mappings μ in Ω in any order, with card[Ω](μ) occurrences of
9476+
<p>ToList(Ω) = a sequence of mappings μ in Ω in any order, with
9477+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ω ) occurrences of
94659478
μ</p>
9466-
<p>card[ToList(Ω)](μ) = card[Ω](μ)</p>
9479+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | ToList(Ω) ) =
9480+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ω )</p>
94679481
</div>
94689482
<div class="defn">
94699483
<p><b>Definition: <span id="defn_algOrdered">OrderBy</span></b></p>
94709484
<p>Let Ψ be a sequence of solution mappings. We define:</p>
94719485
<div id="defn_algOrderBy">
94729486
OrderBy
94739487
</div>(Ψ, condition) = [ μ | μ in Ψ and the sequence satisfies the ordering condition]
9474-
<p>card[OrderBy(Ψ, condition)](μ) = card[Ψ](μ)</p>
9488+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | OrderBy(Ψ, condition) ) =
9489+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ψ )</p>
94759490
</div>
94769491
<div class="defn">
94779492
<p><b>Definition: <span id="defn_algProjection">Project</span></b></p>
94789493
<p>Let Ψ be a sequence of solution mappings and PV a set of variables.</p>
94799494
<p>For mapping μ, write Proj(μ, PV) to be the restriction of μ to variables in PV.</p>
94809495
<p>Project(Ψ, PV) = [ Proj(μ, PV) | μ in Ψ ]</p>
9481-
<p>card[Project(Ψ, PV)](μ) = sum(card[Ψ](ν) | ν in Ψ such that ν = Proj(μ, PV))</p>
9496+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Project(Ψ, PV) ) =
9497+
sum( <a href="#defn_Multiplicity">multiplicity</a>( ν | Ψ ) | ν in Ψ such that ν = Proj(μ, PV))</p>
94829498
<p>The order of Project(Ψ, PV) must preserve any ordering given by OrderBy.</p>
94839499
</div>
94849500
<div class="defn">
94859501
<p><b>Definition: <span id="defn_algDistinct">Distinct</span></b></p>
94869502
<p>Let Ψ be a sequence of solution mappings. We define:</p>
94879503
<p>Distinct(Ψ) = [ μ | μ in Ψ ]</p>
9488-
<p>card[Distinct(Ψ)](μ) = 1</p>
9504+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Distinct(Ψ) ) = 1
9505+
for every μ ∈ Distinct(Ψ)</p>
9506+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Distinct(Ψ) ) = 0
9507+
for every μ ∉ Distinct(Ψ)</p>
94899508
<p>The order of Distinct(Ψ) must preserve any ordering given by OrderBy.</p>
94909509
</div>
94919510
<div class="defn">
94929511
<p><b>Definition: <span id="defn_algReduced">Reduced</span></b></p>
94939512
<p>Let Ψ be a sequence of solution mappings. We define:</p>
94949513
<p>Reduced(Ψ) = [ μ | μ in Ψ ]</p>
9495-
<p>card[Reduced(Ψ)](μ) is between 1 and card[Ψ](μ)</p>
9514+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Reduced(Ψ) ) is
9515+
between 1 and <a href="#defn_Multiplicity">multiplicity</a>( μ | Ψ )
9516+
for every μ ∈ Reduced(Ψ)</p>
9517+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | Reduced(Ψ) ) = 0
9518+
for every μ ∉ Reduced(Ψ)</p>
94969519
<p>The order of Reduced(Ψ) must preserve any ordering given by OrderBy.</p>
94979520
</div>
9498-
<p>The Reduced solution sequence modifier does not guarantee a defined cardinality.</p>
9521+
<p>The Reduced solution sequence modifier does not guarantee a defined multiplicity.</p>
94999522
<div class="defn">
95009523
<p><b>Definition: <span id="defn_algSlice">Slice</span></b></p>
95019524
<p>Let Ψ be a sequence of solution mappings. We define:</p>
@@ -9507,15 +9530,16 @@ <h3>SPARQL Algebra</h3>
95079530
<p><b>Definition: <span id="defn_algToMultiSet">ToMultiSet</span></b></p>
95089531
<p>Let Ψ be a solution sequence. We define:</p>
95099532
<p>ToMultiSet(Ψ) = { μ | μ in Ψ }</p>
9510-
<p>card[ToMultiSet(Ψ)](μ) = card[Ψ](μ)</p>
9533+
<p><a href="#defn_Multiplicity">multiplicity</a>( μ | ToMultiSet(Ψ) ) =
9534+
<a href="#defn_Multiplicity">multiplicity</a>( μ | Ψ )</p>
95119535
</div>
95129536
<p>ListEval is a function which is used to evaluate a list of expressions against a
95139537
solution and return a list of the resulting values.</p>
95149538
<div class="defn">
95159539
<div id="defn_algToMultiset">
95169540
<b>Definition: ToMultiset</b>
95179541
</div>
9518-
<p>ToMultiset turns a sequence into a multiset with the same elements and cardinality as
9542+
<p>ToMultiset turns a sequence into a multiset with the same elements and multiplicities as
95199543
the sequence. The order of the sequence has no effect on the resulting multiset, and
95209544
duplicates are preserved.</p>
95219545
</div>
@@ -9935,8 +9959,8 @@ <h3>Evaluation Semantics</h3>
99359959
the result is R
99369960
</pre>
99379961
</div>
9938-
<p>The evaluation of graph uses the SPARQL algebra union operator. The cardinality of a
9939-
solution mapping is the sum of the cardinalities of that solution mapping in each join
9962+
<p>The evaluation of graph uses the SPARQL algebra union operator. The multiplicity of a
9963+
solution mapping is the sum of the multiplicities of that solution mapping in each join
99409964
operation.</p>
99419965
<div class="defn">
99429966
<div id="defn_evalGroup">

0 commit comments

Comments
 (0)