module

Edits::RestrictedEdit

Restricted Damerau-Levenshtein edit distance (Optimal Alignment).

Determines distance between two strings by counting edits, identifying:

  • Insertion
  • Deletion
  • Substitution
  • Adjacent transposition

This variant is restricted by the condition that no sub-string is edited more than once.

Class methods

distance(str1, str2, max : Int) : Int32

Calculate the Restricted Damerau-Levenshtein distance (Optimal Alignment) of two sequences, bounded by a maximum value.

Edits::RestrictedEdit.distance("cloud", "crayon")    # => 5
Edits::RestrictedEdit.distance("cloud", "crayon", 2) # => 2
Source
distance(str1, str2) : Int32

Calculate the Restricted Damerau-Levenshtein distance (Optimal Alignment) of two sequences.

NOTE: Not a true distance metric, fails to satisfy triangle inequality.

RestrictedEdit.distance("iota", "atom") # => 3
Source