pub struct Engine { /* private fields */ }Expand description
The engine: a registry plus the common workflows.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn with_registry(registry: Registry) -> Self
pub fn with_registry(registry: Registry) -> Self
An engine around a caller-built registry.
pub fn registry(&self) -> &Registry
Sourcepub fn registry_mut(&mut self) -> &mut Registry
pub fn registry_mut(&mut self) -> &mut Registry
Add algorithms or adapters without touching KUTE’s own crates.
Sourcepub fn train(
&self,
algorithm: &str,
adapter: &str,
adapter_config: &AdapterConfig,
documents: &[Vec<u8>],
config: &TrainingConfig,
) -> Result<Vocabulary>
pub fn train( &self, algorithm: &str, adapter: &str, adapter_config: &AdapterConfig, documents: &[Vec<u8>], config: &TrainingConfig, ) -> Result<Vocabulary>
Train algorithm on raw documents read through adapter.
The adapter and its options are recorded in the vocabulary, so encoding and decoding later go through the same adapter without being told.
Sourcepub fn train_stream<'a>(
&self,
algorithm: &str,
adapter: &str,
adapter_config: &AdapterConfig,
config: &TrainingConfig,
documents: &mut dyn FnMut() -> Result<Option<Cow<'a, Vec<u8>>>>,
) -> Result<Vocabulary>
pub fn train_stream<'a>( &self, algorithm: &str, adapter: &str, adapter_config: &AdapterConfig, config: &TrainingConfig, documents: &mut dyn FnMut() -> Result<Option<Cow<'a, Vec<u8>>>>, ) -> Result<Vocabulary>
Train on documents that are produced one at a time. Only the document being read is held, so a corpus larger than memory can be trained on as long as each document fits.
Sourcepub fn train_paths(
&self,
algorithm: &str,
adapter: &str,
adapter_config: &AdapterConfig,
paths: &[PathBuf],
config: &TrainingConfig,
) -> Result<Vocabulary>
pub fn train_paths( &self, algorithm: &str, adapter: &str, adapter_config: &AdapterConfig, paths: &[PathBuf], config: &TrainingConfig, ) -> Result<Vocabulary>
Train on files. A directory is read recursively, in sorted path order.
Sourcepub fn tokenizer(&self, vocabulary: Vocabulary) -> Result<Box<dyn Tokenizer>>
pub fn tokenizer(&self, vocabulary: Vocabulary) -> Result<Box<dyn Tokenizer>>
A tokenizer with vocabulary installed.
Sourcepub fn encode_raw(
&self,
tokenizer: &dyn Tokenizer,
raw: &[u8],
) -> Result<TokenSequence>
pub fn encode_raw( &self, tokenizer: &dyn Tokenizer, raw: &[u8], ) -> Result<TokenSequence>
Raw bytes to tokens, through the vocabulary’s adapter.
Sourcepub fn encode_raw_open(
&self,
tokenizer: &dyn Tokenizer,
raw: &[u8],
policy: UnknownPolicy,
) -> Result<TokenSequence>
pub fn encode_raw_open( &self, tokenizer: &dyn Tokenizer, raw: &[u8], policy: UnknownPolicy, ) -> Result<TokenSequence>
Raw bytes to tokens under an explicit policy for unknown symbols.
Sourcepub fn decode_raw_bounded(
&self,
tokenizer: &dyn Tokenizer,
tokens: &TokenSequence,
max_units: u64,
) -> Result<Vec<u8>>
pub fn decode_raw_bounded( &self, tokenizer: &dyn Tokenizer, tokens: &TokenSequence, max_units: u64, ) -> Result<Vec<u8>>
Like Engine::decode_raw, but refuses before decoding when the
sequence would expand to more than max_units bytes or symbols.
Sourcepub fn decode_raw(
&self,
tokenizer: &dyn Tokenizer,
tokens: &TokenSequence,
) -> Result<Vec<u8>>
pub fn decode_raw( &self, tokenizer: &dyn Tokenizer, tokens: &TokenSequence, ) -> Result<Vec<u8>>
Tokens back to raw bytes, through the vocabulary’s adapter.
Sourcepub fn encode_batch(
&self,
tokenizer: &dyn Tokenizer,
documents: &[Vec<u8>],
) -> Result<Vec<TokenSequence>>
pub fn encode_batch( &self, tokenizer: &dyn Tokenizer, documents: &[Vec<u8>], ) -> Result<Vec<TokenSequence>>
Encode many documents in parallel. Output order matches input order.
Sourcepub fn verify(&self, vocabulary: &Vocabulary) -> Result<VerifyReport>
pub fn verify(&self, vocabulary: &Vocabulary) -> Result<VerifyReport>
Run the vocabulary’s embedded test vectors: each input must encode to the recorded ids and decode back to the input.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Engine
impl !UnwindSafe for Engine
impl Forget for Engine
impl Freeze for Engine
impl Move for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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