Created
February 28, 2020 18:27
-
-
Save AdamSteffanick/41bc14bada0c82e416eec746c071a312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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