6 releases (3 breaking)

0.5.0 Dec 1, 2023
0.4.0 Dec 1, 2023
0.3.2 Nov 29, 2023
0.1.0 Feb 21, 2020

#126 in Text processing

Download history 1896/week @ 2024-07-21 1874/week @ 2024-07-28 1275/week @ 2024-08-04 1195/week @ 2024-08-11 1584/week @ 2024-08-18 2119/week @ 2024-08-25 2538/week @ 2024-09-01 2313/week @ 2024-09-08 2012/week @ 2024-09-15 2930/week @ 2024-09-22 2008/week @ 2024-09-29 4370/week @ 2024-10-06 3698/week @ 2024-10-13 3281/week @ 2024-10-20 3300/week @ 2024-10-27 4307/week @ 2024-11-03

14,724 downloads per month
Used in 4 crates (2 directly)

MIT license

1.5MB
19K SLoC

RapidFuzz

Rapid fuzzy string matching in Rust using the Levenshtein Distance

Continous Integration Gitter chat Documentation license

DescriptionInstallationUsageLicense


Description

RapidFuzz is a general purpose string matching library with implementations for Rust, C++ and Python.

Key Features

  • Diverse String Metrics: Offers a variety of string metrics to suit different use cases. These range from the Levenshtein distance for edit-based comparisons to the Jaro-Winkler similarity for more nuanced similarity assessments.
  • Optimized for Speed: The library is designed with performance in mind. Each implementation is carefully designed to ensure optimal performance, making it suitable for the analysis of large datasets.
  • Easy to use: The API is designed to be simple to use, while still giving the implementation room for optimization.

Installation

The installation is as simple as:

$ cargo add rapidfuzz

Usage

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()));

License

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.

No runtime deps