Expand description
The Chewing (酷音) intelligent phonetic input method library.
This crate provides the core algorithms and facilities that can be used to implement input methods and manipulate user dictionaries.
§Behavior
The Editor implements the behavior of the Chewing input method. Chewing is a bopomofo phonetics input method that can convert keystrokes to Zhuyin/Bopomofo and then to Chinese characters. The state machine powering the input method can detect the current input context and translate the input to symbols, latin characters, or Chinese characters. The Editor also has an option that is enabled by default to auto-learn new phrases from users’ input to provide more personalized intelligence.
use chewing::editor::{BasicEditor, Editor};
use chewing::editor::keyboard::{KeyboardLayout, KeyCode, Qwerty};
let keyboard = Qwerty;
let mut editor = Editor::chewing()?;
editor.process_keyevent(keyboard.map(KeyCode::D));
editor.process_keyevent(keyboard.map(KeyCode::J));
editor.process_keyevent(keyboard.map(KeyCode::N4));
editor.process_keyevent(keyboard.map(KeyCode::Down));
editor.process_keyevent(keyboard.map(KeyCode::N3));
assert_eq!("酷", editor.display());
§Dictionary Files
Chewing requires dictionary files at runtime. By default SystemDictionaryLoader will search dictionaries from pre-configured system paths. See the path module level document for the search order.
chewing-cli
can be used to compile the dictionary files.
cargo install chewing-cli
cd data
chewing-cli init-database -t trie tsi.src tsi.dat
chewing-cli init-database -t trie word.src word.dat
After the tsi.dat
and word.dat
files are generated, copy them to
/usr/share/libchewing
or corresponding path on other platforms. They can
also be placed at user’s home directory $HOME/.config/chewing
which has
higher priority than the system path.
Other required files swkb.dat
and symbols.dat
can be copied directly to
the dictionary folder.
Modules§
- conversion
- Algorithms to convert syllables to Chinese characters.
- dictionary
- Systems and user phrase dictionaries.
- editor
- Abstract input method editors.
- path
- Types and functions related to file system path operations.
- zhuyin
- Chinese syllables and bopomofo phonetic symbols.
Macros§
- syl
- Builds a syllable from bopomofos.