Permalink
Browse files

한자 검색 알고리즘 개선, 사전 보강 및 이모티콘 추가

- 뜻 검색 시 앞부분이 일치하는 모든 단어 검색
- 사전에 뜻이 없는 단어의 경우 표제어를 표시하도록 함
- 유니코드 이모티콘 추가
- 사전 정렬 방식 변경 (무조건 가나다 순 -> 단어, 뜻, 낱자 순 안에서 가나다 순)
  • Loading branch information...
youknowone committed May 25, 2014
1 parent 400eb75 commit cf86795485331e82f9c79dee9484d79518c6b0b0
Showing with 83 additions and 28 deletions.
  1. +3 −3 GureumKIM/HangulComposer.h
  2. +79 −24 GureumKIM/HangulComposer.m
  3. +1 −1 libhangul-objc
@@ -55,7 +55,7 @@ typedef enum {
@end
@interface HanjaComposer : CIMComposer {
- HGHanjaList *_hanjaCandidates;
+ NSMutableArray *_candidates;
NSMutableString *bufferedString;
NSString *composedString;
NSString *commitString;
@@ -67,8 +67,8 @@ typedef enum {
- (void)updateFromClientSelectedRange:(id)client;
@property(nonatomic, readonly) HangulComposer *hangulComposer;
-@property(nonatomic, readonly) HGHanjaTable *hanjaTable;
-@property(nonatomic, readonly) HGHanjaList *hanjaCandidates;
+@property(nonatomic, readonly) HGHanjaTable *characterTable, *wordTable, *reversedTable, *MSSymbolTable, *emoticonTable, *emoticonReversedTable;
+@property(nonatomic, retain) NSArray *candidates;
@property(nonatomic, assign) BOOL mode;
@end
View
@@ -154,7 +154,7 @@ - (void)candidateSelectionChanged:(NSAttributedString *)candidateString {
@end
@implementation HanjaComposer
-@synthesize hanjaCandidates=_hanjaCandidates, mode=_mode;
+@synthesize mode=_mode;
- (id)init {
self = [super init];
@@ -214,11 +214,6 @@ - (void)cancelComposition {
self.composedString = @"";
}
-- (void)setHanjaCandidates:(HGHanjaList *)hanjaCandidates {
- [self->_hanjaCandidates release];
- self->_hanjaCandidates = [hanjaCandidates retain];
-}
-
- (void)composerSelected:(id)sender {
[self->bufferedString setString:@""];
self.commitString = @"";
@@ -230,12 +225,23 @@ - (void)updateHanjaCandidates {
// step 2: 일단 화면에 한글이 표시되도록 조정
self.composedString = self.originalString;
// step 3: 키가 없거나 검색 결과가 키 prefix와 일치하지 않으면 후보를 보여주지 않는다.
- if (self.originalString.length == 0) {
- self.hanjaCandidates = nil;
+ NSString *keyword = self.originalString;
+ if (keyword.length == 0) {
+ self.candidates = nil;
} else {
- self.hanjaCandidates = [self.hanjaTable hanjasByPrefixMatching:self.composedString];
+ NSMutableArray *candidates = [NSMutableArray array];
+ for (HGHanjaTable *table in @[self.emoticonTable, self.MSSymbolTable, self.wordTable, self.reversedTable, self.emoticonReversedTable, self.characterTable]) {
+ HGHanjaList *list = [table hanjasByPrefixSearching:keyword];
+ for (HGHanja *hanja in list) {
+ [candidates addObject:[NSString stringWithFormat:@"%@: %@", hanja.value, hanja.comment]];
+ }
+ }
+ if (candidates.count > 0 && CIMSharedConfiguration->showsInputForHanjaCandidates) {
+ [candidates insertObject:keyword atIndex:0];
+ }
+ self.candidates = candidates;
}
- dlog(DEBUG_HANJACOMPOSER, @"HanjaComposer -updateHanjaCandidates showing: %d", self.hanjaCandidates != nil);
+ dlog(DEBUG_HANJACOMPOSER, @"HanjaComposer -updateHanjaCandidates showing: %d", self.candidates != nil);
}
- (void)updateFromClientSelectedRange:(id)client {
@@ -255,20 +261,17 @@ - (void)updateFromClientSelectedRange:(id)client {
}
- (BOOL)hasCandidates {
- return self.hanjaCandidates.count > 0;
+ return self.candidates.count > 0;
+}
+
+- (void)setCandidates:(NSMutableArray *)candidates {
+ [candidates retain];
+ [self->_candidates release];
+ self->_candidates = candidates;
}
- (NSArray *)candidates {
- HGHanjaList *hanjas = self.hanjaCandidates;
- NSMutableArray *candidates = [NSMutableArray array];
- if (CIMSharedConfiguration->showsInputForHanjaCandidates) {
- [candidates addObject:hanjas.key];
- }
- for (HGHanja *hanja in hanjas) {
- [candidates addObject:[NSString stringWithFormat:@"%@: %@", hanja.value, hanja.comment]];
- }
- dlog(DEBUG_HANJACOMPOSER, @"HanjaComposer -candidates returning: %@", candidates);
- return candidates;
+ return self->_candidates;
}
- (void)candidateSelected:(NSAttributedString *)candidateString {
@@ -289,10 +292,62 @@ - (void)candidateSelectionChanged:(NSAttributedString *)candidateString {
// }
}
-- (HGHanjaTable *)hanjaTable {
+- (HGHanjaTable *)characterTable {
+ static HGHanjaTable *sharedHanjaTable = nil;
+ if (sharedHanjaTable == nil) {
+ NSBundle *bundle = [NSBundle bundleForClass:[HGHanjaTable class]];
+ NSString *path = [bundle pathForResource:@"hanjac" ofType:@"txt"];
+ sharedHanjaTable = [[HGHanjaTable alloc] initWithContentOfFile:path];
+ }
+ return sharedHanjaTable;
+}
+
+- (HGHanjaTable *)wordTable {
+ static HGHanjaTable *sharedHanjaTable = nil;
+ if (sharedHanjaTable == nil) {
+ NSBundle *bundle = [NSBundle bundleForClass:[HGHanjaTable class]];
+ NSString *path = [bundle pathForResource:@"hanjaw" ofType:@"txt"];
+ sharedHanjaTable = [[HGHanjaTable alloc] initWithContentOfFile:path];
+ }
+ return sharedHanjaTable;
+}
+
+- (HGHanjaTable *)reversedTable {
+ static HGHanjaTable *sharedHanjaTable = nil;
+ if (sharedHanjaTable == nil) {
+ NSBundle *bundle = [NSBundle bundleForClass:[HGHanjaTable class]];
+ NSString *path = [bundle pathForResource:@"hanjar" ofType:@"txt"];
+ sharedHanjaTable = [[HGHanjaTable alloc] initWithContentOfFile:path];
+ }
+ return sharedHanjaTable;
+}
+
+- (HGHanjaTable *)MSSymbolTable {
+ static HGHanjaTable *sharedHanjaTable = nil;
+ if (sharedHanjaTable == nil) {
+ NSBundle *bundle = [NSBundle bundleForClass:[HGHanjaTable class]];
+ NSString *path = [bundle pathForResource:@"mssymbol" ofType:@"txt"];
+ sharedHanjaTable = [[HGHanjaTable alloc] initWithContentOfFile:path];
+ }
+ return sharedHanjaTable;
+}
+
+- (HGHanjaTable *)emoticonTable {
+ static HGHanjaTable *sharedHanjaTable = nil;
+ if (sharedHanjaTable == nil) {
+ NSBundle *bundle = [NSBundle bundleForClass:[HGHanjaTable class]];
+ NSString *path = [bundle pathForResource:@"emoticon" ofType:@"txt"];
+ sharedHanjaTable = [[HGHanjaTable alloc] initWithContentOfFile:path];
+ }
+ return sharedHanjaTable;
+}
+
+- (HGHanjaTable *)emoticonReversedTable {
static HGHanjaTable *sharedHanjaTable = nil;
if (sharedHanjaTable == nil) {
- sharedHanjaTable = [[HGHanjaTable alloc] init];
+ NSBundle *bundle = [NSBundle bundleForClass:[HGHanjaTable class]];
+ NSString *path = [bundle pathForResource:@"emoticonr" ofType:@"txt"];
+ sharedHanjaTable = [[HGHanjaTable alloc] initWithContentOfFile:path];
}
return sharedHanjaTable;
}
@@ -334,7 +389,7 @@ - (CIMInputTextProcessResult)inputController:(CIMInputController *)controller in
self.composedString = self.originalString;
[self cancelComposition];
// step 3: 한자 후보 취소
- self.hanjaCandidates = nil; // 후보 취소
+ self.candidates = nil; // 후보 취소
return CIMInputTextProcessResultNotProcessedAndNeedsCommit;
} break;
default:
Submodule libhangul-objc updated 4 files
+27 −5 Hangul.xcodeproj/project.pbxproj
+2 −1 Hangul/HGHanja.h
+7 −3 Hangul/HGHanja.m
+1 −1 libhangul

0 comments on commit cf86795

Please sign in to comment.