Skip to content

Commit

Permalink
Add description more. Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
naokiri committed Oct 19, 2024
1 parent ad2b8e1 commit eee02a5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 32 additions & 21 deletions src/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Candidate> = exact_match_candidates.into_iter()
let exact_match_candidates = dedup_candidates(exact_match_candidates);
let mut all_candidates: Vec<Candidate> = 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<Candidate> = 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<Candidate> =
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);
}
}
Expand Down Expand Up @@ -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, "#/#");
Expand All @@ -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, "❶");
Expand Down
3 changes: 1 addition & 2 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit eee02a5

Please sign in to comment.