pub struct Dictionary {
pub prefix_dictionary: Arc<PrefixDictionary>,
pub connection_cost_matrix: Arc<ConnectionCostMatrix>,
pub character_definition: CharacterDefinition,
pub unknown_dictionary: UnknownDictionary,
pub metadata: Metadata,
}Expand description
prefix_dictionary and connection_cost_matrix are Arc-wrapped so that
Dictionary::clone() is O(1) regardless of load method (embedded, mmap,
or plain filesystem read) – these two components dominate a dictionary’s
memory footprint (tens to hundreds of MB), and nothing in this codebase
mutates them after construction.
Fields§
§prefix_dictionary: Arc<PrefixDictionary>§connection_cost_matrix: Arc<ConnectionCostMatrix>§character_definition: CharacterDefinition§unknown_dictionary: UnknownDictionary§metadata: MetadataImplementations§
Source§impl Dictionary
impl Dictionary
Sourcepub fn unknown_word_details(&self, word_id: usize) -> Vec<&str>
pub fn unknown_word_details(&self, word_id: usize) -> Vec<&str>
Retrieve the detail fields (POS, etc.) for an unknown word entry.
pub fn word_details(&self, word_id: usize) -> Vec<&str>
Sourcepub fn load_from_path(dict_path: &Path) -> LinderaResult<Self>
pub fn load_from_path(dict_path: &Path) -> LinderaResult<Self>
Load dictionary from a directory containing dictionary files
Sourcepub fn load_from_path_with_options(
dict_path: &Path,
use_mmap: bool,
) -> LinderaResult<Self>
pub fn load_from_path_with_options( dict_path: &Path, use_mmap: bool, ) -> LinderaResult<Self>
Load dictionary from a directory with options
use_mmap (when the mmap feature is enabled) routes
connection_cost_matrix and prefix_dictionary through memory-mapped
reads instead of plain file reads. This does not make either
component lazily memory-resident at runtime: ConnectionCostMatrix
always eagerly decodes into an owned Vec<i16>, and
PrefixDictionary’s double-array trie (da) is always eagerly
deserialized into owned daachorse structures (only
PrefixDictionary’s vals_data/words_idx_data/words_data remain
genuinely mmap-backed and are read lazily at lookup time). metadata
and character_definition and unknown_dictionary are always
plain-read regardless of this flag. In short, use_mmap only avoids
the initial file-read syscall/allocation for the two components it
covers — it does not provide OS-level lazy paging for tokenization.
Separately, Dictionary::clone() is O(1) regardless of use_mmap,
since prefix_dictionary/connection_cost_matrix are Arc-wrapped.
Sourcepub fn save_to_path(&self, dict_path: &Path) -> LinderaResult<()>
pub fn save_to_path(&self, dict_path: &Path) -> LinderaResult<()>
Save dictionary to a directory
Trait Implementations§
Source§impl Clone for Dictionary
impl Clone for Dictionary
Source§fn clone(&self) -> Dictionary
fn clone(&self) -> Dictionary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Dictionary
impl RefUnwindSafe for Dictionary
impl Send for Dictionary
impl Sync for Dictionary
impl Unpin for Dictionary
impl UnsafeUnpin for Dictionary
impl UnwindSafe for Dictionary
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.