| Crates.io | match-pinyin-with-hanzi |
| lib.rs | match-pinyin-with-hanzi |
| version | 0.1.4 |
| created_at | 2021-06-28 18:57:21.652077+00 |
| updated_at | 2024-01-06 23:09:01.648339+00 |
| description | Checks whether the sentence in Chinese characters (汉字) matches with the sentence in pinyin (拼音). Erhua is supported. |
| homepage | |
| repository | https://github.com/sozysozbot/match-pinyin-with-hanzi |
| max_upload_size | |
| id | 415843 |
| size | 6,664 |
How can I check that a Chinese sentence written in Chinese characters (汉字) matches with the sentence in pinyin (拼音)? Well, first I have to parse the pinyin (which is not so easy), then I have to iterate over the Chinese characters... wait, 儿 might or might not stick to the previous syllable...
This crate resolves all that mess. With this crate, all you need is:
use match_pinyin_with_hanzi::match_pinyin_with_hanzi;
match_pinyin_with_hanzi(
"māmā qí mǎ, mǎ màn, māma mà mǎ.",
"妈妈骑马,马慢,妈妈骂马。"
).unwrap();
Note that both māmā and māma are allowed to match with 妈妈. This crate assumes that any syllable can lose its tone, so it is perfectly okay to match a toneless pinyin to the Chinese character.