simstring_rust::measures

Struct Cosine

Source
pub struct Cosine;

Implementations§

Source§

impl Cosine

Source

pub fn new() -> Self

Examples found in repository?
examples/basic_usage.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fn main() {
    let _cs = Cosine::new();

    let feature_extractor = CharacterNGrams {
        n: 3,
        padder: " ".to_string(),
    };

    let mut db = HashDB::new(feature_extractor);

    db.insert("hello".to_string());
    db.insert("help".to_string());
    db.insert("halo".to_string());
    db.insert("world".to_string());

    let (total_collection, avg_size_ngrams, total_ngrams) = db.describe_collection();
    println!(
        "Database contains {} strings, average n-gram size {:.2}, total n-grams {}.",
        total_collection, avg_size_ngrams, total_ngrams
    );

    //println!("Complete DB State: {:?}", db); # FIX: db needs a fmt.debug implementation

    let query = "prepress";

    let query_features = db.feature_extractor.extract(query);
    let query_size = query_features.len();

    println!("Query size: {}", query_size);

    println!("Extracted features from query '{}':", query);
    for (feature, count) in &query_features {
        println!(" - Feature: '{}', Count: {}", feature, count);
    }
}

Trait Implementations§

Source§

impl Default for Cosine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SimilarityMeasure for Cosine

Source§

fn minimum_feature_size(&self, query_size: i64, alpha: f64) -> i64

Source§

fn maximum_feature_size( &self, _db: &impl SimStringDB, query_size: i64, alpha: f64, ) -> i64

Source§

fn similarity_score(&self, x: &[i64], y: &[i64]) -> f64

Source§

fn minimum_overlap( &self, query_size: i64, candidate_size: i64, alpha: f64, ) -> i64

Auto Trait Implementations§

§

impl Freeze for Cosine

§

impl RefUnwindSafe for Cosine

§

impl Send for Cosine

§

impl Sync for Cosine

§

impl Unpin for Cosine

§

impl UnwindSafe for Cosine

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.