#levenshtein #distance #algorithm

leven-distance

Compute operational differences between two sequences using the Levenshtein algorithm

1 stable release

1.0.0 Feb 6, 2024

#623 in Text processing

MIT license

14KB
221 lines

Levenshtein

Compute operational differences between two sequences using the Levenshtein algorithm.

Add to Cargo.toml

leven-distance = "*"

Usage:

Basic Usage

use levenshtein::Levenshtein;
use levenshtein::Results;

fn main() {
    let mut levenshtein: Levenshtein = Levenshtein::new();

    // Specify costs as you see fit, the default is 1 for all parameters.
    levenshtein.set_insert_cost(2);
    levenshtein.set_replace_cost(2);
    levenshtein.set_delete_cost(2);

    let results: Results = levenshtein.calculate("test", "text");

    let distance: i32 = results.distance();
    let sequence: &Vec<Vec<i32>> = results.sequence();

    println!("Distance: {}", distance);
    println!("Sequence: {:#?}", sequence);
}

License

This project is licensed under the MIT License.
See the LICENSE file for more information.

No runtime deps