xquery version "3.0";
(:~
: jsonouput for graphs
:)
declare namespace xslt="http://exist-db.org/xquery/transform";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace xqi="http://xqueryinstitute.org/ns";
declare namespace json="http://www.json.org";
declare option exist:serialize "method=json media-type=text/javascript encoding=UTF-8";
let $timestamp := request:get-parameter("timestamp", ())
return
{
(:
functx:mmddyyyy-to-date($dateString as xs:string?) as xs:date?
:)
(: for $hits in collection('/db/apps/iskkan/data/smj/pl/goldstandard')/spelltestresult/results :)
for $result in collection('/db/apps/iskkan/data')//spelltestresult[./header/timestamp = $timestamp]
let $words := $result/results/word[./original/@status = "error"][./speller/@status = "error"]
let $word-count := count($words)
return
for $dist in 1 to 3
return
Dist {$dist},
{
for $p in 1 to 6
let $hits :=
if ($dist ne 3 and $p ne 6) then
$words[./edit_dist=$dist][./position=$p]
else if ($dist eq 3 and $p eq 6) then
$words[./edit_dist>=$dist][./position>=$p]
else if ($dist eq 3) then
$words[./edit_dist>=$dist][./position=$p]
else
$words[./edit_dist=$dist][./position>=$p]
return
{$p}
{count($hits)}
}
}
(:
let $word-count := count($el)
return
{
for $p in 1 to 6
return
for $dist in 1 to 3
let $hits :=
if ($dist ne 3 and $p ne 6) then
$el[./edit_dist=$dist][./position=$p]
else if ($dist eq 3 and $p eq 6) then
$el[./edit_dist>=$dist][./position>=$p]
else if ($dist eq 3) then
$el[./edit_dist>=$dist][./position=$p]
else
$el[./edit_dist=$dist][./position>=$p]
return
{round-half-to-even((count($hits) div $word-count) * 100, 2)}
}
:)