Crates.io | rapidfuzz |
lib.rs | rapidfuzz |
version | 0.5.0 |
source | src |
created_at | 2020-02-21 19:56:52.727404 |
updated_at | 2023-12-01 07:17:57.154236 |
description | rapid fuzzy string matching library |
homepage | |
repository | https://github.com/maxbachmann/rapidfuzz-rs |
max_upload_size | |
id | 211286 |
size | 1,456,514 |
Description • Installation • Usage • License
RapidFuzz is a general purpose string matching library with implementations for Rust, C++ and Python.
The installation is as simple as:
$ cargo add rapidfuzz
The following examples show the usage with the Levenshtein distance. Other metrics can be found in the fuzz and distance modules.
use rapidfuzz::distance::levenshtein;
// Perform a simple comparision using he levenshtein distance
assert_eq!(
3,
levenshtein::distance("kitten".chars(), "sitting".chars())
);
// If you are sure the input strings are ASCII only it's usually faster to operate on bytes
assert_eq!(
3,
levenshtein::distance("kitten".bytes(), "sitting".bytes())
);
// You can provide a score_cutoff value to filter out strings with distance that is worse than
// the score_cutoff
assert_eq!(
None,
levenshtein::distance_with_args(
"kitten".chars(),
"sitting".chars(),
&levenshtein::Args::default().score_cutoff(2)
)
);
// You can provide a score_hint to tell the implementation about the expected score.
// This can be used to select a more performant implementation internally, but might cause
// a slowdown in cases where the distance is actually worse than the score_hint
assert_eq!(
3,
levenshtein::distance_with_args(
"kitten".chars(),
"sitting".chars(),
&levenshtein::Args::default().score_hint(2)
)
);
// When comparing a single string to multiple strings you can use the
// provided `BatchComparators`. These can cache part of the calculation
// which can provide significant speedups
let scorer = levenshtein::BatchComparator::new("kitten".chars());
assert_eq!(3, scorer.distance("sitting".chars()));
assert_eq!(0, scorer.distance("kitten".chars()));
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in RapidFuzz by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.