String Functions
This module contains functions for string operations and computations.
Removed: string:tab
, string:nl
and string:cr
have been removed in favor of fn:char.
All functions and errors in this module and errors are assigned to the http://basex.org/modules/string
namespace, which is statically bound to the string
prefix.
Signature | string:levenshtein(
$string1 as xs:string,
$string2 as xs:string
) as xs:double |
---|
Summary | Computes the Damerau-Levenshtein Distance for $string1 and $string2 and returns a normalized double value (0 – 1). The returned value is computed as follows:
- 1 – distance / max(lengths of strings)
- 1 is returned if the strings are equal; 0 is returned if the strings are too different.
|
---|
Errors | bounds | The specified string exceeds the maximum supported length. |
|
---|
Examples | string:levenshtein("flower", "flowers") Result: 0.8571428571428571e0
let $norm := ft:normalize(?, { 'stemming': true() })
return string:levenshtein($norm("HOUSES"), $norm("house"))
1 is returned after the input has been normalized (words are stemmed, converted to lower case, and diacritics are removed). |
---|
Added: New function.
Signature | string:jaro-winkler(
$string1 as xs:string,
$string2 as xs:string
) as xs:double |
---|
Summary | Computes the Jaro-Winkler Distance for $string1 and $string2 and returns a double value (0 – 1). 1 is returned if the strings are equal; 0 is returned if the strings are too different.
|
---|
Examples | string:jaro-winkler("flower", "flowers") Result: 0.98e0
let $norm := ft:normalize(?, { 'stemming': true() })
return string:jaro-winkler($norm("HOUSES"), $norm("house"))
1 is returned after the input has been normalized (words are stemmed, converted to lower case, and diacritics are removed). |
---|
Signature | string:soundex(
$string as xs:string
) as xs:string |
---|
Summary | Computes the Soundex value for the specified string. The algorithm can be used to find and index English words with similar pronouncation. |
---|
Examples | string:soundex("Michael") Result: 'M240'
string:soundex("OBrien") = string:soundex("O'Brien") Result: true() |
---|
Signature | string:cologne-phonetic(
$string as xs:string
) as xs:string |
---|
Summary | Computes the Kölner Phonetik value for the specified string. Similar to Soundex, the algorithm is used to find similarly pronounced words, but for the German language. As the first returned digit can be 0 , the value is returned as string. |
---|
Examples | string:cologne-phonetic("Michael") Result: '645'
every $s in ("Mayr", "Maier", "Meier")
satisfies string:cologne-phonetic($s) = "67" Result: true() |
---|
Signature | string:format(
$pattern as xs:string,
$values... as item()
) as xs:string |
---|
Summary | Returns a formatted string. The remaining $values are incorported into the $pattern , according to Java’s printf syntax. |
---|
Errors | format | The specified format is invalid. |
|
---|
Examples | string:format("%b", true()) Result: 'true'
string:format("%06d", 256) Result: '000256'
string:format("%e", 1234.5678) Result: '1.234568e+03' |
---|
Code | Description |
---|
bounds | The specified string exceeds the maximum supported length. |
format | The specified format is invalid. |
Version 11.0Version 10.0- Updated: Renamed from Strings Module to String Module. The namespace URI has been updated as well.
- Updated:
string:format
, string:cr
, string:nl
and string:tab
adopted from the obsolete Output Module.
Version 8.3- Added: New module added. Functions were adopted from the obsolete Utility and Output Modules.
⚡Generated with XQuery