Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
/ vladlev Public archive

Levenshtein matching algorithm for ruby using C with an FFI extension

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt
Notifications You must be signed in to change notification settings

mxenabled/vladlev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vladlev

An implementation of the levenshtein distance algorithm for ruby using FFI

Installation

Add this line to your gemfile and then run bundle to install

gem 'vladlev'

Usage

Vladlev will calculate the levenshtein distance between two strings. The levenshtein distance is the number of transforms necessary to transform one string to be idential to the other. A transform is defined as an addition, deletion, or alteration of a single character in a string.

In order to calculate the distance

Vladlev.distance("string1", "string2")
>> 1

Vladlev also includes a 3 parameter version of the distance method. The third parameter is "maximum distance", which tells Vladlev to stop calculation once the distance becomes greater than this parameter.

In order to use this optimization

Vladlev.distance("string1234567890", "string1", 1)
>> 16

Vladlev.distance("string1234567890", "string1", 999)
>> 9

When given a pair of strings such that the distance between the two strings is greater than the "maximum distance" paramter, Vladlev will return the length of the longest string rather than spend the effort of calculating the distance when you know that you are not interested in the result.

Development

Vladlev uses rake-compiler for a build tool

bundle exec rake compile

bundle exec rake clean

For an agressive clean of compiled files, you can do this

bundle exec rake clobber

About

Levenshtein matching algorithm for ruby using C with an FFI extension

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Stars

Watchers

Forks

Packages

No packages published