pub struct CoreTokenizer { /* private fields */ }Expand description
Tokenizer that orchestrates tokenization on behalf of the bindings.
Internally holds a reusable AnalysisWorker behind a Mutex, so
every call reuses the Viterbi lattice and scratch buffers instead of
reallocating them (bindings keep one long-lived CoreTokenizer
instance, which makes this the natural reuse point). Mutex — rather
than RefCell — keeps CoreTokenizer: Send + Sync, which the Python
(pyo3) and Node.js (napi) class wrappers require. All binding runtimes
call tokenize while effectively single-threaded (GIL / one JS thread /
request scope), so the lock is uncontended in practice.
Returns owned TokenViews so the bindings never handle borrowed
lindera tokens directly.
Implementations§
Source§impl CoreTokenizer
impl CoreTokenizer
Sourcepub fn from_segmenter(
mode: &str,
dictionary: Dictionary,
user_dictionary: Option<UserDictionary>,
) -> CoreResult<Self>
pub fn from_segmenter( mode: &str, dictionary: Dictionary, user_dictionary: Option<UserDictionary>, ) -> CoreResult<Self>
Builds a tokenizer from segmenter parts, parsing mode from a string.
Sourcepub fn from_tokenizer(tokenizer: Tokenizer) -> Self
pub fn from_tokenizer(tokenizer: Tokenizer) -> Self
Wraps an already-built lindera Tokenizer, consuming it into the
internal reusable worker (no user-dictionary copy).
Sourcepub fn tokenize(&self, text: &str) -> CoreResult<Vec<TokenView>>
pub fn tokenize(&self, text: &str) -> CoreResult<Vec<TokenView>>
Tokenizes text, returning owned TokenViews.
Reuses the internal worker’s buffers across calls; output is identical to tokenizing with a fresh lattice.
Sourcepub fn tokenize_surfaces(&self, text: &str) -> CoreResult<Vec<SurfaceView>>
pub fn tokenize_surfaces(&self, text: &str) -> CoreResult<Vec<SurfaceView>>
Tokenizes text, returning surface-only views (SurfaceView)
without materializing any morphological details.
This is the fast path for wakati-style callers: it skips the
per-token details loading and string materialization that
CoreTokenizer::tokenize pays (~14 allocations per IPADIC token
down to ~1), while reusing the internal worker’s buffers like the
other methods. Token filters configured on the tokenizer still run
(some may load details internally); the saving on this path is the
FFI-side materialization.
Sourcepub fn tokenize_nbest(
&self,
text: &str,
n: usize,
unique: bool,
cost_threshold: Option<i64>,
) -> CoreResult<Vec<(Vec<TokenView>, i64)>>
pub fn tokenize_nbest( &self, text: &str, n: usize, unique: bool, cost_threshold: Option<i64>, ) -> CoreResult<Vec<(Vec<TokenView>, i64)>>
Tokenizes text and returns the N-best results as (tokens, cost) pairs.
Reuses the internal worker’s buffers across calls, like
CoreTokenizer::tokenize.
Auto Trait Implementations§
impl !Freeze for CoreTokenizer
impl RefUnwindSafe for CoreTokenizer
impl Send for CoreTokenizer
impl Sync for CoreTokenizer
impl Unpin for CoreTokenizer
impl UnsafeUnpin for CoreTokenizer
impl UnwindSafe for CoreTokenizer
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> 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.