mgrLM // +chkIfUserPhraseExists to writeUserPhrase.

This commit is contained in:
ShikiSuen 2022-02-16 16:39:06 +08:00
parent be1e023016
commit db16cdd020
3 changed files with 6 additions and 3 deletions

View File

@ -603,7 +603,7 @@ extension ctlInputMethod: KeyHandlerDelegate {
if !state.validToWrite {
return false
}
mgrLangModel.writeUserPhrase(state.userPhrase, inputMode: keyHandler.inputMode)
mgrLangModel.writeUserPhrase(state.userPhrase, inputMode: keyHandler.inputMode, areWeDuplicating: state.chkIfUserPhraseExists)
return true
}
}

View File

@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (BOOL)checkIfUserDataFolderExists;
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:));
+ (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode;
+ (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode areWeDuplicating:(BOOL)areWeDuplicating;
+ (void)setPhraseReplacementEnabled:(BOOL)phraseReplacementEnabled;
+ (void)setCNSEnabled:(BOOL)cnsEnabled;
+ (NSString *)userPhrasesDataPath:(InputMode)mode;

View File

@ -219,7 +219,7 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
return NO;
}
+ (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode;
+ (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode areWeDuplicating:(BOOL)areWeDuplicating
{
if (![self checkIfUserLanguageModelFilesExist]) {
return NO;
@ -251,6 +251,9 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
// [currentMarkedPhrase appendString:@"\n"];
// }
[currentMarkedPhrase appendString:userPhrase];
if (areWeDuplicating) {
[currentMarkedPhrase appendString:@"\tFreqOverrideByDuplication"];
}
[currentMarkedPhrase appendString:@"\n"];
NSFileHandle *writeFile = [NSFileHandle fileHandleForUpdatingAtPath:path];