chinese_dictionary

About

A searchable Chinese / English dictionary with helpful utilities.

Features

Usage

Querying the dictionary ```rust extern crate chinese_dictionary;

use chinese_dictionary::ChineseDictionary;

let dictionary = ChineseDictionary::new(); // Instantiation may take a while

// Querying the dictionary returns an Option<Vec<&WordEntry>> // Read more about the WordEntry struct below let query = "to run"; let results = dictionary.query(query).unwrap(); let firstresult = results.first().unwrap(); println!("{}", firstresult.simplified) // --> "执行" ```

Classifying a string of text ```rust extern crate chinese_dictionary;

use chinesedictionary::ChineseDictionary; use chinesedictionary::ClassificationResult;

let dictionary = ChineseDictionary::new(); // Instantiation may take a while

// Read more about the ClassificationResult enum below println!("{:?}", dictionary.classify("nihao")); // --> ClassificationResult::PY ```

Convert between Traditional and Simplified Chinese characters ```rust extern crate chinese_dictionary;

use chinese_dictionary::ChineseDictionary;

let dictionary = ChineseDictionary::new(); // Instantiation may take a while

println!("{}", dictionary.converttosimplified("簡體字")); // --> "简体字" println!("{}", dictionary.converttotraditional("繁体字")); // --> "繁體字" ```

Segment a string of characters ```rust extern crate chinese_dictionary;

use chinese_dictionary::ChineseDictionary;

let dictionary = ChineseDictionary::new(); // Instantiation may take a while

println!("{:?}", dictionary.segment("今天天气不错")); // --> ["今天", "天气", "不错"] ```

WordEntry struct

```rust extern crate chinese_dictionary;

use chinesedictionary::WordEntry; use chinesedictionary::MeasureWord;

let examplemeasureword = MeasureWord { traditional: "exampletraditional".tostring(), simplified: "examplesimplified".tostring(), pinyinmarks: "examplepinyinmarks".tostring(), pinyinnumbers: "examplepinyinnumbers".tostring(), };

let example = WordEntry { traditional: "繁體字".tostring(), simplified: "繁体字".tostring(), pinyinmarks: "fán tǐ zì".tostring(), pinyinnumbers: "fan2 ti3 zi4".tostring(), english: vec!["traditional Chinese character".tostring()], tonemarks: vec![2 as u8, 3 as u8, 4 as u8], hash: 000000 as u64, measurewords: vec![examplemeasureword], hsk: 6 as u8, wordid: 11111111 as u32, }; ```

ClassificationResult enum

The possible values for the ClassificationResult enum are: - PY: Represents Pinyin - EN: Represents English - ZH: Represents Chinese - UN: Represents an uncertain classification result

License

This software is licensed under the MIT License.

This project uses data from the CC-CEDICT, licensed under the Creative Commons Attribute-Share Alike 4.0 License. This data has been formatted to work with this project. The .dictionary files within the data/ directory are licensed under the Creative Commons Attribute-Share Alike 4.0 License.