Skip to main content

Model

Struct Model 

Source
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>

Source

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
§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.

Source

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.

Source

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.

Source

pub fn schema(&self) -> &Schema

The schema of the dictionary the model is for.

§Returns

The schema.

Source

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.

Source

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.

Source

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.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

The bytes of the file.

§Returns

The bytes the model was made from.

Trait Implementations§

Source§

impl<B: Clone> Clone for Model<B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: AsRef<[u8]>> Debug for Model<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Writes what the model is for and what it has, not its bytes.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.