diff options
Diffstat (limited to 'libs/db/src/inference.rs')
| -rw-r--r-- | libs/db/src/inference.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/libs/db/src/inference.rs b/libs/db/src/inference.rs index f2cbabf..25415df 100644 --- a/libs/db/src/inference.rs +++ b/libs/db/src/inference.rs @@ -5,7 +5,7 @@ use crate::{ use hypher::{Lang, hyphenate}; use itertools::Itertools; use log::*; -use std::{iter, ops::Add}; +use std::{iter, ops::Add, sync::Arc}; use thiserror::Error; use unicode_segmentation::UnicodeSegmentation; @@ -15,13 +15,14 @@ pub enum InferenceError { TrieError(), #[error("the matched value wasn't in the dictionary")] NotInDictionary(), - #[error("failt to cut the word")] + #[error("failed to cut the word")] WordCutError(), } -pub struct Inference<'a> { - inference_service: Box<dyn InferenceService<InferenceError>>, - save: Save<'a>, +#[derive(Debug, Clone)] +pub struct Inference { + inference_service: Arc<dyn InferenceService<InferenceError>>, + save: Save, } pub struct TLang(whatlang::Lang); @@ -62,7 +63,7 @@ impl Into<Lang> for TLang { } } -impl Inference<'_> { +impl Inference { fn matches(&self, source: &str, complete: &str) -> bool { let source_chars: Vec<&str> = source.graphemes(true).collect(); let complete_chars: Vec<&str> = complete.graphemes(true).collect(); @@ -79,10 +80,10 @@ impl Inference<'_> { return true; } - pub fn new<'a>( - inference_service: Box<dyn InferenceService<InferenceError>>, - save: Save<'a>, - ) -> Inference<'a> { + pub fn new( + inference_service: Arc<dyn InferenceService<InferenceError>>, + save: Save, + ) -> Inference { return Inference { inference_service, save, @@ -112,8 +113,7 @@ impl Inference<'_> { let completion = self .save .trie - .random_starting_with(phonemes.clone()) - .ok_or_else(InferenceError::TrieError)?; + .random_starting_with(phonemes.clone()).unwrap(); // store the found word let initial = cprefix.add(&completion.0); |
