Algorithm

Trait Algorithm 

Source
pub trait Algorithm<R> {
    // Provided methods
    fn for_iter<C, E>(&self, s1: C, s2: C) -> Result<R>
       where C: Iterator<Item = E>,
             E: Eq + Hash { ... }
    fn for_vec<E>(&self, s1: &[E], s2: &[E]) -> Result<R>
       where E: Eq + Hash { ... }
    fn for_str(&self, s1: &str, s2: &str) -> Result<R> { ... }
    fn for_words(&self, s1: &str, s2: &str) -> Result<R> { ... }
    fn for_bigrams(&self, s1: &str, s2: &str) -> Result<R> { ... }
}
Expand description

A base trait for all distance/similarity algorithms.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_str("abc", "acbd");
assert!(res.val() == 3);

Provided Methods§

Source

fn for_iter<C, E>(&self, s1: C, s2: C) -> Result<R>
where C: Iterator<Item = E>, E: Eq + Hash,

Calculate distance/similarity for iterators.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_iter(1..4, 1..6);
assert!(res.val() == 2);
Source

fn for_vec<E>(&self, s1: &[E], s2: &[E]) -> Result<R>
where E: Eq + Hash,

Calculate distance/similarity for vectors.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_vec(&vec![1, 2, 3], &vec![1, 3, 2, 4]);
assert!(res.val() == 3);
Source

fn for_str(&self, s1: &str, s2: &str) -> Result<R>

Calculate distance/similarity for strings.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_str("abc", "acbd");
assert!(res.val() == 3);
Source

fn for_words(&self, s1: &str, s2: &str) -> Result<R>

Calculate distance/similarity for words in strings.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_words("the first edition", "the second edition");
assert!(res.val() == 1);
Source

fn for_bigrams(&self, s1: &str, s2: &str) -> Result<R>

Calculate distance/similarity for bigrams in strings.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_str("abd", "abcd");
assert!(res.val() == 2); // 3 bigrams (ab, bc, cd), only "ab" matches

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§