#string #similarity #Hamming #Levenshtein #Jaro

strsim

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

17 unstable releases (7 breaking)

0.8.0 Aug 19, 2018
0.7.0 Jan 17, 2018
0.6.0 Dec 27, 2016
0.5.2 Nov 22, 2016
0.2.2 Mar 29, 2015

#2 in Algorithms

Download history 48573/week @ 2018-11-17 52068/week @ 2018-11-24 61099/week @ 2018-12-01 61923/week @ 2018-12-08 51656/week @ 2018-12-15 39657/week @ 2018-12-22 47325/week @ 2018-12-29 55380/week @ 2019-01-05 58712/week @ 2019-01-12 58234/week @ 2019-01-19 55943/week @ 2019-01-26 58805/week @ 2019-02-02 61397/week @ 2019-02-09 60528/week @ 2019-02-16 65848/week @ 2019-02-23

162,145 downloads per month
Used in 667 crates (203 directly)

MIT license

26KB
566 lines

strsim-rs Crates.io Crates.io Linux build status Windows build status

Rust implementations of string similarity metrics:

Installation

# Cargo.toml
[dependencies]
strsim = "0.8.0"

Documentation

You can change the version in the url to see the documentation for an older version in the changelog.

Usage

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!(3, levenshtein("kitten", "sitting"));

    assert!((normalized_levenshtein("kitten", "sitting") - 0.57142).abs() < 0.00001);

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

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

    assert!((normalized_damerau_levenshtein("levenshtein", "löwenbräu") - 0.27272).abs() < 0.00001)

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

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

Development

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. They are run by cargo +nightly bench.

License

MIT

No runtime deps