Struct Composite

Source
pub struct Composite<Q, C> { /* private fields */ }

Implementations§

Source§

impl<Q, C> Composite<Q, C>

Source

pub fn new(strategy: Strategy) -> Self

Examples found in repository?
examples/multimetric.rs (line 58)
56fn main() {
57    // Create a composite metric with weighted strategy
58    let composite_metric = Composite::<String, String>::new(Strategy::Weighted(vec![0.6, 0.4]))
59        .add(LevenshteinMetric)
60        .add(JaccardMetric);
61
62    // Create a matcher with the composite metric
63    let matcher = Matcher::<String, String>::new()
64        .add(composite_metric, 1.0)
65        .threshold(0.5);
66
67    // Define the query and candidate strings
68    let query = String::from("hello world");
69    let candidates = vec![
70        String::from("hello"),
71        String::from("hello there"),
72        String::from("world"),
73    ];
74
75    // Find matches with a limit of 2
76    println!("Multiple Metrics Example");
77    println!("=======================");
78    let matches = matcher.find_limit(&query, &candidates, 2);
79    println!("Matches found: {}", matches.len());
80    for (i, m) in matches.iter().enumerate() {
81        println!(
82            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
83            i + 1, m.score, m.candidate, m.exact
84        );
85    }
86}
Source

pub fn add<M: Similarity<Q, C> + 'static>(self, metric: M) -> Self

Examples found in repository?
examples/multimetric.rs (line 59)
56fn main() {
57    // Create a composite metric with weighted strategy
58    let composite_metric = Composite::<String, String>::new(Strategy::Weighted(vec![0.6, 0.4]))
59        .add(LevenshteinMetric)
60        .add(JaccardMetric);
61
62    // Create a matcher with the composite metric
63    let matcher = Matcher::<String, String>::new()
64        .add(composite_metric, 1.0)
65        .threshold(0.5);
66
67    // Define the query and candidate strings
68    let query = String::from("hello world");
69    let candidates = vec![
70        String::from("hello"),
71        String::from("hello there"),
72        String::from("world"),
73    ];
74
75    // Find matches with a limit of 2
76    println!("Multiple Metrics Example");
77    println!("=======================");
78    let matches = matcher.find_limit(&query, &candidates, 2);
79    println!("Matches found: {}", matches.len());
80    for (i, m) in matches.iter().enumerate() {
81        println!(
82            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
83            i + 1, m.score, m.candidate, m.exact
84        );
85    }
86}

Trait Implementations§

Source§

impl<Q, C> Similarity<Q, C> for Composite<Q, C>

Source§

fn score(&self, query: &Q, candidate: &C) -> f64

Source§

fn exact(&self, query: &Q, candidate: &C) -> bool

Auto Trait Implementations§

§

impl<Q, C> Freeze for Composite<Q, C>

§

impl<Q, C> !RefUnwindSafe for Composite<Q, C>

§

impl<Q, C> !Send for Composite<Q, C>

§

impl<Q, C> !Sync for Composite<Q, C>

§

impl<Q, C> Unpin for Composite<Q, C>
where Q: Unpin, C: Unpin,

§

impl<Q, C> !UnwindSafe for Composite<Q, C>

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.