pub struct Dictionary {
pub prefix_dictionary: Arc<PrefixDictionary>,
pub connection_cost_matrix: Arc<ConnectionCostMatrix>,
pub character_definition: Arc<CharacterDefinition>,
pub unknown_dictionary: Arc<UnknownDictionary>,
pub metadata: Arc<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: Arc<CharacterDefinition>§unknown_dictionary: Arc<UnknownDictionary>§metadata: Arc<Metadata>Implementations§
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.
When the mmap feature is compiled in, the connection-cost matrix
and word list are routed through memory-mapped reads by default
(#879); use Dictionary::load_from_path_with_options with
use_mmap = false to force eager reads.
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. What that buys differs per
component:
ConnectionCostMatrixreads its costs in place, with no copy and no anonymous memory:matrix.mtxalready stores the values in the in-memory layout, and an mmap base is page-aligned, so the payload can be viewed as[i16]directly. Loading it is O(1) and the pages are faulted in lazily during tokenization. (Costs are also borrowed from a plain read’s buffer whenever it happens to bei16-aligned; the alignment is only guaranteed under mmap and for embedded data.)PrefixDictionary’svals_data/words_idx_data/words_dataare likewise mmap-backed and read lazily at lookup time.PrefixDictionary’s double-array trie (da) is still eagerly deserialized into owned daachorse structures, so for that componentuse_mmaponly avoids the initial file-read syscall/allocation.
metadata, character_definition and unknown_dictionary are always
plain-read regardless of this flag. 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.