pub struct Model { /* private fields */ }
Expand description
Truecasing model.
See crate documentation for examples.
Implementations§
source§impl Model
impl Model
sourcepub fn deserialize(bytes: &[u8]) -> Result<Self, ModelLoadingError>
pub fn deserialize(bytes: &[u8]) -> Result<Self, ModelLoadingError>
Load a previously serialized model from a byte slice
Use this method if you want to bundle the model into your binary instead of supplying it as a separate resource.
sourcepub fn serialize(&self) -> Result<Vec<u8>, ModelSavingError>
pub fn serialize(&self) -> Result<Vec<u8>, ModelSavingError>
Serialize the model into a vector of bytes
sourcepub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, ModelLoadingError>
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, ModelLoadingError>
Load a previously saved model from a file
sourcepub fn save_to_file(
&self,
path: impl AsRef<Path>
) -> Result<(), ModelSavingError>
pub fn save_to_file( &self, path: impl AsRef<Path> ) -> Result<(), ModelSavingError>
Save this model into a file with the given filename. The format is simple JSON right now.
sourcepub fn truecase(&self, sentence: &str) -> String
pub fn truecase(&self, sentence: &str) -> String
Restore word casings in a sentence.
This will capitalize the first letter of the sentence if necessary.
ⓘ
assert_eq!(model.truecase("sample shakespeare text"), "Sample Shakespeare text");
assert_eq!(model.truecase("iphones get sold quickly"), "iPhones get sold quickly");
sourcepub fn truecase_phrase(&self, phrase: &str) -> String
pub fn truecase_phrase(&self, phrase: &str) -> String
Restore word casings in a phrase (sentence fragment).
ⓘ
assert_eq!(model.truecase_phrase("sample shakespeare text"), "sample Shakespeare text");
assert_eq!(model.truecase_phrase("iphones get sold quickly"), "iPhones get sold quickly");
Trait Implementations§
source§impl<'de> Deserialize<'de> for Model
impl<'de> Deserialize<'de> for Model
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
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