LMConsolidator // Add another option to allow force-consolidate, etc.

This commit is contained in:
ShikiSuen 2022-02-16 17:24:20 +08:00
parent 75f3c371a3
commit 37a96851ea
6 changed files with 9 additions and 22 deletions

View File

@ -37,7 +37,7 @@ class LMConsolidator
public: public:
static bool CheckPragma(const char *path); static bool CheckPragma(const char *path);
static bool FixEOF(const char *path); static bool FixEOF(const char *path);
static bool ConsolidateContent(const char *path, bool shouldsort); static bool ConsolidateContent(const char *path, bool shouldsort, bool shouldCheckPragma);
}; };
} // namespace vChewing } // namespace vChewing

View File

@ -71,8 +71,8 @@ bool LMConsolidator::FixEOF(const char *path)
} // END: EOF FIXER. } // END: EOF FIXER.
// CONTENT CONSOLIDATOR. CREDIT: Shiki Suen. // CONTENT CONSOLIDATOR. CREDIT: Shiki Suen.
bool LMConsolidator::ConsolidateContent(const char *path, bool shouldsort) { bool LMConsolidator::ConsolidateContent(const char *path, bool shouldsort, bool shouldCheckPragma) {
if (LMConsolidator::CheckPragma(path) && !shouldsort){ if (LMConsolidator::CheckPragma(path) && !shouldsort && shouldCheckPragma){
return true; return true;
} }

View File

@ -59,12 +59,7 @@ bool AssociatedPhrases::open(const char *path)
} }
LMConsolidator::FixEOF(path); LMConsolidator::FixEOF(path);
LMConsolidator::ConsolidateContent(path, Preferences.shouldAutoSortAssociatedPhrasesOnLoad, true);
if (Preferences.shouldAutoSortAssociatedPhrasesOnLoad) {
LMConsolidator::ConsolidateContent(path, true);
} else {
LMConsolidator::ConsolidateContent(path, false);
}
fd = ::open(path, O_RDONLY); fd = ::open(path, O_RDONLY);
if (fd == -1) { if (fd == -1) {

View File

@ -54,12 +54,7 @@ bool PhraseReplacementMap::open(const char *path)
} }
LMConsolidator::FixEOF(path); LMConsolidator::FixEOF(path);
LMConsolidator::ConsolidateContent(path, Preferences.shouldAutoSortPhraseReplacementMapOnLoad, true);
if (Preferences.shouldAutoSortPhraseReplacementMapOnLoad) {
LMConsolidator::ConsolidateContent(path, true);
} else {
LMConsolidator::ConsolidateContent(path, false);
}
fd = ::open(path, O_RDONLY); fd = ::open(path, O_RDONLY);
if (fd == -1) { if (fd == -1) {

View File

@ -60,12 +60,7 @@ bool UserPhrasesLM::open(const char *path)
} }
LMConsolidator::FixEOF(path); LMConsolidator::FixEOF(path);
LMConsolidator::ConsolidateContent(path, Preferences.shouldAutoSortUserPhrasesAndExclListOnLoad, true);
if (Preferences.shouldAutoSortUserPhrasesAndExclListOnLoad) {
LMConsolidator::ConsolidateContent(path, true);
} else {
LMConsolidator::ConsolidateContent(path, false);
}
fd = ::open(path, O_RDONLY); fd = ::open(path, O_RDONLY);
if (fd == -1) { if (fd == -1) {

View File

@ -252,7 +252,9 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
// } // }
[currentMarkedPhrase appendString:userPhrase]; [currentMarkedPhrase appendString:userPhrase];
if (areWeDuplicating) { if (areWeDuplicating) {
[currentMarkedPhrase appendString:@"\tFreqOverrideByDuplication"]; // Do not use ASCII characters to comment here.
// Otherwise, it will be scrambled by HYPY2BPMF module shipped in the vChewing Phrase Editor.
[currentMarkedPhrase appendString:@"\t#𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎"];
} }
[currentMarkedPhrase appendString:@"\n"]; [currentMarkedPhrase appendString:@"\n"];