Go to file
Ophir LOJKINE 31cb4cb82d [feature] Implement generic distance functions (#30)
* [feature] Implement generic distance functions

Closes https://github.com/dguo/strsim-rs/issues/29

* Change variable names in generic functions

* rename *_generic functions to generic_*

See https://github.com/dguo/strsim-rs/pull/30#issuecomment-475084373
2019-03-29 16:07:13 -04:00
benches [feature] Implement generic distance functions (#30) 2019-03-29 16:07:13 -04:00
src [feature] Implement generic distance functions (#30) 2019-03-29 16:07:13 -04:00
tests Add normalized Levenshtein and Damerau-Levenstein (#20) 2018-08-19 17:30:28 -04:00
.editorconfig Add EditorConfig 2016-06-05 03:47:56 -04:00
.gitattributes Let Git normalize line endings 2016-09-24 23:45:57 -04:00
.gitignore Use the official Docker image for Rust 2017-10-11 12:03:09 -04:00
.travis.yml Add a pinned Rust version to the Travis config (#27) 2018-10-30 18:47:31 -04:00
Cargo.toml Exclude unneeded files from crates.io (#22) 2018-10-30 16:47:39 -04:00
CHANGELOG.md Release 0.8.0 2018-08-19 18:26:48 -04:00
dev Upgrade Rust to 1.30.0 2018-10-28 11:38:29 -04:00
LICENSE Update the LICENSE 2018-01-17 10:53:00 -05:00
README.md Use Travis for Windows testing (#25) 2018-10-28 14:36:51 -04:00

strsim-rs Crates.io Crates.io build status

Rust implementations of string similarity metrics:

The normalized versions return values between 0.0 and 1.0, where 1.0 means an exact match.

Installation

strsim is available on crates.io. Add it to your Cargo.toml:

[dependencies]
strsim = "0.8.0"

Usage

Go to Docs.rs for the full documentation. You can also clone the repo, and run $ cargo doc --open.

Examples

extern crate strsim;

use strsim::{hamming, levenshtein, normalized_levenshtein, osa_distance,
             damerau_levenshtein, normalized_damerau_levenshtein, jaro,
             jaro_winkler};

fn main() {
    match hamming("hamming", "hammers") {
        Ok(distance) => assert_eq!(3, distance),
        Err(why) => panic!("{:?}", why)
    }

    assert_eq!(levenshtein("kitten", "sitting"), 3);

    assert!((normalized_levenshtein("kitten", "sitting") - 0.571).abs() < 0.001);

    assert_eq!(osa_distance("ac", "cba"), 3);

    assert_eq!(damerau_levenshtein("ac", "cba"), 2);

    assert!((normalized_damerau_levenshtein("levenshtein", "löwenbräu") - 0.272).abs() <
            0.001);

    assert!((jaro("Friedrich Nietzsche", "Jean-Paul Sartre") - 0.392).abs() <
            0.001);

    assert!((jaro_winkler("cheeseburger", "cheese fries") - 0.911).abs() <
            0.001);
}

Contributing

If you don't want to install Rust itself, you can run $ ./dev for a development CLI if you have Docker installed.

Benchmarks require a Nightly toolchain. Run $ cargo +nightly bench.

License

MIT