gecko-dev/third_party/rust/strsim
Bobby Holley 909114ca57 Bug 1340838 - Revendor rust dependencies after upgrade. r=me
MozReview-Commit-ID: IJRUwUF6IcJ


--HG--
rename : third_party/rust/app_units/.cargo-checksum.json => third_party/rust/app_units-0.3.0/.cargo-checksum.json
rename : third_party/rust/app_units/Cargo.toml => third_party/rust/app_units-0.3.0/Cargo.toml
rename : third_party/rust/app_units/src/app_unit.rs => third_party/rust/app_units-0.3.0/src/app_unit.rs
rename : third_party/rust/euclid/.cargo-checksum.json => third_party/rust/euclid-0.10.3/.cargo-checksum.json
rename : third_party/rust/euclid/Cargo.toml => third_party/rust/euclid-0.10.3/Cargo.toml
rename : third_party/rust/euclid/src/length.rs => third_party/rust/euclid-0.10.3/src/length.rs
rename : third_party/rust/euclid/src/lib.rs => third_party/rust/euclid-0.10.3/src/lib.rs
rename : third_party/rust/euclid/src/macros.rs => third_party/rust/euclid-0.10.3/src/macros.rs
rename : third_party/rust/euclid/src/matrix2d.rs => third_party/rust/euclid-0.10.3/src/matrix2d.rs
rename : third_party/rust/euclid/src/matrix4d.rs => third_party/rust/euclid-0.10.3/src/matrix4d.rs
rename : third_party/rust/euclid/src/rect.rs => third_party/rust/euclid-0.10.3/src/rect.rs
rename : third_party/rust/euclid/src/scale_factor.rs => third_party/rust/euclid-0.10.3/src/scale_factor.rs
rename : third_party/rust/euclid/src/size.rs => third_party/rust/euclid-0.10.3/src/size.rs
2017-02-18 14:09:44 -08:00
..
src
tests
.cargo-checksum.json
.cargo-ok
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md
Cargo.toml
LICENSE
README.md
appveyor.yml
dev

README.md

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

Rust implementations of string similarity metrics:

Installation

# Cargo.toml
[dependencies]
strsim = "0.6.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, osa_distance, damerau_levenshtein, jaro,
             jaro_winkler, levenshtein_against_vec, osa_distance_against_vec,
             damerau_levenshtein_against_vec, jaro_against_vec,
             jaro_winkler_against_vec};

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

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

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

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

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

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

    // get vectors of values back
    let v = vec!["test", "test1", "test12", "test123", "", "tset", "tsvet"];

    assert_eq!(levenshtein_against_vec("test", &v),
               vec![0, 1, 2, 3, 4, 2, 3]);

    assert_eq!(osa_distance_against_vec("test", &v),
               vec![0, 1, 2, 3, 4, 1, 3]);

    assert_eq!(damerau_levenshtein_against_vec("test", &v),
               vec![0, 1, 2, 3, 4, 1, 2]);

    let jaro_distances = jaro_against_vec("test", &v);
    let jaro_expected = vec![1.0, 0.933333, 0.888889, 0.857143, 0.0, 0.916667];
    let jaro_delta: f64 = jaro_distances.iter()
                                        .zip(jaro_expected.iter())
                                        .map(|(x, y)| (x - y).abs() as f64)
                                        .fold(0.0, |x, y| x + y as f64);
    assert!(jaro_delta < 0.0001);

    let jaro_winkler_distances = jaro_winkler_against_vec("test", &v);
    let jaro_winkler_expected = vec![1.0, 0.96, 0.933333, 0.914286, 0.0, 0.925];
    let jaro_winkler_delta = jaro_winkler_distances.iter()
                                 .zip(jaro_winkler_expected.iter())
                                 .map(|(x, y)| (x - y).abs() as f64)
                                 .fold(0.0, |x, y| x + y as f64);
    assert!(jaro_winkler_delta < 0.0001);
}

Development

If you don't want to install Rust itself, you can install Docker, and run $ ./dev. This should bring up a temporary container from which you can run cargo commands.

License

MIT