xquery version "3.1";

module namespace ls="http://ahiqar.uni-goettingen.de/ns/annotations/line-segmentation";
declare namespace tei="http://www.tei-c.org/ns/1.0";

declare function ls:get-annotations($teixml-uri as xs:string, $page as xs:string, $fragments as node()+)
as item()* {
    for $num in 1 to count($fragments[@n eq $page]//tei:ab)
    let $iri := "https://wapcas.ahiqar.d.sub.uni-goettingen.de/20260629-04/" || $teixml-uri || "-" || $page || "-" || $num
    let $json :=  try { json-doc($iri) } catch * { () }
    let $log := if (exists($json)) then () else util:log-system-out("Could not get a line-segmentation for " || $iri)
    return
        $json
};
