3 [![Crates.io](https://img.shields.io/crates/v/strsim.svg)](https://crates.io/crates/strsim)
4 [![Crates.io](https://img.shields.io/crates/l/strsim.svg?maxAge=2592000)](https://github.com/dguo/strsim-rs/blob/master/LICENSE)
5 [![CI status](https://github.com/dguo/strsim-rs/workflows/CI/badge.svg)](https://github.com/dguo/strsim-rs/actions?query=branch%3Amaster)
6 [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
8 [Rust](https://www.rust-lang.org) implementations of [string similarity metrics]:
10 - [Levenshtein] - distance & normalized
11 - [Optimal string alignment]
12 - [Damerau-Levenshtein] - distance & normalized
13 - [Jaro and Jaro-Winkler] - this implementation of Jaro-Winkler does not limit the common prefix length
16 The normalized versions return values between `0.0` and `1.0`, where `1.0` means
19 There are also generic versions of the functions for non-string inputs.
23 `strsim` is available on [crates.io](https://crates.io/crates/strsim). Add it to
32 Go to [Docs.rs](https://docs.rs/strsim/) for the full documentation. You can
33 also clone the repo, and run `$ cargo doc --open`.
40 use strsim::{hamming, levenshtein, normalized_levenshtein, osa_distance,
41 damerau_levenshtein, normalized_damerau_levenshtein, jaro,
42 jaro_winkler, sorensen_dice};
45 match hamming("hamming", "hammers") {
46 Ok(distance) => assert_eq!(3, distance),
47 Err(why) => panic!("{:?}", why)
50 assert_eq!(levenshtein("kitten", "sitting"), 3);
52 assert!((normalized_levenshtein("kitten", "sitting") - 0.571).abs() < 0.001);
54 assert_eq!(osa_distance("ac", "cba"), 3);
56 assert_eq!(damerau_levenshtein("ac", "cba"), 2);
58 assert!((normalized_damerau_levenshtein("levenshtein", "löwenbräu") - 0.272).abs() <
61 assert!((jaro("Friedrich Nietzsche", "Jean-Paul Sartre") - 0.392).abs() <
64 assert!((jaro_winkler("cheeseburger", "cheese fries") - 0.911).abs() <
67 assert_eq!(sorensen_dice("web applications", "applications of the web"),
72 Using the generic versions of the functions:
77 use strsim::generic_levenshtein;
80 assert_eq!(2, generic_levenshtein(&[1, 2, 3], &[0, 2, 5]));
86 If you don't want to install Rust itself, you can run `$ ./dev` for a
87 development CLI if you have [Docker] installed.
89 Benchmarks require a Nightly toolchain. Run `$ cargo +nightly bench`.
93 [MIT](https://github.com/dguo/strsim-rs/blob/master/LICENSE)
95 [string similarity metrics]:http://en.wikipedia.org/wiki/String_metric
96 [Damerau-Levenshtein]:http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance
97 [Jaro and Jaro-Winkler]:http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance
98 [Levenshtein]:http://en.wikipedia.org/wiki/Levenshtein_distance
99 [Hamming]:http://en.wikipedia.org/wiki/Hamming_distance
100 [Optimal string alignment]:https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance
101 [Sørensen-Dice]:http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
102 [Docker]:https://docs.docker.com/engine/installation/