1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// #![deny(missing_docs)]
//! 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][editor::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.
//!
//! ```rust,no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use chewing::editor::{BasicEditor, Editor};
//! use chewing::input::{keycode, keysym, KeyboardEvent};
//! use chewing::input::keymap::{map_ascii, QWERTY_MAP};
//! use chewing::dictionary::DEFAULT_DICT_NAMES;
//!
//! let mut editor = Editor::chewing(None, None, &DEFAULT_DICT_NAMES);
//!
//! editor.process_keyevent(map_ascii(&QWERTY_MAP, b'd'));
//! editor.process_keyevent(map_ascii(&QWERTY_MAP, b'j'));
//! editor.process_keyevent(map_ascii(&QWERTY_MAP, b'4'));
//! editor.process_keyevent(KeyboardEvent::builder()
//! .code(keycode::KEY_DOWN)
//! .ksym(keysym::SYM_DOWN)
//! .build());
//! editor.process_keyevent(map_ascii(&QWERTY_MAP, b'3'));
//!
//! assert_eq!("酷", editor.display());
//! # Ok(()) }
//! ```
//!
//! # Dictionary Files
//!
//! Chewing requires dictionary files at runtime. By default
//! [SystemDictionaryLoader][dictionary::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.
//!
//! ```sh
//! 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.