module Edits::Levenshtein
Overview
Implementation of Levenshtein distance algorithm.
Determines distance between two string by counting edits, identifying:
- Insertion
- Deletion
- Substitution
Extended Modules
Defined in:
edits/levenshtein.crClass Method Summary
-
.distance(str1, str2, max : Int)
Calculate the Levenshtein (edit) distance of two sequences, bounded by a maximum value.
-
.distance(str1, str2)
Calculate the Levenshtein (edit) distance of two sequences.
Class Method Detail
def self.distance(str1, str2, max : Int)
#
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("cloud", "crayon", 2) # => 2
def self.distance(str1, str2)
#
Calculate the Levenshtein (edit) distance of two sequences.
Note: a true distance metric, satisfies triangle inequality.
Levenshtein.distance("sand", "hands") # => 2