Project

General

Profile

Actions

Feature #10882

open

Provide Levenshtein distance implementation as part of stdlib

Added by yuki24 (Yuki Nishijima) about 9 years ago. Updated about 9 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:68216]

Description

Levenshtein distance algorithm has been used by Rubygems, Bundler, did_you_mean and Rails and I think it's popular enough to provide it as part of Ruby's stdlib. It still seems a bit too high-level though, but definitely useful (e.g. adding "did you mean?" to rake).

API-wise, I would like to propose something like the following, but I'm totally open to hear the core team's opinions as I'm not sue if this is great.

require 'distance'

Distance.levenshtein(str1, str2)

It would also be interesting to have #distance method on String:

"word".distance("other")

which is implemented as:

def distance(str, algorithm = :levenshtein)
  # calculate the distance here.
end

so it can allow to change the algorythm when we add more (e.g. Jaro–Winkler distance).

Actions

Also available in: Atom PDF

Like0
Like0Like0