mirror of https://github.com/ElnuDev/rust-jmdict
Merge pull request #2 from ultrasaurus/entry-example
new example displaying entry info with kanji and readingmain
commit
a709995cef
@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* SPDX-License-Identifier: Apache-2.0 Refer to the file "LICENSE" for details.
|
||||
* example illustrating how to access kanji and reading information for a word
|
||||
*******************************************************************************/
|
||||
|
||||
fn main() {
|
||||
let input = "一日";
|
||||
let count = jmdict::entries()
|
||||
.filter(|e| {
|
||||
if e.kanji_elements().any(|k| k.text == input) {
|
||||
// note two entries have identical Kanji
|
||||
// yet differ in reading
|
||||
println!("--- entry #{} ---", e.number);
|
||||
for kanji in e.kanji_elements() {
|
||||
println!("kanji element: {}", kanji.text);
|
||||
println!(" priority: {:?}\n", kanji.priority);
|
||||
}
|
||||
|
||||
for reading in e.reading_elements() {
|
||||
println!("reading_form: {}", reading.text);
|
||||
println!(" priority: {:?}\n", reading.priority);
|
||||
|
||||
for info in reading.infos() {
|
||||
println!("info: {:?}", info);
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
false
|
||||
})
|
||||
.count();
|
||||
println!("{} entries for {}", count, input);
|
||||
}
|
Loading…
Reference in new issue