2,258 bytes added
, 17:45, 16 September 2015
This [[Module Library|XQuery Module]] contains functions for string computations.
=Conventions=
All functions in this module and errors are assigned to the <code><nowiki>http://basex.org/modules/strings</nowiki></code> namespace, which is statically bound to the {{Code|strings}} prefix.<br/>
=Functions=
==strings:levenshtein==
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|strings:levenshtein|$string1 as xs:string, $string2 as xs:string|xs:double}}<br/>
|-
| '''Summary'''
|Computes the [https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance Damerau-Levenshtein Distance] for two strings and returns a double value ({{Code|0.0}} - {{Code|1.0}}), which represents the distance. The value is computed as follows:<br/>
* <code>1.0 - distance / max(length of strings)</code>
* <code>1.0</code> is returned if the strings are equal; <code>0.0</code> is returned if the strings are too different.
|-
| '''Examples'''
|{{Code|strings:levenshtein("cafe", "coffee")}} returns {{Code|0.33}}.
|}
==strings:soundex==
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|strings:soundex|$string as xs:string|xs:string}}<br/>
|-
| '''Summary'''
|Computes the [https://en.wikipedia.org/wiki/Soundex Soundex] value for the specified string. The algorithm can be used to find and index English words with similar pronouncation.
|-
| '''Examples'''
|
* <code>strings:soundex("Michael")</code> returns {{Code|M240}}.
* <code>strings:soundex("OBrien") = strings:soundex("O'Brien")</code> returns {{Code|true}}.
|}
==strings:cologne-phonetic==
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|strings:cologne-phonetic|$string as xs:string|xs:string}}<br/>
|-
| '''Summary'''
|Computes the [https://de.wikipedia.org/wiki/K%C3%B6lner_Phonetik Kölner Phonetik] value for the specified string. The algorithm was published by Hans Joachim Postel in 1969. Similar to Soundex, it is used to find similarly pronounced words in the German language.
|-
| '''Examples'''
|
* <code>strings:cologne-phonetic("Michael")</code> returns {{Code|645}}.
* <code>strings:cologne-phonetic("Mayr") = strings:cologne-phonetic("Meier")</code> returns {{Code|67}}.
|}
=Changelog=
The Module was introduced with Version 8.3.
[[Category:XQuery]]