#dictionary #parser #chinese #localization #cantonese #cedict

bin+lib cccedict

支持粤语(通过cantonese.org阅读)的CC-CEDICT解析器

6 个版本

0.2.1 2021年12月5日
0.2.0 2021年12月4日
0.1.3 2021年12月4日
0.1.0 2021年4月30日

#275 in 国际化 (i18n)

MIT 许可证

24KB
487 代码行

cccedict

cccedict 是一个用于解析中英自然语言词典的CC-CEDICT解析器。它具有支持CC-CEDICT格式的cantonese.org扩展的独特功能,该扩展添加了对粤音发音的支持。

使用方法

CedictEntry 代表 Cedict 中的一个条目

use cccedict::cedict_entry::*;

let line = "你好嗎 你好吗 [ni3 hao3 ma5] {nei5 hou2 maa1} /how are you?/";
let entry = CedictEntry::new(line).unwrap();

assert_eq!(entry.traditional, "你好嗎");
assert_eq!(entry.simplified, "你好吗");
assert_eq!(entry.pinyin, Some(
    vec![
        Syllable::new("ni", "3"),
        Syllable::new("hao", "3"),
        Syllable::new("ma", "5"),
    ]
));
assert_eq!(entry.jyutping, Some(
    vec![
        Syllable::new("nei", "5"),
        Syllable::new("hou", "2"),
        Syllable::new("maa", "1"),
    ]
));
assert_eq!(entry.definitions, Some(vec!["how are you?".to_string()]));

您还可以从 FromStrReadAsRef<Path> 实现者实例化一个 Cedict

use cccedict::cedict::Cedict;
use std::str::FromStr;

let cedict_entries = "\
你嘅 你嘅 [ni3 ge2] {nei5 ge3} /your's (spoken)/
你地 你地 [ni3 di4] {nei5 dei6} /you guys; you all/
你好嗎 你好吗 [ni3 hao3 ma5] {nei5 hou2 maa1} /how are you?/";

let cedict = Cedict::from_str(cedict_entries).unwrap();
assert_eq!(cedict.entries.len(), 3);

let reader: &[u8] = cedict_entries.as_bytes();
let cedict = Cedict::from_file(reader).unwrap();
assert_eq!(cedict.entries.len(), 3);

use std::path::Path;
let path = Path::new("fixtures/cccanto-test.txt");
let cedict = Cedict::from_path(path).unwrap();
assert_eq!(cedict.entries.len(), 3);

依赖关系

~2MB
~45K SLoC