xquery version "3.0"; (: Processing Requests that are send in the BioCASE Protocol :) import module namespace biocase-lib = "http://exist-db.org/xquery/rebind/biocase-lib" at "biocase_lib.xql"; import module namespace biocase-settings = "http://exist-db.org/xquery/rebind/biocase-settings" at "biocase_settings.xql"; declare default element namespace "http://www.tdwg.org/schemas/abcd/2.06"; declare namespace biocase = "http://www.biocase.org/schemas/protocol/1.3"; let $needle := "Tos_" let $haystack := "Tost" let $tokens := tokenize($needle, "[*%]") let $return := biocase-lib:looped-like($needle, $haystack) (: :) let $tokens2 := for $token in $tokens return {$token} let $subtokens := tokenize($tokens[1], "_") let $matched-position := biocase-lib:generate-underscore-token-candiates($haystack, $subtokens) let $result1 := if(exists($matched-position) and $matched-position eq 1)then(true())else(false()) let $col := collection('/db/test/abcd') let $elements := $col/DataSets/DataSet/Units/Unit/Identifications/Identification/Result/TaxonIdentified/ScientificName/FullScientificNameString let $query := biocase-lib:like('Marmota*marmota',('Marmota marmota','Cosmarium polymorphum')) let $query := biocase-lib:looped-like('Marmot* m_r*ot_','Marmota marmota') (: let $positions := biocase-lib:index-of-string($haystack,$subtokens[1]) let $substrings := for $pos in $positions return substring($haystack,$pos+1) let $result := biocase-lib:generate-underscore-token-candiates($haystack, $subtokens) let $final := if(exists($result))then($result+1)else(-20) :) let $needle := "M*o_* m_r*mot_" let $haystack := "a margsghsr" let $token := " m_r_s_h" let $subtokens := tokenize($token, "_") let $positions := biocase-lib:index-of-string($haystack,$subtokens[1]) let $substrings := for $pos in $positions return substring($haystack,$pos+string-length($subtokens[1])) let $results := biocase-lib:process-underscore-token-candiates($substrings, $positions, $subtokens[position() = 2 to last()]) let $result := if(count($results) ge 1)then($results[1])else() return { "'" || $query || "' - '" || count($results) || "' ('" || string-join($substrings,"';'") || "')" || "' ('" || string-join($subtokens,"';'") || "')" || substring("house",1)}