]> git.proxmox.com Git - rustc.git/blame - vendor/strsim-0.8.0/README.md
New upstream version 1.63.0+dfsg1
[rustc.git] / vendor / strsim-0.8.0 / README.md
CommitLineData
7cac9316
XL
1# strsim-rs [![Crates.io](https://img.shields.io/crates/v/strsim.svg)](https://crates.io/crates/strsim) [![Crates.io](https://img.shields.io/crates/l/strsim.svg?maxAge=2592000)](https://github.com/dguo/strsim-rs/blob/master/LICENSE) [![Linux build status](https://travis-ci.org/dguo/strsim-rs.svg?branch=master)](https://travis-ci.org/dguo/strsim-rs) [![Windows build status](https://ci.appveyor.com/api/projects/status/ggue6i785618a39w?svg=true)](https://ci.appveyor.com/project/dguo/strsim-rs)
2
3[Rust](https://www.rust-lang.org) implementations of [string similarity metrics]:
4 - [Hamming]
e1599b0c 5 - [Levenshtein] - distance & normalized
041b39d2 6 - [Optimal string alignment]
e1599b0c 7 - [Damerau-Levenshtein] - distance & normalized
7cac9316
XL
8 - [Jaro and Jaro-Winkler] - this implementation of Jaro-Winkler does not limit the common prefix length
9
10### Installation
7cac9316
XL
11```toml
12# Cargo.toml
13[dependencies]
e1599b0c 14strsim = "0.8.0"
7cac9316
XL
15```
16
17### [Documentation](https://docs.rs/strsim/)
7cac9316
XL
18You can change the version in the url to see the documentation for an older
19version in the
20[changelog](https://github.com/dguo/strsim-rs/blob/master/CHANGELOG.md).
21
22### Usage
7cac9316
XL
23```rust
24extern crate strsim;
25
e1599b0c
XL
26use strsim::{hamming, levenshtein, normalized_levenshtein, osa_distance,
27 damerau_levenshtein, normalized_damerau_levenshtein, jaro,
0531ce1d 28 jaro_winkler};
7cac9316
XL
29
30fn main() {
31 match hamming("hamming", "hammers") {
32 Ok(distance) => assert_eq!(3, distance),
33 Err(why) => panic!("{:?}", why)
34 }
35
36 assert_eq!(3, levenshtein("kitten", "sitting"));
37
e1599b0c
XL
38 assert!((normalized_levenshtein("kitten", "sitting") - 0.57142).abs() < 0.00001);
39
041b39d2
XL
40 assert_eq!(3, osa_distance("ac", "cba"));
41
42 assert_eq!(2, damerau_levenshtein("ac", "cba"));
7cac9316 43
e1599b0c
XL
44 assert!((normalized_damerau_levenshtein("levenshtein", "löwenbräu") - 0.27272).abs() < 0.00001)
45
7cac9316
XL
46 assert!((0.392 - jaro("Friedrich Nietzsche", "Jean-Paul Sartre")).abs() <
47 0.001);
48
49 assert!((0.911 - jaro_winkler("cheeseburger", "cheese fries")).abs() <
50 0.001);
7cac9316
XL
51}
52```
53
54### Development
0531ce1d
XL
55If you don't want to install Rust itself, you can run `$ ./dev` for a
56development CLI if you have [Docker] installed.
7cac9316 57
e1599b0c
XL
58Benchmarks require a Nightly toolchain. They are run by `cargo +nightly bench`.
59
7cac9316 60### License
7cac9316
XL
61[MIT](https://github.com/dguo/strsim-rs/blob/master/LICENSE)
62
63[string similarity metrics]:http://en.wikipedia.org/wiki/String_metric
64[Damerau-Levenshtein]:http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance
65[Jaro and Jaro-Winkler]:http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance
66[Levenshtein]:http://en.wikipedia.org/wiki/Levenshtein_distance
67[Hamming]:http://en.wikipedia.org/wiki/Hamming_distance
041b39d2
XL
68[Optimal string alignment]:https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance
69[Docker]:https://docs.docker.com/engine/installation/