Skip to main content

RomanizationMap

Struct RomanizationMap 

Source
pub struct RomanizationMap(/* private fields */);
Expand description

A Thai-word → RTGS-romanization lookup table.

Built from tab-separated data via RomanizationMap::from_tsv. Lookup is O(log n) via BTreeMap.

Implementations§

Source§

impl RomanizationMap

Source

pub fn builtin() -> Self

Load the built-in RTGS romanization table.

Source

pub fn from_tsv(data: &str) -> Self

Parse a tab-separated romanization table.

Format: thai_word\trtgs_romanization — one entry per line. Lines beginning with # and blank lines are skipped. For duplicate keys, the last entry wins.

Source

pub fn romanize(&self, word: &str) -> Option<&str>

Look up the RTGS romanization for a pre-segmented Thai word.

Returns None if the word is not in the table. The returned &str borrows from the map — zero-copy for hits.

§Example
use kham_core::romanizer::RomanizationMap;

let map = RomanizationMap::from_tsv("กิน\tkin\n");
assert_eq!(map.romanize("กิน"), Some("kin"));
assert_eq!(map.romanize("xyz"), None);
Source

pub fn romanize_or_raw<'a>(&'a self, word: &'a str) -> &'a str

Return the RTGS romanization for word, or word unchanged if not found.

§Example
use kham_core::romanizer::RomanizationMap;

let map = RomanizationMap::from_tsv("กิน\tkin\n");
assert_eq!(map.romanize_or_raw("กิน"), "kin");
assert_eq!(map.romanize_or_raw("xyz"), "xyz");
Source

pub fn romanize_tokens(&self, tokens: &[&str]) -> Vec<String>

Romanize a slice of pre-segmented token strings.

Returns a Vec<String> aligned 1:1 with the input slice. Tokens not found in the table are returned unchanged (same behaviour as romanize_or_raw).

§Example
use kham_core::romanizer::RomanizationMap;

let map = RomanizationMap::from_tsv("กิน\tkin\nปลา\tpla\n");
let out = map.romanize_tokens(&["กิน", "ปลา"]);
assert_eq!(out, vec!["kin", "pla"]);
Source

pub fn len(&self) -> usize

Number of entries in the map.

Source

pub fn is_empty(&self) -> bool

Return true if the map has no entries.

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.