Project

vladlev

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Levenshtein matching algorithm for ruby using C with an FFI extension
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

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