pub struct Model<B> { /* private fields */ }Expand description
A model file, read in place.
B is what holds the bytes: a &[u8], a Vec<u8>, or the memory map of
the caller. A model is made once and used from any number of threads.
See the module for the format and an example.
Implementations§
Source§impl<B: AsRef<[u8]>> Model<B>
impl<B: AsRef<[u8]>> Model<B>
Sourcepub fn new(bytes: B) -> Result<Self>
pub fn new(bytes: B) -> Result<Self>
Reads a model file.
The whole file is checked here, once: afterwards nothing of it is parsed again and nothing can fail.
§Arguments
bytes- The bytes of the file, asModelBuilder::to_byteswrote them.
§Returns
The model, or Error::Model for bytes that are not a model file
of this version: another magic number or version, an unknown kind of
part or the same kind twice, parts that are not one after the other
up to the end of the bytes, bytes that end early, or a part whose
content is not what the format says.
Sourcepub fn dictionary(&self) -> &str
pub fn dictionary(&self) -> &str
The name of the dictionary the model is for.
§Returns
The name, as it was given to ModelBuilder::new: ipadic.
Sourcepub fn check_dictionary(&self, name: &str) -> Result<()>
pub fn check_dictionary(&self, name: &str) -> Result<()>
Checks that the model is for a dictionary.
A model depends on the feature columns and on the segmentation of its dictionary: on the morphemes of another one it gives wrong answers without an error. What knows the dictionary of its morphemes calls this before it analyzes them.
Morphemes with fewer feature columns than the schema of the model
reads are refused when they are analyzed
(Schema::check); morphemes of another dictionary that are wide
enough are not, which is what this check is for.
§Arguments
name- The name of the dictionary of the morphemes.
§Returns
Ok(()) when it is the name of the model, or
Error::Dictionary.
Sourcepub fn chunker(&self) -> Option<Chunker<ChunkerPart<'_>>>
pub fn chunker(&self) -> Option<Chunker<ChunkerPart<'_>>>
The chunker of the model.
§Returns
A chunker that reads its weights on the bytes of the model, or
None when the file has no chunker part.
Sourcepub fn parser(&self) -> Option<Parser<ParserPart<'_>>>
pub fn parser(&self) -> Option<Parser<ParserPart<'_>>>
The parser of the model.
§Returns
A parser whose classifier reads its weights on the bytes of the
model, or None when the file has no parser part.
Sourcepub fn analyze<M: Morpheme>(&self, morphemes: &[M]) -> Result<Vec<Bunsetsu>>
pub fn analyze<M: Morpheme>(&self, morphemes: &[M]) -> Result<Vec<Bunsetsu>>
Analyzes a sentence: segments its morphemes into bunsetsu with the chunker of the model, and finds the head of each with its parser.
To analyze many sentences, take Model::chunker and
Model::parser once and use them for each: this makes both for
every call.
§Arguments
morphemes- The morphemes of the sentence.
§Returns
The bunsetsu with their heads, as Parser::parse gives them; none
for an empty sentence. Error::Model when the file has no chunker
or no parser, and Error::Dictionary for a morpheme with fewer
feature columns than the schema reads.