#levenshtein

stringmetrics

Rust library for approximate string matching

29 releases (stable)

2.2.2 Dec 28, 2022
2.2.0 Dec 15, 2022
2.1.3 Aug 26, 2022
2.1.2 Jul 24, 2022
0.1.15 May 20, 2022

#256 in Algorithms

Download history 90/week @ 2023-11-01 47/week @ 2023-11-08 74/week @ 2023-11-15 142/week @ 2023-11-22 91/week @ 2023-11-29 131/week @ 2023-12-06 120/week @ 2023-12-13 97/week @ 2023-12-20 104/week @ 2023-12-27 38/week @ 2024-01-03 44/week @ 2024-01-10 152/week @ 2024-01-17 63/week @ 2024-01-24 86/week @ 2024-01-31 111/week @ 2024-02-07 328/week @ 2024-02-14

614 downloads per month
Used in 6 crates (3 directly)

Custom license

50KB
721 lines

Stringmetrics

This is a Rust library for approximate string matching that implements simple algorithms such has Hamming distance, Levenshtein distance, Jaccard similarity, and more.

Here are some useful quick links:

Algorithms

The main purpose of this library is to provide a variety of string metric functions. Included algorithms are:

  • Levenshtein Distance
  • Limited & Weighted Levenshtein Distance
  • Jaccard Similarity
  • Hamming Distance

See the documentation for full information. Some examples are below:

// Basic levenshtein distance
use stringmetrics::levenshtein;

assert_eq!(levenshtein("kitten", "sitting"), 3);
// Levenshtein distance with a limit to save computation time
use stringmetrics::levenshtein_limit;

assert_eq!(levenshtein_limit("a very long string", "short!", 4), 4);
// Set custom weights
use stringmetrics::{levenshtein_weight, LevWeights};

// This struct holds insertion, deletion, and substitution costs
let weights = LevWeights::new(4, 3, 2);
assert_eq!(levenshtein_weight("kitten", "sitting", 100, &weights), 8);
// Basic hamming distance
use stringmetrics::hamming;

let a = "abcdefg";
let b = "aaadefa";
assert_eq!(hamming(a, b), Ok(3));

Future Algorithms & Direction

Eventually, this library aims to add support for more algorithms. Intended work includes:

  1. Update levenshtein distance to have a more performant algorithm for short (<64 characters) and long (>100 characters) strings
  2. Add the Damerau–Levenshtein distance
  3. Add the Jaro–Winkler distance
  4. Add the Tversky index
  5. Add Cosine similarity
  6. Add some useful tokenizers with examples

License

See the LICENSE file for license information. The provided license does allow for proprietary use and adaptation; that being said, I kindly suggest that if you come up with an improvement, you submit a pull request and help us all out :)

No runtime deps