word-dictionary

Crates.ioword-dictionary
lib.rsword-dictionary
version0.1.2
sourcesrc
created_at2021-05-05 09:11:32.403161
updated_at2023-09-09 09:47:31.565519
descriptionThis crate provides a data structure for word mapping. It can be used for language translation.
homepagehttps://magiclen.org/words-transformer-rs
repositoryhttps://github.com/magiclen/words-transformer-rs
max_upload_size
id393378
size19,786
Magic Len (Ron Li) (magiclen)

documentation

README

Word Dictionary

CI

This crate provides a data structure for word mapping. It can be used for language translation.

Examples

use word_dictionary::Dictionary;

let mut dictionary = Dictionary::new("tests/data/dictionary.txt"); // input a dictionary file

// dictionary.read_data().unwrap(); // if the dictionary file already exists

dictionary.add_edit("Althasol", "阿爾瑟索").unwrap();
dictionary.add_edit("Aldun", "奧爾敦").unwrap();
dictionary.add_edit("Alduin", "阿爾杜因").unwrap();
dictionary.add_edit("Alduin", "奥杜因").unwrap();

assert_eq!("阿爾瑟索", dictionary.get_right(dictionary.find_left_strictly("Althasol", 0).unwrap()).unwrap());
assert_eq!("奧爾敦", dictionary.get_right(dictionary.find_left("dun", 0).unwrap()).unwrap());
assert_eq!("奥杜因", dictionary.get_right(dictionary.find_left("Alduin", 0).unwrap()).unwrap());
assert_eq!("阿爾杜因 --> 奥杜因", dictionary.get_all_right_to_string(dictionary.find_left("Alduin", 0).unwrap()).unwrap());

// The dictionary file now would be
/*
Alduin = 阿爾杜因 --> 奥杜因
Aldun = 奧爾敦
Althasol = 阿爾瑟索
*/

Crates.io

https://crates.io/crates/word-dictionary

Documentation

https://docs.rs/word-dictionary

License

MIT

Commit count: 14

cargo fmt