pub struct Registry { /* private fields */ }Expand description
Run-time table of algorithms and adapters.
Implementations§
Source§impl Registry
impl Registry
pub fn new() -> Self
Sourcepub fn register_algorithm<F>(&mut self, name: &str, factory: F) -> Result<()>
pub fn register_algorithm<F>(&mut self, name: &str, factory: F) -> Result<()>
Register a tokenization algorithm under name. A name can be taken
once: a second registration is an error, so one plugin cannot quietly
change what another’s vocabularies mean. Use
Registry::replace_algorithm to override on purpose.
Sourcepub fn replace_algorithm<F>(&mut self, name: &str, factory: F)
pub fn replace_algorithm<F>(&mut self, name: &str, factory: F)
Register or replace the algorithm under name.
Sourcepub fn register_adapter<F>(&mut self, name: &str, factory: F) -> Result<()>
pub fn register_adapter<F>(&mut self, name: &str, factory: F) -> Result<()>
Register an adapter under name. Like algorithms, a name can be
taken once.
Sourcepub fn replace_adapter<F>(&mut self, name: &str, factory: F)
pub fn replace_adapter<F>(&mut self, name: &str, factory: F)
Register or replace the adapter under name.
Sourcepub fn tokenizer(&self, name: &str) -> Result<Box<dyn Tokenizer>>
pub fn tokenizer(&self, name: &str) -> Result<Box<dyn Tokenizer>>
A fresh, untrained tokenizer for name.
pub fn adapter(&self, name: &str) -> Result<Box<dyn ModalityAdapter>>
Sourcepub fn tokenizer_for(
&self,
vocabulary: Vocabulary,
) -> Result<Box<dyn Tokenizer>>
pub fn tokenizer_for( &self, vocabulary: Vocabulary, ) -> Result<Box<dyn Tokenizer>>
A tokenizer with vocabulary installed, chosen by the manifest.
A tokenizer with vocabulary installed.
This is the sealed boundary of the runtime. A Vocabulary value is
plain data with public fields, and its digest() reports what was
recorded; code may have changed the content since. What a tokenizer
returned from here holds cannot be changed (it hands out only shared
references), and it is checked here, whatever the algorithm’s own
load did: it carries a digest, and that digest is the hash of its
content. So tokenizer.vocabulary().digest() always names the
vocabulary that is doing the encoding.