GitXplorerGitXplorer
b

cccedict

public
4 stars
1 forks
6 issues

Commits

List of commits on branch main.
Verified
83e50ca7d2fbfc2f926c4a16b9eb63b86d189da0

Update README.md

bbriankung committed a year ago
Verified
ff28dfdf30566b2a7e4ab2b726749c014c625724

Update README.md

bbriankung committed a year ago
Unverified
76945513579099a5b1f0741860cd3025adc95928

Quick refactor - rename variable, add test, remove match

bbriankung committed 3 years ago
Unverified
ead50b12b3471e97b6739c0867dda44b61a4f43e

Bump version

bbriankung committed 3 years ago
Unverified
6259d62bd43c6bfe5210a6f301a2a6fccb12c82a

Remove backlog, prefer github issues

bbriankung committed 3 years ago
Unverified
86aef3cace6c4b7dde2aa828d9cfe44ff2c6571f

Update backlog

bbriankung committed 3 years ago

README

The README file for this repository.

cccedict

cccedict is a CC-CEDICT parser for parsing Chinese/English natural language dictionaries. It has the unique feature of supporting the cantonese.org extensions to the CC-CEDICT format, which adds support for jyutping pronunciations.

Usage

A CedictEntry represents a single entry in a 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()]));

You can also instantiate a Cedict from a FromStr, Read, or AsRef<Path> implementor:

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);