mirror of
https://gitee.com/openharmony/third_party_rust_strsim-rs
synced 2024-11-27 01:40:41 +00:00
src | ||
tests | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.travis.yml | ||
appveyor.yml | ||
Cargo.toml | ||
CHANGELOG.md | ||
dev | ||
LICENSE | ||
README.md |
strsim-rs
Rust implementations of string similarity metrics:
- Hamming
- Levenshtein
- Optimal string alignment
- Damerau-Levenshtein
- Jaro and Jaro-Winkler - this implementation of Jaro-Winkler does not limit the common prefix length
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};
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);
}
Development
If you don't want to install Rust itself, you can run $ ./dev
for a
development CLI if you have Docker installed.