module Edits::Levenshtein
Overview
Implementation of Levenshtein distance algorithm.
Determines distance between two string by counting edits, identifying:
 Insertion
 Deletion
 Substitution
Defined in:
edits/levenshtein.crClass Method Summary

.distance(str1, str2)
Calculate the Levenshtein (edit) distance of two sequences.

.distance(str1, str2, max : Int32)
Calculate the Levenshtein (edit) distance of two sequences, bounded by a maximum value.

.most_similar(prototype, strings : Enumerable)
Given a prototype string and an array of strings, determines which string is most similar to the prototype.
Class Method Detail
Calculate the Levenshtein (edit) distance of two sequences.
Note: a true distance metric, satisfies triangle inequality.
Levenshtein.distance("sand", "hands") # => 2
Calculate the Levenshtein (edit) distance of two sequences, bounded by a maximum value. For low max values, this can have better performance.
Levenshtein.distance "cloud", "crayon" # => 5
Levenshtein.distance_with_max "cloud", "crayon", 2 # => 2
Given a prototype string and an array of strings, determines which string is most similar to the prototype.
Levenshtein.most_similar("foo", strings)
is functionally equivalent to
strings.min_by { s Levenshtein.distance("foo", s) }
, leveraging a
max distance.