jaccard

Function jaccard 

Source
pub fn jaccard<I, T>(a: I, b: I) -> f32
where I: IntoIterator<Item = T>, T: Hash + Eq,
Expand description

Calculate the Jaccard index on two iterators using jaccard_set

Returns the mathematical Jaccard index, i.e. |A ∩ B| / |A ∪ B|. Iterators can point to anything hashable. Often this is combined with an iterator adapter such as std::str::Split and/or core::slice::Windows to generate n-grams for text similarity. See this wikipedia page for descriptions on n-grams.

Note: If the data are interested in is already in a HashSet, use jaccard_set to save the collection step.

§Example

use stringmetrics::jaccard;

let crew1 = ["Einar", "Olaf", "Harald"];
let crew2 = ["Olaf", "Harald", "Birger"];

assert_eq!(jaccard(crew1.iter(), crew2.iter()), 0.5);

Example using using 2-grams. See this execllent reference for an in-depth explanation of Jaccard Index for k-grams/n-grams.

use stringmetrics::jaccard;

let a = [["to", "be"], ["be", "or"], ["or", "not"]];
let b = [["who", "wants"], ["wants", "to"], ["to", "be"]];

assert_eq!(jaccard(a.iter(), b.iter()), 0.2);