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>
impl<'a> Grammar<'a>
pub const INHIBITED_CONNECTION: i16 = 32_767i16
pub const BOS_PARAMETER: (i16, i16, i16) = _
pub const EOS_PARAMETER: (i16, i16, i16) = _
sourcepub fn parse(buf: &[u8], offset: usize) -> SudachiResult<Grammar<'_>>
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
sourcepub fn connect_cost(&self, left_id: i16, right_id: i16) -> i16
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
pub fn conn_matrix(&self) -> &ConnectionMatrix<'_>
sourcepub fn set_character_category(&mut self, character_category: CharacterCategory)
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.
sourcepub fn set_connect_cost(&mut self, left_id: i16, right_id: i16, cost: i16)
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
sourcepub fn get_part_of_speech_id<S>(&self, pos1: &[S]) -> Option<u16>
pub fn get_part_of_speech_id<S>(&self, pos1: &[S]) -> Option<u16>
Returns a pos_id of given pos in the grammar
pub fn register_pos<S>(&mut self, pos: &[S]) -> SudachiResult<u16>
sourcepub fn pos_components(&self, pos_id: u16) -> &[String]
pub fn pos_components(&self, pos_id: u16) -> &[String]
Gets POS components for POS ID. Panics if out of bounds.
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> 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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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