5 stable releases

new 1.1.1 Oct 23, 2024
1.0.3 Oct 10, 2024
1.0.2 Sep 30, 2024
1.0.1 Sep 13, 2024
1.0.0 Sep 6, 2024

#353 in Algorithms

Download history 94/week @ 2024-09-02 147/week @ 2024-09-09 62/week @ 2024-09-16 21/week @ 2024-09-23 250/week @ 2024-09-30 145/week @ 2024-10-07 16/week @ 2024-10-14

435 downloads per month

MIT license

52KB
328 lines

About

Sniffer is a library for fuzzy matching strings in rust. For example ybe is a match for Youtube. This provides a easy and user friendly way to search for a match without the need for a lot of code.

Install

To install do this in your project:

cargo add sniffer-rs

Or add it manually in cargo.toml:

[dependencies]
sniffer-rs = "1.1.1"

Usage

The usage of the library is very simple. It provides 4 algorithms for searching and a sniffer object that contains sane defaults for searching.

Basic match

let sniffer = Sniffer::new();
let matches = sniffer.matches("banana", "bana");

Case sensitive match

let sniffer = Sniffer::new().set_case_sensitive(true);
let matches = sniffer.matches("Banana", "banana");

Levenshtein Algorithm

Returns the amount of characters that are different.

let matches = get_levenshtein_distance("Banana", "banin3");

Hamming Algorithm

Returns the amount of positional characters different. It only works with same size strings.

let matches = get_hamming_distance("banana", "banin3")

Jaro Winkler Algorithm

Returns the difference in a percentage. From 0.0 to 1.0.

let matches = get_jaro_winkler_distance("banana", "banan")

Inner Algorithm

Returns true if the characters are inside the string.

let matches = get_inner_match("Sprigatito", "agt");

Sniffer

The sniffer match object can be changed in its intialization in case you don't like the default values.

let sniffer = Sniffer().set_levenshtein_distance(2)
                .set_do_levenshtein_match(true)
                .set_hamming_distance(2)
                .set_do_hamming_match(true)
                .set_jaro_winkler_distance(0.8)
                .set_do_jaro_winkler_match(true)
                .set_do_inner_match(true)
                .set_case_sensitive(false);

Sniffer Result

The sniffer result returns the values of the algorithms from a match. It's more appropriate for debuging.

let result = get_sniffer_result("Luxray", "lux");

Contributors

The people that are helping the project with minor or big changes.

No runtime deps