Skip to main content

SpellChecker

Struct SpellChecker 

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

Thai spell checker using edit distance and lk82 phonetic ranking.

Candidates are drawn from the built-in 62k-word dictionary and filtered to edit distance ≤ 2. Phonetically similar candidates (matching lk82 code) are ranked above purely orthographic matches.

§Examples

use kham_core::spell::SpellChecker;

let checker = SpellChecker::builtin();

// Misspelled word — expect near-miss suggestions
let suggestions = checker.suggestions("กานข้าว", 5);
assert!(suggestions.iter().all(|s| s.edit_distance <= 2));

Correctly spelled word — edit_distance 0 if it is in the dictionary:

use kham_core::spell::SpellChecker;

let checker = SpellChecker::builtin();
let suggestions = checker.suggestions("กิน", 10);
assert!(suggestions.iter().any(|s| s.word == "กิน" && s.edit_distance == 0));

Implementations§

Source§

impl SpellChecker

Source

pub fn builtin() -> Self

Create a spell checker backed by the built-in dictionary and TNC frequency table.

Construction loads the TNC frequency map (~106k entries) — reuse the returned instance rather than calling builtin() on every query.

§Examples
use kham_core::spell::SpellChecker;

let checker = SpellChecker::builtin();
assert!(!checker.suggestions("สวัดสี", 5).is_empty());
Source

pub fn suggestions(&self, word: &str, max_n: usize) -> Vec<Suggestion>

Return up to max_n spelling suggestions for word.

Only candidates with edit distance ≤ 2 are returned. Results are sorted by phonetic match (lk82), then edit distance, then TNC frequency.

Returns an empty Vec when word is empty or max_n is zero.

§Examples
use kham_core::spell::SpellChecker;

let checker = SpellChecker::builtin();

// Empty input → no suggestions
assert!(checker.suggestions("", 5).is_empty());

// max_n = 0 → no suggestions
assert!(checker.suggestions("กาน", 0).is_empty());

// Results respect the distance threshold
let suggs = checker.suggestions("กิน", 10);
assert!(suggs.iter().all(|s| s.edit_distance <= 2));

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.