Skip to content

Commit

Permalink
perf: improve Apple Dictionary query Chinese word result
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Dec 22, 2023
1 parent 35f7bec commit c02148a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Easydict/Feature/Service/Apple/AppleDictionary/EZAppleDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "EZWindowManager.h"
#import "NSString+EZUtils.h"
#import "NSString+EZHandleInputText.h"
#import "NSString+EZChineseText.h"

@implementation EZAppleDictionary

Expand Down Expand Up @@ -605,6 +606,9 @@ - (BOOL)isValidHeadword:(NSString *)headword

// If text is Chinese
if ([EZLanguageManager.shared isChineseLanguage:language]) {
if (word.length == 1) {
return YES;
}

/**
開 --> 开
Expand All @@ -613,15 +617,15 @@ - (BOOL)isValidHeadword:(NSString *)headword
開始 --> 開始 kāishǐ
国色天香 --> 国色天香 guósè-tiānxiāng, 国色天香 guó sè tiān xiāng, 天香国色 tiān xiāng guó sè
浮云终日行 --> 浮 fú xxx
奇怪字符 --> 奇怪 qiguai xxx
*/

if (word.length == 1) {
return YES;
}
normalizedWord = [normalizedWord toSimplifiedChineseText];
normalizedHeadword = [normalizedHeadword toSimplifiedChineseText];

BOOL hasWordSubstring = [normalizedHeadword containsString:normalizedWord];
BOOL hasSameWordParts = [normalizedWord wordsInText].count == [normalizedHeadword wordsInText].count;
if (hasWordSubstring || hasSameWordParts) {
NSString *pureChineseHeadwords = [normalizedHeadword removeAlphabet].trim;
BOOL hasWordSubstring = [pureChineseHeadwords containsString:normalizedWord];
if (hasWordSubstring) {
return YES;
}

Expand Down

0 comments on commit c02148a

Please sign in to comment.