I’m working on some functions that can be useful for a concordance. Right now, that’s a function to give me the frequency of each word in a text.
I’ve successfully defined it as follows:
123456789101112131415 function_decl 'count-words', %{f:histogram(f:split(f:normalize-space(f:keep(f:lower-case($1),('lower')))," ")/*)}, {'f' => FAB_NS}
This allows functions to be written in terms of previously defined functions, using all of the expressiveness of the Fabulator expression language.
For example, if I defined the XML prefix ‘c’ to correspond to the namespace in which the ‘count-words’ function is defined, then I could run the following expression:
1 let $i := c:count-words("This allows functions to be written in terms of previously defined functions, using all of the expressiveness of the Fabulator expression language.")
And then ‘$i/of’ would equal 3 because the word ‘of’ appears three times.