Skip to content

Instantly share code, notes, and snippets.

@AdamSteffanick
Created February 28, 2020 18:27
Show Gist options
  • Save AdamSteffanick/41bc14bada0c82e416eec746c071a312 to your computer and use it in GitHub Desktop.
Save AdamSteffanick/41bc14bada0c82e416eec746c071a312 to your computer and use it in GitHub Desktop.
xquery version "3.1" encoding "UTF-8";
(:~
: A public function to return the frequency of a string.
:
: @author Adam Steffanick
: @see https://www.steffanick.com/adam/
: @version v1.0.0
:
: @param $parameter is a string
: @return a sequence of record elements
:)
declare %public function local:frequency(
$parameter as xs:string
) as element(record)*
{
let $results := (
for $document in fn:collection("bp-sample")
let $date := (
$document//NumericPubDate/text()
=> substring(1, 4)
)
let $frequency := (
ft:count($document//FullText[.//text() contains text {$parameter} using case insensitive using stemming])
)
group by $date
return (
element record {
element date {
$date
},
element frequency {
fn:sum($frequency)
}
}
)
)
return (
$results
)
};
local:frequency("jury")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment