simstring_rust::database

Struct HashDB

Source
pub struct HashDB<TExtractor>
where TExtractor: FeatureExtractor,
{ pub feature_extractor: TExtractor, pub string_collection: Vec<String>, pub string_size_map: HashMap<usize, HashSet<String>>, pub string_feature_map: HashMap<usize, HashMap<(String, i32), HashSet<String>>>, pub lookup_cache: HashMap<(usize, (String, i32)), HashSet<String>>, }

Fields§

§feature_extractor: TExtractor§string_collection: Vec<String>§string_size_map: HashMap<usize, HashSet<String>>§string_feature_map: HashMap<usize, HashMap<(String, i32), HashSet<String>>>§lookup_cache: HashMap<(usize, (String, i32)), HashSet<String>>

Implementations§

Source§

impl<TExtractor> HashDB<TExtractor>
where TExtractor: FeatureExtractor,

Source

pub fn new(feature_extractor: TExtractor) -> Self

Examples found in repository?
examples/basic_usage.rs (line 13)
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);
    }
}
Source

pub fn lookup_feature_set_by_size_feature( &mut self, size: usize, feature: &(String, i32), ) -> &HashSet<String>

Trait Implementations§

Source§

impl<TExtractor> SimStringDB for HashDB<TExtractor>
where TExtractor: FeatureExtractor,

Auto Trait Implementations§

§

impl<TExtractor> Freeze for HashDB<TExtractor>
where TExtractor: Freeze,

§

impl<TExtractor> RefUnwindSafe for HashDB<TExtractor>
where TExtractor: RefUnwindSafe,

§

impl<TExtractor> Send for HashDB<TExtractor>
where TExtractor: Send,

§

impl<TExtractor> Sync for HashDB<TExtractor>
where TExtractor: Sync,

§

impl<TExtractor> Unpin for HashDB<TExtractor>
where TExtractor: Unpin,

§

impl<TExtractor> UnwindSafe for HashDB<TExtractor>
where TExtractor: 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.