Crates.io | word-dictionary |
lib.rs | word-dictionary |
version | 0.1.2 |
source | src |
created_at | 2021-05-05 09:11:32.403161 |
updated_at | 2023-09-09 09:47:31.565519 |
description | This crate provides a data structure for word mapping. It can be used for language translation. |
homepage | https://magiclen.org/words-transformer-rs |
repository | https://github.com/magiclen/words-transformer-rs |
max_upload_size | |
id | 393378 |
size | 19,786 |
This crate provides a data structure for word mapping. It can be used for language translation.
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 = 阿爾瑟索
*/
https://crates.io/crates/word-dictionary
https://docs.rs/word-dictionary