Skip to main content

msime_engine/cantonese/
mod.rs

1//! Cantonese input in toneless Jyutping, read against `msime-cantonese.db` (`language_dictionary`). Output is Traditional as stored, and nothing is learned.
2
3pub mod scheme;
4pub mod shuangpin;
5pub mod syllable;
6
7use std::path::Path;
8use std::sync::Arc;
9
10pub use scheme::{CantoneseCandidate, CantoneseScheme};
11pub use syllable::Inventory;
12
13use crate::error::Result;
14use crate::language_dictionary::{self, LanguageDictionary};
15
16/// The non-letter keys the scheme spells with while composing: `'` is an explicit syllable boundary.
17pub const SPELLING_SYMBOLS_COMPOSING: &str = "'";
18
19/// `msime-cantonese.db` opened for one activation of the scheme, with its syllable inventory read once.
20pub struct CantoneseDictionary {
21    dictionary: LanguageDictionary,
22    inventory: Arc<Inventory>,
23}
24
25impl CantoneseDictionary {
26    /// Opens `path` read-only; fails as `language_dictionary::open_read_only` does, which the caller reports as the scheme being unavailable.
27    pub fn open(path: &Path) -> Result<Self> {
28        let dictionary = language_dictionary::open_read_only(path)?;
29        let inventory = Arc::new(Inventory::load(&dictionary)?);
30        Ok(Self {
31            dictionary,
32            inventory,
33        })
34    }
35
36    pub fn dictionary(&self) -> &LanguageDictionary {
37        &self.dictionary
38    }
39
40    /// The inventory a `CantoneseScheme` segments against.
41    pub fn inventory(&self) -> Arc<Inventory> {
42        Arc::clone(&self.inventory)
43    }
44}