From 4b58333fc2b7af434b1c29dbdef30de82621df54 Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Mon, 11 Jul 2022 19:03:34 -0700 Subject: [PATCH 1/3] new example displaying entry info with kanji and reading --- examples/kanji_info.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/kanji_info.rs diff --git a/examples/kanji_info.rs b/examples/kanji_info.rs new file mode 100644 index 0000000..4180c5b --- /dev/null +++ b/examples/kanji_info.rs @@ -0,0 +1,39 @@ +/******************************************************************************* +* 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 +*******************************************************************************/ +use jmdict::{KanjiElement, ReadingElement}; + +fn main() { + let input = "一日"; + let count = jmdict::entries() + .filter(|e| { + let mut result = false; + if e.kanji_elements().any(|k| k.text == input) { + result = true; + println!("--- entry #{} ---", e.number); + let kanji_elements: Vec = e.kanji_elements().map(|ke| ke).collect(); + for kanji in &kanji_elements { + println!("kanji element: {}", kanji.text); + println!(" priority: {:?}\n", kanji.priority); + } + + let reading_forms: Vec = e.reading_elements().map(|item| item).collect(); + for reading in reading_forms { + println!("reading_form: {}", reading.text); + println!(" priority: {:?}\n", reading.priority); + + for info in reading.infos() { + println!("info: {:?}", info); + } + } + + + // let sense = e.senses().next().unwrap().text; + + } + result + }) + .count(); + println!("{} entries for {}", count, input); +} From efdecaee2ca5572038431114d5b224b4a88fba63 Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Thu, 29 Dec 2022 13:45:44 -0800 Subject: [PATCH 2/3] address feedback from code review --- examples/kanji_info.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/kanji_info.rs b/examples/kanji_info.rs index 4180c5b..7780adc 100644 --- a/examples/kanji_info.rs +++ b/examples/kanji_info.rs @@ -2,24 +2,21 @@ * 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 *******************************************************************************/ -use jmdict::{KanjiElement, ReadingElement}; fn main() { let input = "一日"; let count = jmdict::entries() .filter(|e| { - let mut result = false; if e.kanji_elements().any(|k| k.text == input) { - result = true; + // note two entries have identical Kanji and reading + // yet differ in "sense" not shown in this example println!("--- entry #{} ---", e.number); - let kanji_elements: Vec = e.kanji_elements().map(|ke| ke).collect(); - for kanji in &kanji_elements { + for kanji in e.kanji_elements() { println!("kanji element: {}", kanji.text); println!(" priority: {:?}\n", kanji.priority); } - let reading_forms: Vec = e.reading_elements().map(|item| item).collect(); - for reading in reading_forms { + for reading in e.reading_elements() { println!("reading_form: {}", reading.text); println!(" priority: {:?}\n", reading.priority); @@ -28,11 +25,9 @@ fn main() { } } - - // let sense = e.senses().next().unwrap().text; - + return true } - result + false }) .count(); println!("{} entries for {}", count, input); From 00d5edfa05185e7e7f737ac237d62ca849f9fa58 Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Fri, 30 Dec 2022 11:46:05 -0800 Subject: [PATCH 3/3] fix comment -- two entries differ in reading --- examples/kanji_info.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/kanji_info.rs b/examples/kanji_info.rs index 7780adc..7566a79 100644 --- a/examples/kanji_info.rs +++ b/examples/kanji_info.rs @@ -8,8 +8,8 @@ fn main() { let count = jmdict::entries() .filter(|e| { if e.kanji_elements().any(|k| k.text == input) { - // note two entries have identical Kanji and reading - // yet differ in "sense" not shown in this example + // 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);