On Tue, Mar 31, 2020 at 04:21:52PM +0200, Ben Engbers scripsit:
Op 31-03-2020 om 01:18 schreef Graydon:
On Mon, Mar 30, 2020 at 11:16:23PM +0200, Ben Engbers scripsit: [snip]
For "probleem", the idf should be calculated as ln($count/703). Since there are 1780 nodes this would result in 0.929011751. I tried to exten the 'let $idf' line with: => array:for-each(function($idf) {array:append($idf, math:log($count div $idf[2]) )}) which should result in ["probleem", 703, 0.929011751]
but no mather what I do, every time I get this error: [XPTY0004] Cannot promote (array(xs:anyAtomicType))+ to array(*): ([ "probleem", 703 ], [ "opgelost.", 248 ], ...).
The errors says you're trying to feed a sequence of arrays to an array function; maybe you want ! where you have => ?
Upon your remark about feeding a sequence of arrays, I first tried to apply 'for-each' instead of 'array:for-each'. Alas, that didn't help ;-(, the error was still the same.
array:for-each takes a single array and gives you back a new array based on what the anonymous function passed as the second parameter does to each member of the original array.
So you have to make sure you're feeding a single array to it. (and you're not; that's what the error message is telling you, you've got a sequence of arrays on the left of the => operator.)
I then tried to understand what you mean with the '!'. In the book from Priscilla Walmsley, the ! is mentioned as a simple map operator. How is that related to this problem?
=> means "take the thing on the left and substitute it for the first parameter of the function on the right, so
('weasels') => replace('weasels','mustelids') works
('weasels','badgers') => replace('weasels','mustelids') DOES NOT work
This is because a one-item sequence can be treated as the single string value the first parameter of replace() requires, but a greater-then-one-item sequence can't be. (This one gives you "item expected, sequence found" if you try it from the GUI.)
! means "take each item of the sequence on the left and pass it to the thing on the right in turn", so
('weasels','badgers') ! replace(.,'weasels','mustelids') works.
(note that replace() got its first parameter back as the context item dot.)
so if you take
=> array:for-each(function($idf) {array:append($idf,math:log($count div $idf[2]) )})
and replace it with ! array:for-each(.,function($idf) {array:append($idf,math:log($count div $idf[2]) )})
(note the context-item dot!)
you should at least get a different error message.
-- Graydon