Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

150bis revised proposal for fn:ranks #1062

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ebbd656
fn:ranks
dnovatchev Feb 17, 2024
6d2f47a
fixed the result of Example 2
dnovatchev Feb 17, 2024
4a9ffc7
Added Example 3 - World Cup Group C final standings
dnovatchev Feb 18, 2024
5515804
fixed the definition of Example 3 (3 points for a win)
dnovatchev Feb 18, 2024
2d991ca
Example - rplaced a period with a comma
dnovatchev Feb 18, 2024
1db1358
fix in Example 3 removed the $ sign at the start of ranks.
dnovatchev Feb 18, 2024
55ed089
Reflected Michael Kay's comments
dnovatchev Feb 19, 2024
87f9d3f
Expanded the Summary
dnovatchev Feb 19, 2024
7d61d7c
Reflected Michael Kay's comments and added a second collation and a note
dnovatchev Feb 19, 2024
8756a29
Removed the word singleton
dnovatchev Feb 19, 2024
a574c57
Remuved a comma from the commented rreturn
dnovatchev Feb 19, 2024
668767b
Added Example 4 - Synonyms translated to the same Swedish word form a…
dnovatchev Feb 20, 2024
1450e5d
Fixed Example 4
dnovatchev Feb 20, 2024
393f9a6
Expanded the rules with a non-formal definition
dnovatchev Feb 20, 2024
69ceb1c
Refined the rules
dnovatchev Feb 20, 2024
23b7f06
Now using fn:compare to form each array-result
dnovatchev Feb 20, 2024
6fa30c3
Refined the Notes
dnovatchev Feb 20, 2024
c651d7e
compare() is now calles with $collation-key
dnovatchev Feb 20, 2024
1f61d49
Made more precise formal definition. Added 2 more examples
dnovatchev Feb 21, 2024
1f61de8
Eliminated incorrect use of $colation-input. Made the rules more prec…
dnovatchev Feb 21, 2024
c0f18da
Minot lexical-spatial adjustments
dnovatchev Feb 22, 2024
d126ff0
Minor lexical-spatial adjustments - 2
dnovatchev Feb 22, 2024
66513d9
Formal definition refactoring
dnovatchev Feb 22, 2024
7c7eb25
Merge branch 'qt4cg:master' into master
dnovatchev Feb 28, 2024
3b7fbab
150 Revised proposal for fn:ranks
michaelhkay Mar 5, 2024
9ee4c59
Fix typo in example
michaelhkay Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 155 additions & 1 deletion specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19783,7 +19783,7 @@ else let $rel = op:simple-compare(head($a), head($b), $C)
return if ($rel eq 0)
then op:lexicographic-compare(tail($a), tail($b), $C)
else $rel</eg></item>
<item><p>Here <code>op:simple-compare($k1, $k2)</code> is defined as follows:</p>
<item><p>Here <code>op:simple-compare($k1, $k2, $C)</code> is defined as follows:</p>
<eg>if ($k1 instance of union(xs:string, xs:anyURI, xs:untypedAtomic)
and $k2 instance of union(xs:string, xs:anyURI, xs:untypedAtomic))
then compare($k1, $k2, $C)
Expand Down Expand Up @@ -30215,6 +30215,160 @@ path with an explicit <code>file:</code> scheme.</p>
<fos:version version="4.0">Proposed for 4.0</fos:version>
</fos:history>
</fos:function>

<fos:function name="ranks" prefix="fn">
<fos:signatures>
<fos:proto name="ranks" return-type="array(item())*">
<fos:arg name="input" type="item()*" usage="navigation"/>
<fos:arg name="collations" type="xs:string*" usage="absorption" default="fn:default-collation()"/>
<fos:arg name="keys" type="(function(item()) as xs:anyAtomicType*)*" usage="inspection" default="fn:data#1"/>
<fos:arg name="orders" type="enum('ascending', 'descending')*" usage="absorption" default="'ascending'"/>
</fos:proto>
</fos:signatures>
<fos:properties>
<fos:property>deterministic</fos:property>
<fos:property>context-independent</fos:property>
<fos:property>focus-independent</fos:property>
</fos:properties>
<fos:summary>
<p>Sorts the items of a supplied sequence based on the value of one or more sort keys,
grouping the results so that items with the same key appear together
as members of the same array, ordered by increasing key value.
</p>
</fos:summary>
<fos:rules>
<p>The effect of the function is equivalent to first sorting the input
sequence by applying the <code>fn:sort</code> function with the same
arguments, and then partitioning the result into a sequence of arrays
so that adjacent items with the same sort key go into the same array.</p>

<p>That is, the result of the function is given by the expression:</p>

<eg>sort($input, $collations, $keys, $orders) =>
partition(split-when := fn($group, $item) {
not(op:same-sort-keys(foot($group),
$item,
$collations,
$keys))})</eg>

<p>where <code>op:same-sort-keys($item1, $item2, $collations, $keys)</code> is a function
that returns true if and only if the first two arguments have pairwise equal sort
key values as defined in the rules of the <code>fn:sort</code> function.</p>

</fos:rules>

<fos:errors>
<p>The errors that may be raised are the same as for <code>fn:sort</code>.</p>
</fos:errors>
<fos:examples>
<fos:example>
<fos:test>
<fos:expression><eg>ranks(("red", "orange", "yellow", "green", "blue", "indigo", "violet"),
(), string-length#1)</eg></fos:expression>
<fos:result>["red"], ["blue"], ["green"], ["orange", "yellow", "indigo", "violet"]</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression><eg>ranks((3, 2, 4), (), fn($n) {$n mod 2})</eg></fos:expression>
<fos:result>[2, 4], [3]</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression><eg>ranks((-2, -1, 0, 1, 2, 3), (), fn($n) {$n * $n})</eg></fos:expression>
<fos:result>[0], [-1, 1], [-2, 2], [3]</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression><eg><![CDATA[
let $group := map {
"Argentina" : (2, 0, 1),
"Poland" : (1, 1, 1),
"Mexico" : (1, 1, 1),
"Saudi Arabia" : (1, 0, 2)
}
return ranks(map:keys($group),
(),
fn($team){3 * $group($team)[1] + $group($team)[2]},
"descending")) ]]></eg>
</fos:expression>
<fos:result>["Argentina"], ["Poland", "Mexico"], ["Saudi Arabia"]</fos:result>
</fos:test>
</fos:example>
<!-- <fos:example>
<fos:test>
<fos:expression><eg><![CDATA[
$toSwedish := map{
"good" : "Bra",
"difficult" : "svår",
"great" : "Bra",
"severe": "svår",
"fine": "Bra"
}
return
ranks(("good", "difficult", "great", "severe", "fine", "good"), ()
fn($word){$toSwedish($word)}, true(), default-collation(),
"http://www.w3.org/2013/collation/UCA?lang=se") ]]></eg>
</fos:expression>
<fos:result>["good","great","fine"], ["difficult","severe"]</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression><eg><![CDATA[
$toSwedish := map{
"good" : "Bra",
"difficult" : "svår",
"great" : "Bra",
"severe": "svår",
"fine": "Bra"
}
return
ranks(("good", "difficult", "great", "severe", "fine", "good"),
fn($word){$toSwedish($word)}, false(), default-collation(),
"http://www.w3.org/2013/collation/UCA?lang=se") ]]></eg>
</fos:expression>
<fos:result>["good","great","fine","good"], ["difficult","severe"]</fos:result>
</fos:test>
</fos:example> -->
<fos:example>
<fos:test>
<fos:expression><eg><![CDATA[
let $decompose := fn($s as xs:string) {
let $chars := characters($s)[. ne ' '],
$frequencies := map:build($chars, value:=fn{1}, combine:=op('+'))
=> map:pairs()
=> sort((), fn{?key})
return string-join($frequencies ! (?key, ?value), '')
}
return
ranks (("apple macintosh", "astronomer",
"angered", "brush", "dictionary",
"dirty room", "editor",
"enraged", "eleven plus two",
"indicatory", "laptop machines",
"redo it", "dormitory", "shrub",
"moon starer", "twelve plus one"),
keys := $decompose ) ]]></eg>
</fos:expression>
<fos:result>["astronomer", "moon starer"],
["apple macintosh", "laptop machines"],
["editor", "redo it"],
["dirty room", "dormitory"],
["eleven plus two", "twelve plus one"],
["dictionary", "indicatory"],
["angered", "enraged"],
["brush", "shrub"]
</fos:result>
</fos:test>
</fos:example>
</fos:examples>
<fos:history>
<fos:version version="4.0">Proposed for 4.0</fos:version>
</fos:history>
</fos:function>

<fos:function name="scan-left" prefix="fn">
<fos:signatures>
Expand Down
4 changes: 4 additions & 0 deletions specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7571,6 +7571,9 @@ return <table>
<div3 id="func-partition" diff="add" at="A">
<head><?function fn:partition?></head>
</div3>
<div3 id="func-ranks" diff="add" at="A">
<head><?function fn:ranks?></head>
</div3>
<div3 id="func-scan-left" diff="add" at="A">
<head><?function fn:scan-left?></head>
</div3>
Expand Down Expand Up @@ -11886,6 +11889,7 @@ ISBN 0 521 77752 6.</bibl>
<item><p><code>fn:parse-QName</code></p></item>
<item><p><code>fn:parse-uri</code></p></item>
<item><p><code>fn:partition</code></p></item>
<item><p><code>fn:ranks</code></p></item>
<item><p><code>fn:replicate</code></p></item>
<item><p><code>fn:scan-left</code></p></item>
<item><p><code>fn:scan-right</code></p></item>
Expand Down
Loading