Result

Struct Result 

Source
pub struct Result<R> { /* private fields */ }
Expand description

Result of a distance/similarity algorithm.

Implementations§

Source§

impl Result<usize>

Source

pub fn val(&self) -> usize

Raw value of the metric.

It is equivalent to dist for distance metrics and to sim for similarity metrics.

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

pub fn dist(&self) -> usize

Absolute distance.

A non-negative number showing how different the two sequences are. Two exactly the same sequences have the distance 0.

The highest possible number varies based on the length of the input strings. Most often, each increment of this value indicates one symbol that differs in the input sequences.

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

pub fn sim(&self) -> usize

Absolute similarity.

A non-negative number showing how similar the two sequences are. Two absolutely different sequences have the similarity 0.

The highest possible number varies based on the length of the input strings. Most often, each increment of this value indicates one symbol that is the same in both sequences.

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

pub fn nval(&self) -> f64

Normalized raw value of the metric.

It is equivalent to ndist for distance metrics and to nsim for similarity metrics.

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

pub fn ndist(&self) -> f64

Normalized distance.

A number from 0.0 to 1.0 showing how different the two sequences are. 0.0 indicates that the sequences are the same, and 1.0 indicates that the sequences are very different.

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

pub fn nsim(&self) -> f64

Normalized similarity.

A number from 0.0 to 1.0 showing how similar the two sequences are. 0.0 indicates that the sequences are very different, and 1.0 indicates that the sequences are the same.

use textdistance::{Algorithm, Hamming};
let h = Hamming::default();
let res = h.for_str("abc", "acbd");
assert!(res.nsim() == 1.0 / 4.0);
Source§

impl Result<f64>

Source

pub fn nval(&self) -> f64

Normalized raw value of the metric.

It is equivalent to ndist for distance metrics and to nsim for similarity metrics.

use textdistance::{Algorithm, Jaro};
let h = Jaro::default();
let res = h.for_str("test", "tset");
assert_eq!(res.nval(), 0.9166666666666666);
Source

pub fn ndist(&self) -> f64

Normalized distance.

A number from 0.0 to 1.0 showing how different the two sequences are. 0.0 indicates that the sequences are the same, and 1.0 indicates that the sequences are very different.

use textdistance::{Algorithm, Jaro};
let h = Jaro::default();
let res = h.for_str("test", "tset");
assert_eq!(res.ndist(), 0.08333333333333337);
Source

pub fn nsim(&self) -> f64

Normalized similarity.

A number from 0.0 to 1.0 showing how similar the two sequences are. 0.0 indicates that the sequences are very different, and 1.0 indicates that the sequences are the same.

use textdistance::{Algorithm, Jaro};
let h = Jaro::default();
let res = h.for_str("test", "tset");
assert_eq!(res.nsim(), 0.9166666666666666);

Auto Trait Implementations§

§

impl<R> Freeze for Result<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Result<R>
where R: RefUnwindSafe,

§

impl<R> Send for Result<R>
where R: Send,

§

impl<R> Sync for Result<R>
where R: Sync,

§

impl<R> Unpin for Result<R>
where R: Unpin,

§

impl<R> UnwindSafe for Result<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.