Hi,
To insert the third value into each array I think you want
let $result := $idf ! array:append(., math:log($count div .(2) ))
This works!
Martin and Graydon, thanks for the help and the explanation.
Ben
import module namespace tidyTM = 'http://www.be-logical.nl';
declare function local:step_one($nodes as node()*) as array(*)* { let $text := for $node in $nodes return $node/text() => tokenize() => distinct-values() let $idf := $text => tidyTM:wordCount_arr() return $idf };
declare function local:wordFreq_idf($nodes as node()*) as array(*) { let $count := count($nodes) let $idf := local:step_one($nodes) let $result := $idf ! array:append(., math:log($count div .(2) )) return $result };
let $nodes := collection('IncidentRemarks/Incidenten-180101-190630.csv')/csv/record/INC_RM let $Stoppers := doc('TextMining/Stopwoorden.txt')/text/line/text()
return local:wordFreq_idf( tidyTM:remove_Stopwords($nodes, "Stp", $Stoppers))
--------------
declare function tidyTM:wordCount_arr( $Words as xs:string*) as array(*)* { for $w in $Words let $f := $w group by $f order by count($w) descending return ([$f, count($w)]) } ;
-----------
["probleem", 703, 9.362885817944681e-1] ["opgelost.", 248, 1.9782167274401508e0] ...