pub struct Predictor(_);
Expand description
Predictor created from the model.
Example 1: without tag prediction
use std::fs::File;
use vaporetto::{Model, Predictor, Sentence};
let f = File::open("../resources/model.bin").unwrap();
let model = Model::read(f).unwrap();
let predictor = Predictor::new(model, false).unwrap();
let mut s = Sentence::from_raw("まぁ社長は火星猫だ").unwrap();
predictor.predict(&mut s);
// s.fill_tags(); will panic!
let mut buf = String::new();
s.write_tokenized_text(&mut buf);
assert_eq!(
"まぁ 社長 は 火星 猫 だ",
buf,
);
Example 2: with tag prediction
Tag prediction requires crate feature tag-prediction
.
use std::fs::File;
use vaporetto::{Model, Predictor, Sentence};
let mut f = File::open("../resources/model.bin").unwrap();
let model = Model::read(f).unwrap();
let predictor = Predictor::new(model, true).unwrap();
let mut s = Sentence::from_raw("まぁ社長は火星猫だ").unwrap();
predictor.predict(&mut s);
s.fill_tags();
let mut buf = String::new();
s.write_tokenized_text(&mut buf);
assert_eq!(
"まぁ/名詞/マー 社長/名詞/シャチョー は/助詞/ワ 火星/名詞/カセー 猫/名詞/ネコ だ/助動詞/ダ",
buf,
);
Implementations§
source§impl Predictor
impl Predictor
sourcepub fn predict<'a>(&'a self, sentence: &mut Sentence<'_, 'a>)
pub fn predict<'a>(&'a self, sentence: &mut Sentence<'_, 'a>)
Predicts word boundaries of the given sentence. If necessary, this function also prepares for predicting tags.
sourcepub fn serialize_to_vec(&self) -> Result<Vec<u8>>
pub fn serialize_to_vec(&self) -> Result<Vec<u8>>
Serializes the predictor into a Vec.
sourcepub unsafe fn deserialize_from_slice_unchecked(
data: &[u8]
) -> Result<(Self, &[u8])>
pub unsafe fn deserialize_from_slice_unchecked( data: &[u8] ) -> Result<(Self, &[u8])>
Deserializes a predictor from a given slice and returns a tuple of the predictor and the remaining slice.
Safety
The given data must be a correct predictor exported by Predictor::serialize_to_vec()
function.