Skip to main content

GramDb

Struct GramDb 

Source
pub struct GramDb { /* private fields */ }
Expand description

一条 .gram 镜像:mmap 只读视图 + 双数组单元的字节区间。

Implementations§

Source§

impl GramDb

Source

pub fn load(path: &Path) -> Option<GramDb>

文件缺失、过短、魔数错误或数组越界时返回 None;调用方按无模型运行, 与缺少 msime-bigram.bin 时的处理一致。

Source

pub fn shared(path: &Path) -> Option<Arc<GramDb>>

按路径共享模型实例;缺失或非法的文件同样被记住(None),不会在每次 set_sentence_association 后重复探测。与 NgramTable::shared 同一范式。

Source

pub fn evict_shared(path: &Path)

摘掉指定路径的缓存引用(设置侧删除模型包后调用);仍被会话持有的实例 由 Arc 兜底,最后一个引用松开才真正 unmap,被删的 .gram 随之可物理删除。 资源包卸载通过 Host API 调用;活跃会话的引用仍保留到会话重建。

Source

pub fn query( &self, context: &str, word: &str, is_rear: bool, config: &GramConfig, ) -> f64

Octagram::Query。context、word 都是原始 UTF-8;is_rear 对应句尾 词的「词+$」rear 项。返回值是自然对数域的搭配强度,未命中为 config.non_collocation_penalty。

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.