Skip to content

Commit

Permalink
feat(capi): load embedded mini dictionary if system dictionaries were…
Browse files Browse the repository at this point in the history
… not found
  • Loading branch information
kanru committed Jul 15, 2024
1 parent e3caee6 commit 91ca883
Show file tree
Hide file tree
Showing 7 changed files with 7,068 additions and 8 deletions.
Binary file added capi/data/mini.dat
Binary file not shown.
19 changes: 13 additions & 6 deletions capi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ use std::{

use chewing::{
conversion::{ChewingEngine, Interval, SimpleEngine, Symbol},
dictionary::{Layered, SystemDictionaryLoader, UserDictionaryLoader},
dictionary::{
Dictionary, Layered, LoadDictionaryError, SystemDictionaryLoader, Trie,
UserDictionaryLoader,
},
editor::{
keyboard::{AnyKeyboardLayout, KeyCode, KeyboardLayout, Modifiers, Qwerty},
zhuyin_layout::{
DaiChien26, Et, Et26, GinYieh, Hsu, Ibm, KeyboardLayoutCompat, Pinyin, Standard,
SyllableEditor,
},
BasicEditor, CharacterForm, ConversionEngineKind, Editor, EditorKeyBehavior, LanguageMode,
LaxUserFreqEstimate, UserPhraseAddDirection,
AbbrevTable, BasicEditor, CharacterForm, ConversionEngineKind, Editor, EditorKeyBehavior,
LanguageMode, LaxUserFreqEstimate, SymbolSelector, UserPhraseAddDirection,
},
zhuyin::Syllable,
};
Expand Down Expand Up @@ -130,24 +133,28 @@ pub unsafe extern "C" fn chewing_new2(
let dictionaries = match dictionaries {
Ok(d) => d,
Err(e) => {
let builtin = Trie::new(&include_bytes!("../data/mini.dat")[..]);
error!("Failed to load system dict: {e}");
return null_mut();
error!("Loading builtin minimum dictionary...");
vec![Box::new(builtin.unwrap()) as Box<dyn Dictionary>]
}
};
let abbrev = sys_loader.load_abbrev();
let abbrev = match abbrev {
Ok(abbr) => abbr,
Err(e) => {
error!("Failed to load abbrev table: {e}");
return null_mut();
error!("Loading empty table...");
AbbrevTable::new()
}
};
let sym_sel = sys_loader.load_symbol_selector();
let sym_sel = match sym_sel {
Ok(sym_sel) => sym_sel,
Err(e) => {
error!("Failed to load symbol table: {e}");
return null_mut();
error!("Loading empty table...");
SymbolSelector::new(b"".as_slice()).unwrap()
}
};
let user_dictionary = if userpath.is_null() {
Expand Down
15 changes: 15 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,23 @@ add_custom_command(
-t trie
-n 內建字庫
${DATA_SRC_DIR}/word.src word.dat
COMMAND chewing-cli init-database
-c ${DATA_COPYRIGHT}
-l ${DATA_LICENSE}
-r ${DATA_VERSION}
-t trie
-n 內嵌字庫
${DATA_SRC_DIR}/mini.src mini.dat
COMMAND chewing-cli init-database
-c ${DATA_COPYRIGHT}
-l ${DATA_LICENSE}
-r ${DATA_VERSION}
-t trie
-n 內嵌字庫
${DATA_SRC_DIR}/mini.src ${PROJECT_SOURCE_DIR}/capi/data/mini.dat
DEPENDS
chewing-cli
${DATA_SRC_DIR}/mini.src
${DATA_SRC_DIR}/word.src
${DATA_SRC_DIR}/tsi.src
WORKING_DIRECTORY ${DATA_BIN_DIR}
Expand Down
Loading

0 comments on commit 91ca883

Please sign in to comment.