(: + | Module: Utility functions for the database at www.risten.no. | | $Id$ | | Functions that are safe with respect to the planned enhancements | to allow multiple terminology collections and dictionaries are marked as such. | | The functions defined thus far are: | | makeTermID($term as xs:string, $pos as xs:string) as xs:string | get-doc($lang as xs:string) as xs:string | newID() as xs:string | dateTime() as xs:string | countRecords() as xs:integer - - multiple db safe | lastChanged() as xs:double - - multiple db safe | | namespace: "http://www.risten.no/shared/util" | + :) module namespace ristenutil="http://www.risten.no/shared/util"; declare namespace util="http://exist-db.org/xquery/util"; (: + | Creates a new term ID based on entry string and POS + :) declare function ristenutil:makeTermID($term as xs:string, $pos as xs:string) as xs:string { let $t := translate($term, ' ', '_') let $id := concat($t, '\', $pos) return $id }; (: + | Returns the full path to a term document in the SD-terms collection, | based on language. + :) declare function ristenutil:get-doc($lang as xs:string) as xs:string { let $doc := concat('/db/ordbase/terms/SD-terms/terms-',$lang,'.xml') return $doc }; (: + | Create an ID filter expression from query term + :) declare function ristenutil:id-filter($record as xs:string) as xs:string { let $t := concat("'", $record, "'") return concat("@id = ", $t) }; (: + | Make a unique numeric ID for termcenter.xml + :) declare function ristenutil:newID() as xs:string { (: Find the highest existing ID, increment, & return the non-decimal part: :) let $r := document('/db/ordbase/terms/SD-terms/termcenter.xml') //entry/@id return substring-before((max($r) + 1), ".") }; (: + | Create a numeric string of the current date&time. The format is: | YYYYMMDDHHMMSS, eg. 20050329123129 | Storing the date as an integer makes it easy to compare dates, sorting etc. + :) declare function ristenutil:dateTime() as xs:string { let $dt:=fn:current-dateTime(), $y:=fn:year-from-dateTime($dt), $m:=fn:month-from-dateTime($dt), $d:=fn:day-from-dateTime($dt), $h:=fn:hours-from-dateTime($dt), $min:=fn:minutes-from-dateTime($dt), $s:=fn:seconds-from-dateTime($dt), $lmon:=fn:string-length($m), $padmon:=fn:concat(fn:string-pad("0",2-$lmon),$m), $lday:=fn:string-length($d), $padday:=fn:concat(fn:string-pad("0",2-$lday),$d), $lhour:=fn:string-length($h), $padhour:=fn:concat(fn:string-pad("0",2-$lhour),$h), $lmin:=fn:string-length($min), $padmin:=fn:concat(fn:string-pad("0",2-$lmin),$min), $lsec:=fn:string-length($s), $padsec:=fn:concat(fn:string-pad("0",2-$lsec),$s) return fn:concat($y,$padmon,$padday,$padhour,$padmin,$padsec) }; (: Count the number for entries in all termcenter.xml files: :) declare function ristenutil:countRecords() as xs:integer { let $r := collection('/db/ordbase')/termCenter/entry return count($r) }; (: Count the number for entries in all termcenter.xml files: :) declare function ristenutil:lastChanged() as xs:double { let $r := collection('/db/ordbase')//@last-update return max($r) };