Bug: 328419676

Clone this repo:
  1. ca082c4 Migrate 25 crates to monorepo. am: 3fc32ff89d by James Farrell · 5 months ago main
  2. 3fc32ff Migrate 25 crates to monorepo. by James Farrell · 5 months ago
  3. 70f5381 Update Android.bp by running cargo_embargo am: bf3489c8f2 by James Farrell · 6 months ago
  4. bf3489c Update Android.bp by running cargo_embargo by James Farrell · 6 months ago
  5. c03a9d0 Update Android.bp by running cargo_embargo am: 4fef949c73 am: 2ca42d9ea4 by James Farrell · 8 months ago android15-tests-dev aml_art_350913340 aml_art_351011240 aml_art_351011340 aml_art_351110180 aml_cbr_350910020 aml_cbr_351011020 aml_doc_350915120 aml_doc_351012120 aml_ext_350912020 aml_hef_350921160 aml_hef_351016140 aml_med_350914000 aml_med_351010060 aml_net_350911020 aml_net_351010000 aml_net_351010020 aml_per_350910080 aml_per_351014000 aml_res_351011000 aml_rkp_350910000 aml_rkp_351011000 aml_sdk_350910000 aml_sta_350911020 aml_tet_350911120 aml_tet_351010220 aml_uwb_350911040 aml_uwb_351011040 aml_wif_350912040 aml_wif_351010040

strsim-rs

Crates.io Crates.io CI status unsafe forbidden

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 project:

cargo add strsim

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, sorensen_dice};

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);

    assert_eq!(sorensen_dice("web applications", "applications of the web"),
        0.7878787878787878);
}

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