sudachi::dic::grammar

Struct Grammar

source
pub struct Grammar<'a> {
    pub pos_list: Vec<Vec<String>>,
    pub storage_size: usize,
    pub character_category: CharacterCategory,
    /* private fields */
}
Expand description

Dictionary grammar

Contains part_of_speech list and connection cost map. It also holds character category.

Fields§

§pos_list: Vec<Vec<String>>§storage_size: usize§character_category: CharacterCategory

The mapping from character to character_category_type

Implementations§

source§

impl<'a> Grammar<'a>

source

pub const INHIBITED_CONNECTION: i16 = 32_767i16

source

pub const BOS_PARAMETER: (i16, i16, i16) = _

source

pub const EOS_PARAMETER: (i16, i16, i16) = _

source

pub fn parse(buf: &[u8], offset: usize) -> SudachiResult<Grammar<'_>>

Creates a Grammar from dictionary bytes

buf: reference to the dictionary bytes offset: offset to the grammar section in the buf

source

pub fn connect_cost(&self, left_id: i16, right_id: i16) -> i16

Returns connection cost of nodes

left_id: right_id of left node right_id: left_if of right node

source

pub fn conn_matrix(&self) -> &ConnectionMatrix<'_>

source

pub fn set_character_category(&mut self, character_category: CharacterCategory)

Sets character category

This is the only way to set character category. Character category will be a empty map by default.

source

pub fn set_connect_cost(&mut self, left_id: i16, right_id: i16, cost: i16)

Sets connect cost for a specific pair of ids

left_id: right_id of left node right_id: left_if of right node

source

pub fn get_part_of_speech_id<S>(&self, pos1: &[S]) -> Option<u16>
where S: AsRef<str>,

Returns a pos_id of given pos in the grammar

source

pub fn register_pos<S>(&mut self, pos: &[S]) -> SudachiResult<u16>
where S: AsRef<str> + ToString,

source

pub fn pos_components(&self, pos_id: u16) -> &[String]

Gets POS components for POS ID. Panics if out of bounds.

source

pub fn merge(&mut self, other: Grammar<'_>)

Merge a another grammar into this grammar

Only pos_list is merged

Auto Trait Implementations§

§

impl<'a> Freeze for Grammar<'a>

§

impl<'a> RefUnwindSafe for Grammar<'a>

§

impl<'a> Send for Grammar<'a>

§

impl<'a> Sync for Grammar<'a>

§

impl<'a> Unpin for Grammar<'a>

§

impl<'a> UnwindSafe for Grammar<'a>

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.