From eee02a52d0fc75866119aae4764515cd756fc4e5 Mon Sep 17 00:00:00 2001 From: Naoaki Iwakiri Date: Sat, 19 Oct 2024 16:27:22 +0900 Subject: [PATCH] Add description more. Lint fix --- CHANGELOG.md | 2 +- src/dictionary/mod.rs | 53 ++++++++++++++++++++++++++----------------- tests/tests.rs | 3 +-- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376b5b0..7a5d274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. ### Fixed -- 辞書の見出しに数字が含まれている時に#4を含むエントリ以外では変換候補にならない問題を修正 +- 辞書の見出しに数字が含まれている時に#4を含むエントリ以外では変換候補にならない問題を修正。数値自体を見出しに含む候補と数値置換候補があった場合、常に完全一致の候補の方が優先される。 (辞書のエントリ上、双方にマッチする時に各々の候補の別見出しの候補に対しての優先順位を保持する事が不可能なため。) ## [3.1.1] - 2024-03-05 diff --git a/src/dictionary/mod.rs b/src/dictionary/mod.rs index 37028cf..6f02939 100644 --- a/src/dictionary/mod.rs +++ b/src/dictionary/mod.rs @@ -207,27 +207,32 @@ fn get_all_candidates_inner( let mut matched_numbers = vec![]; let exact_match_candidates = get_candidates_in_order(dictionaries, &composite_key); - let exact_match_candidates= dedup_candidates(exact_match_candidates); - let mut all_candidates: Vec = exact_match_candidates.into_iter() + let exact_match_candidates = dedup_candidates(exact_match_candidates); + let mut all_candidates: Vec = exact_match_candidates + .into_iter() .map(|dictionary_candidate| { Candidate::from_dictionary_candidate(&composite_key, &dictionary_candidate) }) .collect(); - if !is_numeric_re_lookup { let replaced_key; (replaced_key, matched_numbers) = to_composite_to_numeric_dict_key(&composite_key); if replaced_key != *composite_key { - let numeric_replace_match_candidates= get_candidates_in_order(dictionaries, &replaced_key); - let numeric_replace_match_candidates = dedup_candidates(numeric_replace_match_candidates); - let mut numeric_replace_match_candidates: Vec = numeric_replace_match_candidates - .into_iter() - .map(|dictionary_candidate| { - Candidate::from_dictionary_candidate(&replaced_key, &dictionary_candidate) - }) - .flat_map(|candidate| replace_numeric_match(&candidate, &matched_numbers, dictionaries)) - .collect(); + let numeric_replace_match_candidates = + get_candidates_in_order(dictionaries, &replaced_key); + let numeric_replace_match_candidates = + dedup_candidates(numeric_replace_match_candidates); + let mut numeric_replace_match_candidates: Vec = + numeric_replace_match_candidates + .into_iter() + .map(|dictionary_candidate| { + Candidate::from_dictionary_candidate(&replaced_key, &dictionary_candidate) + }) + .flat_map(|candidate| { + replace_numeric_match(&candidate, &matched_numbers, dictionaries) + }) + .collect(); all_candidates.append(&mut numeric_replace_match_candidates); } } @@ -563,22 +568,27 @@ mod test { #[test] fn get_all_candidates_basic() { - let test_dictionary = CskkDictionary::new_static_dict("tests/data/dictionaries/SKK-JISYO.S", "euc-jp", false) - .unwrap(); + let test_dictionary = + CskkDictionary::new_static_dict("tests/data/dictionaries/SKK-JISYO.S", "euc-jp", false) + .unwrap(); let dictionaries = vec![Arc::new(test_dictionary)]; let key = CompositeKey::new("あい", None); - let result = get_all_candidates(&dictionaries,&key); + let result = get_all_candidates(&dictionaries, &key); assert_eq!(result[0].kouho_text, "愛"); } #[test] fn get_all_candidates_numeric_match() { - let test_dictionary = CskkDictionary::new_static_dict("tests/data/dictionaries/number_jisyo.dat", "utf-8", false) - .unwrap(); + let test_dictionary = CskkDictionary::new_static_dict( + "tests/data/dictionaries/number_jisyo.dat", + "utf-8", + false, + ) + .unwrap(); let dictionaries = vec![Arc::new(test_dictionary)]; let key = CompositeKey::new("5/1", None); - let result = get_all_candidates(&dictionaries,&key); + let result = get_all_candidates(&dictionaries, &key); assert_eq!(result[0].kouho_text, "#0月#0日"); assert_eq!(result[0].midashi, "#/#"); @@ -587,11 +597,12 @@ mod test { #[test] fn get_all_candidates_numeric_exact_match() { - let test_dictionary = CskkDictionary::new_static_dict("tests/data/dictionaries/maruichi.dat", "utf-8", false) - .unwrap(); + let test_dictionary = + CskkDictionary::new_static_dict("tests/data/dictionaries/maruichi.dat", "utf-8", false) + .unwrap(); let dictionaries = vec![Arc::new(test_dictionary)]; let key = CompositeKey::new("まる1", None); - let result = get_all_candidates(&dictionaries,&key); + let result = get_all_candidates(&dictionaries, &key); assert_eq!(result[0].kouho_text, "①"); // 0xE291A0 (U+02460) assert_eq!(result[1].kouho_text, "❶"); diff --git a/tests/tests.rs b/tests/tests.rs index d17b25c..550e96e 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1475,8 +1475,7 @@ fn maruichi() { let static_dict = CskkDictionary::new_static_dict("tests/data/dictionaries/maruichi.dat", "utf-8", false) .unwrap(); - let mut context = - test_context_with_dictionaries(vec![Arc::new(static_dict)]); + let mut context = test_context_with_dictionaries(vec![Arc::new(static_dict)]); transition_test( &mut context, CompositionMode::Direct,