KeyHandler // Refactoring "buildAssociatePhraseStateWithKey".
This commit is contained in:
parent
c1ed41cf16
commit
0cdf0020c1
|
@ -74,6 +74,7 @@ struct BufferStatePackage
|
||||||
- (BOOL)ifLangModelHasUnigramsForKey:(NSString *)reading;
|
- (BOOL)ifLangModelHasUnigramsForKey:(NSString *)reading;
|
||||||
- (BOOL)isPhoneticReadingBufferEmpty;
|
- (BOOL)isPhoneticReadingBufferEmpty;
|
||||||
- (BOOL)isPrintable:(UniChar)charCode;
|
- (BOOL)isPrintable:(UniChar)charCode;
|
||||||
|
- (NSArray<NSString *> *)buildAssociatePhraseArrayWithKey:(NSString *)key;
|
||||||
- (NSArray<NSString *> *)getCandidatesArray;
|
- (NSArray<NSString *> *)getCandidatesArray;
|
||||||
- (NSInteger)getBuilderCursorIndex;
|
- (NSInteger)getBuilderCursorIndex;
|
||||||
- (NSInteger)getBuilderLength;
|
- (NSInteger)getBuilderLength;
|
||||||
|
|
|
@ -405,23 +405,29 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
||||||
}
|
}
|
||||||
|
|
||||||
// NON-SWIFTIFIABLE
|
// NON-SWIFTIFIABLE
|
||||||
- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode
|
- (NSArray<NSString *> *)buildAssociatePhraseArrayWithKey:(NSString *)key
|
||||||
{
|
{
|
||||||
|
NSMutableArray<NSString *> *array = [NSMutableArray array];
|
||||||
std::string cppKey = std::string(key.UTF8String);
|
std::string cppKey = std::string(key.UTF8String);
|
||||||
if (_languageModel->hasAssociatedPhrasesForKey(cppKey))
|
if (_languageModel->hasAssociatedPhrasesForKey(cppKey))
|
||||||
{
|
{
|
||||||
std::vector<std::string> phrases = _languageModel->associatedPhrasesForKey(cppKey);
|
std::vector<std::string> phrases = _languageModel->associatedPhrasesForKey(cppKey);
|
||||||
NSMutableArray<NSString *> *array = [NSMutableArray array];
|
|
||||||
for (auto phrase : phrases)
|
for (auto phrase : phrases)
|
||||||
{
|
{
|
||||||
NSString *item = [[NSString alloc] initWithUTF8String:phrase.c_str()];
|
NSString *item = [[NSString alloc] initWithUTF8String:phrase.c_str()];
|
||||||
[array addObject:item];
|
[array addObject:item];
|
||||||
}
|
}
|
||||||
InputStateAssociatedPhrases *associatedPhrases =
|
|
||||||
[[InputStateAssociatedPhrases alloc] initWithCandidates:array useVerticalMode:useVerticalMode];
|
|
||||||
return associatedPhrases;
|
|
||||||
}
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable InputState *)buildAssociatePhraseStateWithKey:(NSString *)key useVerticalMode:(BOOL)useVerticalMode
|
||||||
|
{
|
||||||
|
NSArray<NSString *> *array = [self buildAssociatePhraseArrayWithKey:key];
|
||||||
|
if (array == nil || [array count] == 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
else
|
||||||
|
return [[InputStateAssociatedPhrases alloc] initWithCandidates:array useVerticalMode:useVerticalMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - 必須用 ObjCpp 處理的部分: Mandarin
|
#pragma mark - 必須用 ObjCpp 處理的部分: Mandarin
|
||||||
|
|
|
@ -63,7 +63,7 @@ import Cocoa
|
||||||
return newState
|
return newState
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - 用以生成候選詞數組
|
// MARK: - 用以生成候選詞數組及狀態
|
||||||
|
|
||||||
func _buildCandidateState(
|
func _buildCandidateState(
|
||||||
_ currentState: InputState.NotEmpty,
|
_ currentState: InputState.NotEmpty,
|
||||||
|
@ -80,6 +80,8 @@ import Cocoa
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - 用以接收聯想詞數組且生成狀態
|
||||||
|
|
||||||
// MARK: - 用以處理就地新增自訂語彙時的行為
|
// MARK: - 用以處理就地新增自訂語彙時的行為
|
||||||
|
|
||||||
func _handleMarkingState(
|
func _handleMarkingState(
|
||||||
|
|
Loading…
Reference in New Issue