User Tools

Site Tools


syntax:functions:distance

Distance(text1, text2)

Category: Text function


Description

This function returns the edit distance between two text strings calculated as the Damerau-Levenshtein distance.

This shows the number of text edits, such as character insertions or deletions, that is needed to produce text2 from text1. It is used to measure the degree of variance between two strings. The larger the edit distance, the more different the strings are.


Use cases

Rating the similarity between words (fuzzy matching).

The detection of mistyped words.


Arguments

ArgumentTypeDescription
text1TextThe "source" string value.
text2TextThe "destination" string to transform text1 into .

Return value type: Number


Remarks

This function is case sensitive insofar as replacing a lower-case character with the upper-case version, or upper-case with the lower-case version, is considered an edit.

While numeric values can be entered for either argument, the function handles them as text strings for the calculation of the edit distance.


Examples

distance("cat", "cat") //Returns 0  (Strings are the same)
distance("cat", "cut") //Returns 1  (Change "a" to "u")
distance("cat", "dog") //Returns 3  (Change "c" to "d", "a" to "o", and "t" to "g")
distance("cat", "Scott") //Returns 3  (Delete "S" and one of the "t"s, and change "a" to "o")
distance("Mary","mary") //Returns 1  (Replace upper-case "M" with lower-case "m")
distance(100, 1) //Returns 2  (Remove both "0"s)
distance(100, "Bob") //Returns 3  (Replace "1" with "M", replace "0" with "a", and replace "0" with "r")
syntax/functions/distance.txt · Last modified: 2021/08/14 22:02 by craigt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki