Difference between revisions of "String Module"
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
=Functions= | =Functions= | ||
− | == | + | ==string:levenshtein== |
{| width='100%' | {| width='100%' | ||
|- | |- | ||
| width='120' | '''Signatures''' | | width='120' | '''Signatures''' | ||
− | |{{Func| | + | |{{Func|string:levenshtein|$string1 as xs:string, $string2 as xs:string|xs:double}}<br/> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
Line 23: | Line 23: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * {{Code| | + | * {{Code|string:levenshtein("flower", "flower")}} returns {{Code|1}} |
− | * {{Code| | + | * {{Code|string:levenshtein("flower", "lewes")}} returns {{Code|0.5}} |
* In the following query, the input is first normalized (words are stemmed, converted to lower case, and diacritics are removed). It returns {{Code|1}}: | * In the following query, the input is first normalized (words are stemmed, converted to lower case, and diacritics are removed). It returns {{Code|1}}: | ||
<syntaxhighlight lang="xquery"> | <syntaxhighlight lang="xquery"> | ||
let $norm := ft:normalize(?, map { 'stemming': true() }) | let $norm := ft:normalize(?, map { 'stemming': true() }) | ||
− | return | + | return string:levenshtein($norm("HOUSES"), $norm("house")) |
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||
− | == | + | ==string:soundex== |
{| width='100%' | {| width='100%' | ||
|- | |- | ||
| width='120' | '''Signatures''' | | width='120' | '''Signatures''' | ||
− | |{{Func| | + | |{{Func|string:soundex|$string as xs:string|xs:string}}<br/> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
Line 44: | Line 44: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * <code> | + | * <code>string:soundex("Michael")</code> returns {{Code|M240}} |
− | * <code> | + | * <code>string:soundex("OBrien") = string:soundex("O'Brien")</code> returns {{Code|true}} |
|} | |} | ||
− | == | + | ==string:cologne-phonetic== |
{| width='100%' | {| width='100%' | ||
|- | |- | ||
| width='120' | '''Signatures''' | | width='120' | '''Signatures''' | ||
− | |{{Func| | + | |{{Func|string:cologne-phonetic|$string as xs:string|xs:string}}<br/> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
Line 60: | Line 60: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * <code> | + | * <code>string:cologne-phonetic("Michael")</code> returns {{Code|645}} |
− | * <code>every $s in ("Mayr", "Maier", "Meier") satisfies | + | * <code>every $s in ("Mayr", "Maier", "Meier") satisfies string:cologne-phonetic($s) = "67"</code> returns {{Code|true}} |
|} | |} | ||
Revision as of 20:05, 18 July 2022
Updated with Version 10: Renamed from Strings Module to String Module. The namespace URI has been updated as well.
This XQuery Module contains functions for string computations.
Contents
Conventions
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.
Functions
string:levenshtein
Signatures | string:levenshtein($string1 as xs:string, $string2 as xs:string) as xs:double |
Summary | Computes the Damerau-Levenshtein Distance for two strings and returns a double value (0.0 - 1.0 ). The returned value is computed as follows:
|
Examples |
<syntaxhighlight lang="xquery"> let $norm := ft:normalize(?, map { 'stemming': true() }) return string:levenshtein($norm("HOUSES"), $norm("house")) </syntaxhighlight> |
string:soundex
Signatures | 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:cologne-phonetic
Signatures | 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 |
|
Changelog
- Version 10.0
- Updated: Renamed from Strings Module to String Module. The namespace URI has been updated as well.
The Module was introduced with Version 8.3.