Skip to content

Commit a0d0be9

Browse files
committed
Use code point plus CJK Block penalty when unranked
Fixes <#12>.
1 parent 5437a78 commit a0d0be9

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
## [Unreleased]
55

6+
- Sorted unranked candidates by code point plus CJK Block penalty
7+
(fixes [Candidate order changes between Android 7 and 8])
8+
9+
[Candidate order changes between Android 7 and 8]:
10+
https://github.com/stroke-input/stroke-input-android/issues/12
11+
612

713
## [v0.9.26] (48) Mouth besides (2023-01-15)
814

app/src/main/java/io/github/yawnoc/strokeinput/StrokeInputService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ public class StrokeInputService
108108
private static final String PHRASES_FILE_NAME_SIMPLIFIED = "phrases-simplified.txt";
109109

110110
private static final int LAG_PREVENTION_CODE_POINT_COUNT = 1400;
111-
private static final int LARGISH_SORTING_RANK = 3000;
112-
private static final int RANKING_PENALTY_PER_CHAR = 2 * LARGISH_SORTING_RANK;
113-
private static final int RANKING_PENALTY_UNPREFERRED = 10 * LARGISH_SORTING_RANK;
111+
private static final int CJK_MAIN_CODE_POINT_START = 0x4E00;
112+
private static final int CJK_MAIN_CODE_POINT_END = 0x9FFF;
113+
private static final int CJK_EXTENSION_CODE_POINT_MIN = 0x3400;
114+
private static final int CJK_EXTENSION_CODE_POINT_MAX = 0x2CEAF;
115+
private static final int RANKING_PENALTY_CJK_EXTENSION = CJK_MAIN_CODE_POINT_END - CJK_EXTENSION_CODE_POINT_MIN + 1;
116+
private static final int RANKING_PENALTY_PER_CHAR = 2 * CJK_EXTENSION_CODE_POINT_MAX;
117+
private static final int RANKING_PENALTY_UNPREFERRED = 10 * CJK_EXTENSION_CODE_POINT_MAX;
114118
private static final int MAX_PREFIX_MATCH_COUNT = 30;
115119
private static final int MAX_PHRASE_LENGTH = 6;
116120

@@ -794,10 +798,14 @@ private int computeCandidateRank(
794798
final boolean firstCodePointMatchesPhraseCompletionCandidate = phraseCompletionIndex > 0;
795799

796800
final Integer sortingRank = sortingRankFromCodePoint.get(firstCodePoint);
801+
final int cjkBlockPenalty =
802+
(firstCodePoint < CJK_MAIN_CODE_POINT_START || firstCodePoint > CJK_MAIN_CODE_POINT_END)
803+
? RANKING_PENALTY_CJK_EXTENSION
804+
: 0;
797805
final int sortingRankNonNull =
798806
(sortingRank != null)
799807
? sortingRank
800-
: LARGISH_SORTING_RANK;
808+
: firstCodePoint + cjkBlockPenalty;
801809

802810
final int lengthPenalty = (stringLength - 1) * RANKING_PENALTY_PER_CHAR;
803811
final int unpreferredPenalty =

0 commit comments

Comments
 (0)