AssoPhrases // Making the function user-customizable.
This commit is contained in:
parent
ecc01c3f84
commit
13429be47b
|
@ -147,6 +147,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
|||
if Preferences.shouldAutoReloadUserDataFiles {
|
||||
mgrLangModel.loadUserPhrases()
|
||||
mgrLangModel.loadUserPhraseReplacement()
|
||||
mgrLangModel.loadUserAssociatedPhrases()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +174,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
|||
mgrLangModel.loadDataModels() // 這句還是不要砍了。
|
||||
mgrLangModel.loadUserPhrases()
|
||||
mgrLangModel.loadUserPhraseReplacement()
|
||||
mgrLangModel.loadUserAssociatedPhrases()
|
||||
fsStreamHelper.delegate = self
|
||||
_ = fsStreamHelper.start()
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (void)loadDataModel:(InputMode)mode;
|
||||
+ (void)loadUserPhrases;
|
||||
+ (void)loadUserAssociatedPhrases;
|
||||
+ (void)loadUserPhraseReplacement;
|
||||
+ (void)setupDataModelValueConverter;
|
||||
+ (BOOL)checkIfUserLanguageModelFilesExist;
|
||||
|
@ -36,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (void)setPhraseReplacementEnabled:(BOOL)phraseReplacementEnabled;
|
||||
+ (void)setCNSEnabled:(BOOL)cnsEnabled;
|
||||
+ (NSString *)userPhrasesDataPath:(InputMode)mode;
|
||||
+ (NSString *)userAssociatedPhrasesDataPath:(InputMode)mode;
|
||||
+ (NSString *)excludedPhrasesDataPath:(InputMode)mode;
|
||||
+ (NSString *)phraseReplacementDataPath:(InputMode)mode;
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ static UserOverrideModel gUserOverrideModelCHT(kUserOverrideModelCapacity, kObse
|
|||
static UserOverrideModel gUserOverrideModelCHS(kUserOverrideModelCapacity, kObservedOverrideHalflife);
|
||||
|
||||
static NSString *const kUserDataTemplateName = @"template-data";
|
||||
static NSString *const kUserAssDataTemplateName = @"template-data";
|
||||
static NSString *const kExcludedPhrasesvChewingTemplateName = @"template-exclude-phrases";
|
||||
static NSString *const kPhraseReplacementTemplateName = @"template-phrases-replacement";
|
||||
static NSString *const kTemplateExtension = @".txt";
|
||||
|
@ -46,13 +47,6 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
|
|||
lm.loadLanguageModel([dataPath UTF8String]);
|
||||
}
|
||||
|
||||
static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
||||
{
|
||||
Class cls = NSClassFromString(@"ctlInputMethod");
|
||||
NSString *dataPath = [[NSBundle bundleForClass:cls] pathForResource:@"assPhrases" ofType:@"txt"];
|
||||
lm.loadAssociatedPhrases([dataPath UTF8String]);
|
||||
}
|
||||
|
||||
+ (void)loadDataModels
|
||||
{
|
||||
if (!gLangModelCHT.isDataModelLoaded()) {
|
||||
|
@ -61,18 +55,12 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (!gLangModelCHT.isCNSDataLoaded()){
|
||||
gLangModelCHT.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHT.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHT);
|
||||
}
|
||||
if (!gLangModelCHS.isDataModelLoaded()) {
|
||||
LTLoadLanguageModelFile(@"data-chs", gLangModelCHS);
|
||||
}
|
||||
if (!gLangModelCHS.isCNSDataLoaded()){
|
||||
gLangModelCHS.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHS.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHS);
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)loadDataModel:(InputMode)mode
|
||||
|
@ -84,9 +72,6 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (!gLangModelCHT.isCNSDataLoaded()){
|
||||
gLangModelCHT.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHT.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHT);
|
||||
}
|
||||
}
|
||||
|
||||
if ([mode isEqualToString:imeModeCHS]) {
|
||||
|
@ -96,9 +81,6 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (!gLangModelCHS.isCNSDataLoaded()){
|
||||
gLangModelCHS.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHS.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,6 +90,12 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
gLangModelCHS.loadUserPhrases([[self userPhrasesDataPath:imeModeCHS] UTF8String], [[self excludedPhrasesDataPath:imeModeCHS] UTF8String]);
|
||||
}
|
||||
|
||||
+ (void)loadUserAssociatedPhrases
|
||||
{
|
||||
gLangModelCHT.loadUserAssociatedPhrases([[self userAssociatedPhrasesDataPath:imeModeCHT] UTF8String]);
|
||||
gLangModelCHS.loadUserAssociatedPhrases([[self userAssociatedPhrasesDataPath:imeModeCHS] UTF8String]);
|
||||
}
|
||||
|
||||
+ (void)loadUserPhraseReplacement
|
||||
{
|
||||
gLangModelCHT.loadPhraseReplacementMap([[self phraseReplacementDataPath:imeModeCHT] UTF8String]);
|
||||
|
@ -197,6 +185,12 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (![self ensureFileExists:[self userPhrasesDataPath:imeModeCHT] populateWithTemplate:kUserDataTemplateName extension:kTemplateExtension]) {
|
||||
return NO;
|
||||
}
|
||||
if (![self ensureFileExists:[self userAssociatedPhrasesDataPath:imeModeCHS] populateWithTemplate:kUserAssDataTemplateName extension:kTemplateExtension]) {
|
||||
return NO;
|
||||
}
|
||||
if (![self ensureFileExists:[self userAssociatedPhrasesDataPath:imeModeCHT] populateWithTemplate:kUserAssDataTemplateName extension:kTemplateExtension]) {
|
||||
return NO;
|
||||
}
|
||||
if (![self ensureFileExists:[self excludedPhrasesDataPath:imeModeCHS] populateWithTemplate:kExcludedPhrasesvChewingTemplateName extension:kTemplateExtension]) {
|
||||
return NO;
|
||||
}
|
||||
|
@ -288,6 +282,12 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
return [[self dataFolderPath] stringByAppendingPathComponent:fileName];
|
||||
}
|
||||
|
||||
+ (NSString *)userAssociatedPhrasesDataPath:(InputMode)mode;
|
||||
{
|
||||
NSString *fileName = [mode isEqualToString:imeModeCHT] ? @"associatedPhrases-cht.txt" : @"associatedPhrases-chs.txt";
|
||||
return [[self dataFolderPath] stringByAppendingPathComponent:fileName];
|
||||
}
|
||||
|
||||
+ (NSString *)excludedPhrasesDataPath:(InputMode)mode;
|
||||
{
|
||||
NSString *fileName = [mode isEqualToString:imeModeCHT] ? @"exclude-phrases-cht.txt" : @"exclude-phrases-chs.txt";
|
||||
|
|
|
@ -71,16 +71,13 @@ public:
|
|||
/// If the data model is already loaded.
|
||||
bool isCNSDataLoaded();
|
||||
|
||||
/// Asks to load the associated phrases at the given path.
|
||||
/// @param associatedPhrasesPath The path of the associated phrases.
|
||||
void loadAssociatedPhrases(const char* associatedPhrasesPath);
|
||||
/// If the associated phrases already loaded.
|
||||
bool isAssociatedPhrasesLoaded();
|
||||
|
||||
/// Asks to load the user phrases and excluded phrases at the given path.
|
||||
/// @param userPhrasesPath The path of user phrases.
|
||||
/// @param excludedPhrasesPath The path of excluded phrases.
|
||||
void loadUserPhrases(const char* userPhrasesPath, const char* excludedPhrasesPath);
|
||||
/// Asks to load the user associated phrases at the given path.
|
||||
/// @param userAssociatedPhrasesPath The path of the phrase replacement table.
|
||||
void loadUserAssociatedPhrases(const char* userAssociatedPhrasesPath);
|
||||
/// Asks to load the phrase replacement table at the given path.
|
||||
/// @param phraseReplacementPath The path of the phrase replacement table.
|
||||
void loadPhraseReplacementMap(const char* phraseReplacementPath);
|
||||
|
|
|
@ -50,19 +50,6 @@ bool vChewingLM::isDataModelLoaded()
|
|||
return m_languageModel.isLoaded();
|
||||
}
|
||||
|
||||
void vChewingLM::loadAssociatedPhrases(const char* associatedPhrasesPath)
|
||||
{
|
||||
if (associatedPhrasesPath) {
|
||||
m_associatedPhrases.close();
|
||||
m_associatedPhrases.open(associatedPhrasesPath);
|
||||
}
|
||||
}
|
||||
|
||||
bool vChewingLM::isAssociatedPhrasesLoaded()
|
||||
{
|
||||
return m_associatedPhrases.isLoaded();
|
||||
}
|
||||
|
||||
void vChewingLM::loadCNSData(const char* cnsDataPath)
|
||||
{
|
||||
if (cnsDataPath) {
|
||||
|
@ -89,6 +76,14 @@ void vChewingLM::loadUserPhrases(const char* userPhrasesDataPath,
|
|||
}
|
||||
}
|
||||
|
||||
void vChewingLM::loadUserAssociatedPhrases(const char *userAssociatedPhrasesPath)
|
||||
{
|
||||
if (userAssociatedPhrasesPath) {
|
||||
m_associatedPhrases.close();
|
||||
m_associatedPhrases.open(userAssociatedPhrasesPath);
|
||||
}
|
||||
}
|
||||
|
||||
void vChewingLM::loadPhraseReplacementMap(const char* phraseReplacementPath)
|
||||
{
|
||||
if (phraseReplacementPath) {
|
||||
|
|
Loading…
Reference in New Issue