#string #similarity #Hamming #Levenshtein #Jaro

strsim

Implementations of string similarity metrics. Includes Hamming, Levenshtein, OSA, Damerau-Levenshtein, Jaro, and Jaro-Winkler

20 releases

0.9.2 May 9, 2019
0.8.0 Aug 19, 2018
0.7.0 Jan 17, 2018
0.6.0 Dec 27, 2016
0.2.2 Mar 29, 2015

#2 in Algorithms

Download history 56337/week @ 2019-01-24 57486/week @ 2019-01-31 61454/week @ 2019-02-07 60493/week @ 2019-02-14 63039/week @ 2019-02-21 65904/week @ 2019-02-28 65960/week @ 2019-03-07 65331/week @ 2019-03-14 62201/week @ 2019-03-21 65704/week @ 2019-03-28 88345/week @ 2019-04-04 94324/week @ 2019-04-11 89966/week @ 2019-04-18 87311/week @ 2019-04-25 76519/week @ 2019-05-02

351,166 downloads per month
Used in 729 crates (239 directly)

MIT license

29KB
606 lines

strsim-rs Crates.io Crates.io build status

Rust implementations of string similarity metrics:

The normalized versions return values between 0.0 and 1.0, where 1.0 means an exact match.

There are also generic versions of the functions for non-string inputs.

Installation

strsim is available on crates.io. Add it to your Cargo.toml:

[dependencies]
strsim = "0.9.2"

Usage

Go to Docs.rs for the full documentation. You can also clone the repo, and run $ cargo doc --open.

Examples

extern crate strsim;

use strsim::{hamming, levenshtein, normalized_levenshtein, osa_distance,
             damerau_levenshtein, normalized_damerau_levenshtein, jaro,
             jaro_winkler};

fn main() {
    match hamming("hamming", "hammers") {
        Ok(distance) => assert_eq!(3, distance),
        Err(why) => panic!("{:?}", why)
    }

    assert_eq!(levenshtein("kitten", "sitting"), 3);

    assert!((normalized_levenshtein("kitten", "sitting") - 0.571).abs() < 0.001);

    assert_eq!(osa_distance("ac", "cba"), 3);

    assert_eq!(damerau_levenshtein("ac", "cba"), 2);

    assert!((normalized_damerau_levenshtein("levenshtein", "löwenbräu") - 0.272).abs() <
            0.001);

    assert!((jaro("Friedrich Nietzsche", "Jean-Paul Sartre") - 0.392).abs() <
            0.001);

    assert!((jaro_winkler("cheeseburger", "cheese fries") - 0.911).abs() <
            0.001);
}

Using the generic versions of the functions:

extern crate strsim;

use strsim::generic_levenshtein;

fn main() {
    assert_eq!(2, generic_levenshtein(&[1, 2, 3], &[0, 2, 5]));
}

Contributing

If you don't want to install Rust itself, you can run $ ./dev for a development CLI if you have Docker installed.

Benchmarks require a Nightly toolchain. Run $ cargo +nightly bench.

License

MIT

No runtime deps