11xquery version "4.0" ;
22
3+
4+ (:~
5+ : Module providing utility functions for DoTS.
6+ : These functions facilitate the retrieval of TEI documents,
7+ : metadata, paths, and identifiers from a BaseX database or import folder.
8+ : @version 1
9+ : @date 2025-06-30
10+ : @author École nationale des chartes - Philippe Pons
11+ :)
12+
313module namespace utils_dots = "utils_dots" ;
414
515import module namespace G = "globals" ;
616
717declare namespace dots = "https://github.com/chartes/dots/" ;
818declare namespace tei = "http://www.tei-c.org/ns/1.0" ;
919
20+ (:~
21+ : This functions returns the DTS project identifier (dtsResourceId) for the root collection in the resources register of the given database.
22+ : @param $dbName the name of the BaseX database
23+ : @return the project identifier (dtsResourceId)
24+ :)
1025declare function utils_dots:getIdProject ($dbName as xs:string) {
1126 normalize-space (db:get ($dbName, $G:resourcesRegister)//dots:collection[not (@parentIds)]/@dtsResourceId)
1227};
@@ -19,13 +34,24 @@ declare function utils_dots:getDbName($resourceId as xs:string) {
1934 normalize-space (db:get ($G:dots)//dots:member/node ()[@dtsResourceId = $resourceId]/@dbName)
2035};
2136
37+ (:~
38+ : This function retrieves a TEI document from the database using its xml:id.
39+ : @param $dbName the name of the database
40+ : @param $resourceId the document identifier
41+ : @return the TEI element
42+ :)
2243declare function utils_dots:getDocument ($dbName as xs:string, $resourceId as xs:string) {
2344 if (db:get ($dbName)/tei:TEI[@xml:id = $resourceId])
2445 then db:get ($dbName)/tei:TEI[@xml:id = $resourceId]
2546 else
2647 db:get ($dbName)/node () ! db:path (.)[ends-with (., $resourceId)]
2748};
2849
50+ (:~
51+ : This function retrieves the document identifier (xml:id) from a file path.
52+ : @param $docPath the path to the document file
53+ : @return the resource ID (xml:id or filename)
54+ :)
2955declare function utils_dots:findDocId ($docPath) {
3056 let $document := utils_dots:findDocInFolder ($docPath)
3157 let $resourceId := $document/tei:TEI/@xml:id
@@ -44,6 +70,12 @@ declare function utils_dots:findDocInFolder($docPath) {
4470 doc ($docPath)
4571};
4672
73+ (:~
74+ : This function finds the path of a document in the database based on its identifier.
75+ : @param $dbName the name of the database
76+ : @param $resourceId the document identifier
77+ : @return the database path to the document
78+ :)
4779declare function utils_dots:findPath ($dbName as xs:string, $resourceId as xs:string) {
4880 head ((
4981 db:get ($dbName)/*:TEI[@xml:id = $resourceId] ! db:path (.)
@@ -53,7 +85,7 @@ declare function utils_dots:findPath($dbName as xs:string, $resourceId as xs:str
5385};
5486
5587(:~
56- : Retrieves the document with the specified id.
88+ : This function retrieves the document with the specified id.
5789 : @param $dbName name of database
5890 : @param $resourceId resource ID
5991 : @param $strip strip processing instructions (by default true)
@@ -101,20 +133,38 @@ declare function utils_dots:getDocInRegister($dbName as xs:string, $resourceId a
101133 db:get ($dbName, $G:resourcesRegister)//dots:member/node ()[@dtsResourceId = $resourceId]
102134};
103135
136+ (:~
137+ : This function extracts all parent identifiers from the @parentIds attribute of a <document> element.
138+ : @param $dbName the name of the database
139+ : @param $docInRegister the <dots:document> element
140+ : @return a sequence of parent identifiers
141+ :)
104142declare function utils_dots:getParentIds ($dbName as xs:string, $docInRegister as element (dots:document )) {
105143 for $parentId in tokenize ($docInRegister/@parentIds, " " )
106144 return
107145 $parentId
108146};
109147
148+ (:~
149+ : This function retrieves the root identifier of the DTS Collection endpoint.
150+ : @return the root identifier as a string
151+ :)
110152declare function utils_dots:getRootId () {
111153 normalize-space (db:get ($G:dots)/dots:metadataMap/dots:root/dots:id)
112154};
113155
156+ (:~
157+ : This function retrieves the root title of the DTS Collection endpoint.
158+ : @return the root title as a string
159+ :)
114160declare function utils_dots:getRootTitle () {
115161 normalize-space (db:get ($G:dots)/dots:metadataMap/dots:root/dots:title)
116162};
117163
164+ (:~
165+ : Retrieves the root description of the DTS Collection endpoint.
166+ : @return the root description as a string
167+ :)
118168declare function utils_dots:getRootDescription () {
119169 let $desc := db:get ($G:dots)/dots:metadataMap/dots:root/dots:description
120170 return
0 commit comments