pub struct Translator { /* private fields */ }Expand description
The main Translator struct that provides the translate() API.
Implementations§
Source§impl Translator
impl Translator
Sourcepub fn new(config: TranslatorConfig) -> NlResult<Self>
pub fn new(config: TranslatorConfig) -> NlResult<Self>
Create a new Translator with the given configuration.
§Errors
Returns an error if the classifier fails to load (when classifier feature is enabled).
Sourcepub fn load_default() -> NlResult<Self>
pub fn load_default() -> NlResult<Self>
Sourcepub fn translate(&mut self, input: &str) -> TranslationResponse
pub fn translate(&mut self, input: &str) -> TranslationResponse
Translate a natural language query to a sqry command.
§Arguments
input- The natural language query to translate
§Returns
A TranslationResponse indicating:
Execute: High confidence, safe to run automaticallyConfirm: Medium confidence, ask user to confirmDisambiguate: Low confidence, need user clarificationReject: Cannot translate safely
§Note
This method requires &mut self when the classifier feature is enabled.
Sourcepub fn translation_count(&self) -> u64
pub fn translation_count(&self) -> u64
Get translation count.
Sourcepub fn cache_stats(&self) -> Option<CacheStats>
pub fn cache_stats(&self) -> Option<CacheStats>
Get cache statistics.
Returns None if caching is disabled.
Sourcepub fn cache_hit_rate(&self) -> Option<f64>
pub fn cache_hit_rate(&self) -> Option<f64>
Get cache hit rate (0.0-1.0).
Returns None if caching is disabled.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the translation cache.
Does nothing if caching is disabled.
Auto Trait Implementations§
impl !Freeze for Translator
impl !RefUnwindSafe for Translator
impl Send for Translator
impl Sync for Translator
impl Unpin for Translator
impl UnsafeUnpin for Translator
impl !UnwindSafe for Translator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more