mirror of
https://gitee.com/openharmony/third_party_rust_strsim-rs
synced 2024-11-23 07:39:51 +00:00
1.4 KiB
1.4 KiB
strsim-rs
Rust implementations of string similarity metrics. Best efforts will be made to stay up-to-date with Rust nightly. Currently includes:
- Hamming
- Levenshtein
- Jaro and Jaro-Winkler - this implementation does not limit the common prefix length
Installation
# Cargo.toml
[dependencies]
strsim = "0.1.1"
Usage
extern crate strsim;
use strsim::{hamming, 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!((0.392 - jaro("Friedrich Nietzsche", "Jean-Paul Sartre")).abs() <
0.001);
assert!((0.911 - jaro_winkler("cheeseburger", "cheese fries")).abs() <
0.001);
}
Todo's
- Implement Damerau-Levenshtein
Version
0.1.1
License
MIT