mgrLM // Make the phrase duplication check compatible with CHS mode.
This commit is contained in:
parent
d8fab57402
commit
fb38beabd9
|
@ -182,7 +182,7 @@ class InputState: NSObject {
|
|||
let (exactEnd, _) = (composingBuffer as NSString).characterIndex(from: markedRange.location + markedRange.length)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
let exist = mgrLangModel.checkIfExist(userPhrase: text, key: joined)
|
||||
let exist = mgrLangModel.checkIfUserPhraseExist(userPhrase: text, mode: ctlInputMethod.currentKeyHandler.inputMode, key: joined)
|
||||
if exist {
|
||||
return String(format: NSLocalizedString("\"%@\" already exists.", comment: ""), text)
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ class InputState: NSObject {
|
|||
let (exactEnd, _) = (composingBuffer as NSString).characterIndex(from: markedRange.location + markedRange.length)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
return mgrLangModel.checkIfExist(userPhrase: text, key: joined) == true
|
||||
return mgrLangModel.checkIfUserPhraseExist(userPhrase: text, mode: ctlInputMethod.currentKeyHandler.inputMode, key: joined) == true
|
||||
}
|
||||
|
||||
@objc var userPhrase: String {
|
||||
|
|
|
@ -47,6 +47,13 @@ class ctlInputMethod: IMKInputController {
|
|||
private var keyHandler: KeyHandler = KeyHandler()
|
||||
private var state: InputState = InputState.Empty()
|
||||
|
||||
// 想讓 keyHandler 能夠被外界調查狀態與參數的話,就得對 keyHandler 做常態處理。
|
||||
// 這樣 InputState 可以藉由這個 ctlInputMethod 了解到當前的輸入模式是簡體中文還是繁體中文。
|
||||
// 然而,要是直接對 keyHandler 做常態處理的話,反而會導致 keyHandlerInput 無法協同處理。
|
||||
// 所以才需要「currentKeyHandler」這個假 keyHandler。
|
||||
// 這個「currentKeyHandler」僅用來讓其他模組知道當前的輸入模式是什麼模式,除此之外別無屌用。
|
||||
static var currentKeyHandler: KeyHandler = KeyHandler()
|
||||
|
||||
// MARK: - IMKInputController methods
|
||||
|
||||
override init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
|
||||
|
@ -157,6 +164,8 @@ class ctlInputMethod: IMKInputController {
|
|||
keyHandler.inputMode = newInputMode
|
||||
self.handle(state: .Empty(), client: client)
|
||||
}
|
||||
// 讓外界知道目前的簡繁體輸入模式。
|
||||
ctlInputMethod.currentKeyHandler.inputMode = keyHandler.inputMode
|
||||
}
|
||||
|
||||
// MARK: - IMKServerInput protocol methods
|
||||
|
|
|
@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (BOOL)checkIfUserLanguageModelFilesExist;
|
||||
+ (BOOL)checkIfUserDataFolderExists;
|
||||
|
||||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:));
|
||||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase inputMode:(InputMode)mode key:(NSString *)key NS_SWIFT_NAME(checkIfUserPhraseExist(userPhrase:mode:key:));
|
||||
+ (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode areWeDuplicating:(BOOL)areWeDuplicating;
|
||||
+ (void)setPhraseReplacementEnabled:(BOOL)phraseReplacementEnabled;
|
||||
+ (void)setCNSEnabled:(BOOL)cnsEnabled;
|
||||
|
|
|
@ -207,10 +207,10 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
|
|||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:))
|
||||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase inputMode:(InputMode)mode key:(NSString *)key NS_SWIFT_NAME(checkIfUserPhraseExist(userPhrase:mode:key:))
|
||||
{
|
||||
string unigramKey = string(key.UTF8String);
|
||||
vector<Unigram> unigrams = gLangModelCHT.unigramsForKey(unigramKey);
|
||||
vector<Unigram> unigrams = [mode isEqualToString:imeModeCHT] ? gLangModelCHT.unigramsForKey(unigramKey): gLangModelCHS.unigramsForKey(unigramKey);
|
||||
string userPhraseString = string(userPhrase.UTF8String);
|
||||
for (auto unigram: unigrams) {
|
||||
if (unigram.keyValue.value == userPhraseString) {
|
||||
|
|
Loading…
Reference in New Issue