Re: [basex-talk] Re: Sequence comparison
Hi Martin, What I was looking for is a “quick way” to get a comparison such that an item (when it is repeated more than once) is returned only as many times as it appears in both sequences. For example, in for $a in (1,2,3,5,3,3) where $a = (1,3,2,3, 2) group by $k := $a return <c>{$a}</c> you get <c>1</c> <c>2</c> <c>3 3 3</c> with three 3 even if in the second sequence you have two 3.
On 26. Nov 2020, at 08:30, Martin Honnen <martin.honnen@gmx.de> wrote:
Am 26.11.2020 um 07:14 schrieb Martin Honnen:
My bad, use group by $k := $a return <c>{$a}</c>
To describe it clearer, the whole FLOWR should be
for $a in (1,2,3,5) where $a = (1,3,2,3) group by $k := $a return <c>{$a}</c>
On Fri, Nov 27, 2020 at 04:38:42AM +0100, Giuseppe G. A. Celano scripsit:
What I was looking for is a “quick way” to get a comparison such that an item (when it is repeated more than once) is returned only as many times as it appears in both sequences.
I don't know if it's quick, and I don't know if I understand the requirements, but resorting to maps seems to work: let $occursMap as function(*) := function($in as xs:integer+) { map:merge( for $item in $in let $key as xs:integer := $item group by $key (: where $item[2] :) return map:entry($key,$item => count()) ) } let $a as xs:integer+ := (1,2,3,5,3,3) let $k as xs:integer+ := (1,3,2,3,2) let $aMap as map(xs:integer,xs:integer) := $occursMap($a) let $aKeys as xs:integer+ := $aMap => map:keys() let $kMap as map(xs:integer,xs:integer) := $occursMap($k) let $kKeys as xs:integer+ := $kMap => map:keys() return for $each in $aKeys[. = $kKeys] return (1 to min(($aMap($each),$kMap($each)))) ! $each If you need to restrict this to "and they have to occur multiple times in the sequence" as well as "occurs in both sequences", uncomment "where $item[2]". -- Graydon Saunders | graydonish@gmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")
participants (4)
-
Giuseppe G. A. Celano -
Graydon -
Martin Honnen -
Martin Honnen