Skip to content

Commit

Permalink
get range of citeable items for sp and stage on level 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ingoboerner committed Dec 11, 2024
1 parent e021d08 commit 234e2a5
Showing 1 changed file with 67 additions and 4 deletions.
71 changes: 67 additions & 4 deletions modules/dts.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,15 @@ declare function local:get-fragment-range($tei as element(tei:TEI), $start as xs
let $sp-pos := xs:int(replace(replace(tokenize($start, "/")[3], "sp\[",""),"\]",""))
return
( $tei//tei:body/tei:div[$div-pos]/tei:sp[$sp-pos] , $tei//tei:body/tei:div[$div-pos]/tei:sp[$sp-pos]/following-sibling::node() )

(: stage on level 3 - xpath-ish :)
(: body/div[x]/stage[y] :)
else if ( matches($start, "^body/div\[\d+\]/stage\[\d+\]$") ) then
let $div-pos := xs:int(replace(replace(tokenize($start,"/")[2],"div\[",""),"\]",""))
let $stage-pos := xs:int(replace(replace(tokenize($start, "/")[3], "stage\[",""),"\]",""))
return
( $tei//tei:body/tei:div[$div-pos]/tei:stage[$stage-pos] , $tei//tei:body/tei:div[$div-pos]/tei:stage[$stage-pos]/following-sibling::node() )


(: structures on level 4 :)
(: body/act/scene/sp|stage :)
Expand Down Expand Up @@ -1112,12 +1121,20 @@ declare function local:get-fragment-range($tei as element(tei:TEI), $start as xs
$tei//tei:body/tei:div[$div1-pos]/tei:div[$div2-pos]/following-sibling::node()

(: level3: sp in div :)
else if ( matches($start, "^body/div\[\d+\]/sp\[\d+\]$") ) then
let $div-pos := xs:int(replace(replace(tokenize($start,"/")[2],"div\[",""),"\]",""))
let $sp-pos := xs:int(replace(replace(tokenize($start, "/")[3], "sp\[",""),"\]",""))
else if ( matches($end, "^body/div\[\d+\]/sp\[\d+\]$") ) then
let $div-pos := xs:int(replace(replace(tokenize($end,"/")[2],"div\[",""),"\]",""))
let $sp-pos := xs:int(replace(replace(tokenize($end, "/")[3], "sp\[",""),"\]",""))
return
$tei//tei:body/tei:div[$div-pos]/tei:sp[$sp-pos]/following-sibling::node()

(: stage on level 3 - xpath-ish :)
(: body/div[x]/stage[y] :)
else if ( matches($end, "^body/div\[\d+\]/stage\[\d+\]$") ) then
let $div-pos := xs:int(replace(replace(tokenize($end,"/")[2],"div\[",""),"\]",""))
let $stage-pos := xs:int(replace(replace(tokenize($end, "/")[3], "stage\[",""),"\]",""))
return
$tei//tei:body/tei:div[$div-pos]/tei:stage[$stage-pos]/following-sibling::node()


(: level4 structures :)
(: sp on level 4 :)
Expand Down Expand Up @@ -2605,9 +2622,13 @@ declare function local:bordering-citeable-unit-of-range($tei, $ref, $doc-uri) {

(: this works for body structures, e.g. /body/div[2] to /body/div[7] :)
(: somewhere before all is returned there should be a warning if something strange is requested :)
else if (matches($start,"^body/div\[\d+\]$") ) then
else if (matches($start,"^body/div\[\d+\]$") and matches($end,"^body/div\[\d+\]$")) then
local:top_level_members_of_range($tei, $start, $end)

(: this works for http://localhost:8088/api/v1/dts/navigation?resource=http://localhost:8088/id/ger000638&start=body/div[2]/stage[1]&end=body/div[2]/sp[5] :)
else if (matches($start, "^body/div\[\d+\]/(sp|stage)\[\d+\]") ) then
local:sp_stage_level3_members_of_range($tei, $start, $end)

(: this is for debugging.. :)
(: else if ($start eq "body/div[2]/sp[1]") then :)
(: ("error") :) (: top_level_members_of_range does not work for body/div[2]/sp[1] :)
Expand All @@ -2624,6 +2645,48 @@ declare function local:bordering-citeable-unit-of-range($tei, $ref, $doc-uri) {

};

(:~ should handle the case of getting the members of
start=body/div[x]/stage[y]&end=body/div[z]/sp[a]
:)
declare function local:sp_stage_level3_members_of_range($tei as element(tei:TEI), $start as xs:string, $end as xs:string) {
let $doc-id := $tei/@xml:id/string()
let $doc-uri := local:id-to-uri($doc-id)
let $start-object := local:bordering-citeable-unit-of-range($tei, $start, $doc-uri)
let $end-object := local:bordering-citeable-unit-of-range($tei, $end, $doc-uri)

(: not sure if I really need them because I can retrieve the fragment via the alreay implemented funcion – see other :)
let $start-xpath := "$tei//" || replace(replace($start, "/","/tei:"),"body", "tei:body")

let $start-elem := util:eval($start-xpath)

(: get the number of preceding elements sp and stage inside the same parent.
We need this to construct the identifier in the requested range :)
let $preceding-sp-count := count($start-elem/preceding-sibling::tei:sp)
let $preceding-stage-count := count($start-elem/preceding-sibling::tei:stage)

(: use the designated function to get the range :)
let $tei-fragments := local:get-fragment-range($tei, $start, $end)/dts:wrapper/element()
let $parent := local:get-parent-from-ref($start)
let $members := for $item in $tei-fragments
let $identifier :=
if ($item/name() eq "sp") then
(: we need to check how many sp are before this item and add the number of sp before the start of the range :)
let $pos := count($item/preceding-sibling::tei:sp) + $preceding-sp-count + 1
return $parent || "/sp[" || xs:string($pos) || "]"

else if ($item/name() eq "stage") then
let $pos := count($item/preceding-sibling::tei:stage) + $preceding-stage-count + 1
return $parent || "/stage[" || xs:string($pos) || "]"

else "unknown"

return local:citable-unit($identifier, 3, $parent, local:get-cite-type-from-tei-fragment($item), $item, $doc-uri )


return $members

};

(:~ Get the members of a range requested via the navigation endpoint
: this works for http://localhost:8088/api/v1/dts/navigation?resource=http://localhost:8088/id/ger000638&start=body/div[2]&end=body/div[4]
: but would not work for mixed element range, e.g. sp/stage
Expand Down

0 comments on commit 234e2a5

Please sign in to comment.