Kyori: A Javascript library focused on string metrics
A library that offers many methods to calculate string edit distance. In addition, it offers the Kyori algorithm, a simple-yet-nice approach to rank several results against a set of terms (keywords). It is handy when you have search results, and you want to return the most relevant lexicographically.
In Japanese, the word for “distance” is 距離 pronounced as kyori (きょり).
Supported methods
The library provides support for the following methods for string edit distance:
- Levenshtein It measures the minimum number of single-character edits—insertions, deletions, or substitutions—required to change one word into the other.
- Damerau-Levenshtein An extension of the Levenshtein distance, this method also accounts for transpositions (swapping of two adjacent characters) in addition to insertions, deletions, and substitutions. It is particularly useful when transposition errors are common, such as in typographical mistakes.
- Hamming Distance This method calculates the number of positions at which the corresponding characters in two strings of equal length are different. It is only applicable when the strings are of the same length and is often used in error detection and correction algorithms.
... and for string similarity:
- Jaro-Winkler This method is particularly effective for short strings such as names. It calculates a similarity score based on the number and order of common characters, giving higher scores to strings that match from the beginning.
- Kyori A similarity method that is token sensitive and focus of the similarity of a term to a specific text. It is ideal to rank results for autocomplete interfaces.
Except kyori, levensthein, Jaro-Winkler and Hamming all the other methods are wrapper on the talisman library ↗. For these early versions, this library will be used as a dependency, but since it has not been updated for 3-4 years, it will be replaced in the next versions.