mirror of
https://gitee.com/openharmony/third_party_rust_strsim-rs
synced 2024-11-23 15:49:45 +00:00
src | ||
tests | ||
.gitignore | ||
.travis.yml | ||
Cargo.toml | ||
LICENSE | ||
README.md |
strsim-rs
Rust implementations of string similarity metrics. Best efforts will be made to stay up-to-date with Rust nightly. Includes:
- Hamming
- Levenshtein and Damerau-Levenshtein
- Jaro and Jaro-Winkler - this implementation of Jaro-Winkler does not limit the common prefix length
Installation
# Cargo.toml
[dependencies]
strsim = "0.2.0"
Usage
extern crate strsim;
use strsim::{hamming, levenshtein, damerau_levenshtein, jaro, jaro_winkler};
use std::num::Float;
fn main() {
match hamming("hamming", "hammers") {
Ok(distance) => assert_eq!(3, distance),
Err(why) => panic!("{:?}", why)
}
assert_eq!(3, levenshtein("kitten", "sitting"));
assert_eq!(1, damerau_levenshtein("specter", "spectre"));
assert!((0.392 - jaro("Friedrich Nietzsche", "Jean-Paul Sartre")).abs() <
0.001);
assert!((0.911 - jaro_winkler("cheeseburger", "cheese fries")).abs() <
0.001);
}
Version
0.2.0
License
MIT