LMConsolidator // Removing Sorting Feature.

- This feature is now considered troublesome, considering that there is no way to control the sorting method in Cpp: Some people prefer sorting things alphabetically, and some prefer counting strokes, etc.
This commit is contained in:
ShikiSuen 2022-02-23 12:31:00 +08:00
parent 051203b081
commit 5b29153850
12 changed files with 12 additions and 101 deletions

View File

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

View File

@ -71,8 +71,8 @@ bool LMConsolidator::FixEOF(const char *path)
} // END: EOF FIXER.
// CONTENT CONSOLIDATOR. CREDIT: Shiki Suen.
bool LMConsolidator::ConsolidateContent(const char *path, bool shouldsort, bool shouldCheckPragma) {
if (LMConsolidator::CheckPragma(path) && !shouldsort && shouldCheckPragma){
bool LMConsolidator::ConsolidateContent(const char *path, bool shouldCheckPragma) {
if (LMConsolidator::CheckPragma(path) && shouldCheckPragma){
return true;
}
@ -97,8 +97,7 @@ bool LMConsolidator::ConsolidateContent(const char *path, bool shouldsort, bool
vecEntry[i] = regex_replace(vecEntry[i], sedTrailingSpace, "").c_str(); // 去掉行尾空格。
}
}
// 在第二遍 for 運算之前,針對 vecEntry 排序+去除重複條目。
if (shouldsort) {sort(vecEntry.begin(), vecEntry.end());} // 要不要排序,得做成開關。
// 在第二遍 for 運算之前,針對 vecEntry 去除重複條目。
vecEntry.erase(unique(vecEntry.begin(), vecEntry.end()), vecEntry.end()); // 去重複。
// 統整完畢。開始將統整過的內容寫入檔案。
ofstream zfdContentConsolidatorOutput(path); // 這裡是要從頭開始重寫檔案內容,所以不需要「 ios_base::app 」。

View File

@ -28,9 +28,6 @@ private let kFunctionKeyKeyboardLayoutOverrideIncludeShift = "FunctionKeyKeyboar
private let kCandidateListTextSize = "CandidateListTextSize"
private let kAppleLanguagesPreferences = "AppleLanguages"
private let kShouldAutoReloadUserDataFiles = "ShouldAutoReloadUserDataFiles"
private let kShouldAutoSortUserPhrasesAndExclListOnLoad = "ShouldAutoSortUserPhrasesAndExclListOnLoad"
private let kShouldAutoSortPhraseReplacementMapOnLoad = "ShouldAutoSortPhraseReplacementMapOnLoad"
private let kShouldAutoSortAssociatedPhrasesOnLoad = "ShouldAutoSortAssociatedPhrasesOnLoad"
private let kSelectPhraseAfterCursorAsCandidatePreference = "SelectPhraseAfterCursorAsCandidate"
private let kUseHorizontalCandidateListPreference = "UseHorizontalCandidateList"
private let kComposingBufferSizePreference = "ComposingBufferSize"
@ -222,9 +219,6 @@ struct ComposingBufferSize {
kCandidateListTextSize,
kAppleLanguagesPreferences,
kShouldAutoReloadUserDataFiles,
kShouldAutoSortUserPhrasesAndExclListOnLoad,
kShouldAutoSortPhraseReplacementMapOnLoad,
kShouldAutoSortAssociatedPhrasesOnLoad,
kSelectPhraseAfterCursorAsCandidatePreference,
kUseHorizontalCandidateListPreference,
kComposingBufferSizePreference,
@ -270,26 +264,11 @@ struct ComposingBufferSize {
UserDefaults.standard.set(Preferences.chooseCandidateUsingSpace, forKey: kChooseCandidateUsingSpace)
}
// 使
// 使
if UserDefaults.standard.object(forKey: kShouldAutoReloadUserDataFiles) == nil {
UserDefaults.standard.set(Preferences.shouldAutoReloadUserDataFiles, forKey: kShouldAutoReloadUserDataFiles)
}
//
if UserDefaults.standard.object(forKey: kShouldAutoSortUserPhrasesAndExclListOnLoad) == nil {
UserDefaults.standard.set(Preferences.shouldAutoSortUserPhrasesAndExclListOnLoad, forKey: kShouldAutoSortUserPhrasesAndExclListOnLoad)
}
//
if UserDefaults.standard.object(forKey: kShouldAutoSortAssociatedPhrasesOnLoad) == nil {
UserDefaults.standard.set(Preferences.shouldAutoSortAssociatedPhrasesOnLoad, forKey: kShouldAutoSortAssociatedPhrasesOnLoad)
}
// 使
if UserDefaults.standard.object(forKey: kShouldAutoSortPhraseReplacementMapOnLoad) == nil {
UserDefaults.standard.set(Preferences.shouldAutoSortPhraseReplacementMapOnLoad, forKey: kShouldAutoSortPhraseReplacementMapOnLoad)
}
// false
if UserDefaults.standard.object(forKey: kUseSCPCTypingMode) == nil {
UserDefaults.standard.set(Preferences.useSCPCTypingMode, forKey: kUseSCPCTypingMode)
@ -371,15 +350,6 @@ struct ComposingBufferSize {
@UserDefault(key: kShouldAutoReloadUserDataFiles, defaultValue: true)
@objc static var shouldAutoReloadUserDataFiles: Bool
@UserDefault(key: kShouldAutoSortUserPhrasesAndExclListOnLoad, defaultValue: false)
@objc static var shouldAutoSortUserPhrasesAndExclListOnLoad: Bool
@UserDefault(key: kShouldAutoSortPhraseReplacementMapOnLoad, defaultValue: false)
@objc static var shouldAutoSortPhraseReplacementMapOnLoad: Bool
@UserDefault(key: kShouldAutoSortAssociatedPhrasesOnLoad, defaultValue: false)
@objc static var shouldAutoSortAssociatedPhrasesOnLoad: Bool
@UserDefault(key: kSelectPhraseAfterCursorAsCandidatePreference, defaultValue: true)
@objc static var selectPhraseAfterCursorAsCandidate: Bool

View File

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

View File

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

View File

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

View File

@ -266,7 +266,7 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
[writeFile closeFile];
// We enforce the format consolidation here, since the pragma header will let the UserPhraseLM bypasses the consolidating process on load.
vChewing::LMConsolidator::ConsolidateContent([path UTF8String], Preferences.shouldAutoSortUserPhrasesAndExclListOnLoad, false);
vChewing::LMConsolidator::ConsolidateContent([path UTF8String], false);
// We use FSEventStream to monitor the change of the user phrase folder,
// so we don't have to load data here unless FSEventStream is disabled by user.

View File

@ -503,36 +503,8 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button translatesAutoresizingMaskIntoConstraints="NO" id="1hA-Po-5li">
<rect key="frame" x="19" y="94.5" width="401" height="17"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="288" id="0mm-CA-Mxs"/>
<constraint firstAttribute="height" constant="16" id="c3e-cU-pEw"/>
</constraints>
<buttonCell key="cell" type="check" title="Sort entries when reloading user phrases and excluded phrases list" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" state="on" inset="2" id="Li3-Yg-SOC">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
<connections>
<binding destination="32" name="value" keyPath="values.ShouldAutoSortUserPhrasesAndExclListOnLoad" id="k4w-CX-EfE"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nnT-wS-mZo">
<rect key="frame" x="19" y="72.5" width="342" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="16" id="IBn-Xf-uEw"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="234" id="srn-3X-kPi"/>
</constraints>
<buttonCell key="cell" type="check" title="Sort entries when reloading the phrase replacement map" bezelStyle="regularSquare" imagePosition="left" controlSize="small" state="on" inset="2" id="o60-vW-i1B">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
<connections>
<binding destination="32" name="value" keyPath="values.ShouldAutoSortPhraseReplacementMapOnLoad" id="Xn2-So-Dp3"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="p7V-IN-OTr">
<rect key="frame" x="19" y="51.5" width="336" height="17"/>
<rect key="frame" x="19" y="93.5" width="336" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="16" id="8eX-Tw-Erk"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="234" id="yhP-XF-CQj"/>
@ -548,17 +520,11 @@
</subviews>
<constraints>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="dnE-Vw-KrP" secondAttribute="trailing" constant="214" id="3wA-Rn-cTn"/>
<constraint firstItem="nnT-wS-mZo" firstAttribute="leading" secondItem="p7V-IN-OTr" secondAttribute="leading" id="4di-W1-ufn"/>
<constraint firstItem="1hA-Po-5li" firstAttribute="leading" secondItem="nnT-wS-mZo" secondAttribute="leading" id="Cfb-2F-MRg"/>
<constraint firstItem="1hA-Po-5li" firstAttribute="leading" secondItem="dnE-Vw-KrP" secondAttribute="leading" id="Exw-iA-Unz"/>
<constraint firstItem="1hA-Po-5li" firstAttribute="top" secondItem="dnE-Vw-KrP" secondAttribute="bottom" constant="6.5" id="HrQ-4q-l78"/>
<constraint firstItem="p7V-IN-OTr" firstAttribute="top" secondItem="dnE-Vw-KrP" secondAttribute="bottom" constant="7.5" id="Arf-UU-TPA"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="p7V-IN-OTr" secondAttribute="trailing" constant="20" symbolic="YES" id="MFR-05-QJN"/>
<constraint firstItem="p7V-IN-OTr" firstAttribute="leading" secondItem="dnE-Vw-KrP" secondAttribute="leading" id="MO7-eJ-fcH"/>
<constraint firstItem="dnE-Vw-KrP" firstAttribute="leading" secondItem="rWB-y8-q94" secondAttribute="leading" constant="20" id="QQJ-7P-HAG"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="nnT-wS-mZo" secondAttribute="trailing" constant="101" id="QsT-xW-prJ"/>
<constraint firstItem="dnE-Vw-KrP" firstAttribute="top" secondItem="rWB-y8-q94" secondAttribute="top" constant="15" id="Vzj-xd-Q2W"/>
<constraint firstItem="p7V-IN-OTr" firstAttribute="top" secondItem="nnT-wS-mZo" secondAttribute="bottom" constant="5" id="gRe-fD-67h"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="1hA-Po-5li" secondAttribute="trailing" constant="39" id="quD-Rd-uwL"/>
<constraint firstItem="nnT-wS-mZo" firstAttribute="top" secondItem="1hA-Po-5li" secondAttribute="bottom" constant="6" symbolic="YES" id="zxn-Pa-o6f"/>
</constraints>
</view>
<constraints>

View File

@ -134,9 +134,6 @@
/* Class = "NSMenuItem"; title = "Auto-Select"; ObjectID = "GlJ-Ns-9eE"; */
"GlJ-Ns-9eE.title" = "Auto-Select";
/* Class = "NSButtonCell"; title = "Sort entries when reloading user phrases and excluded phrases list"; ObjectID = "Li3-Yg-SOC"; */
"Li3-Yg-SOC.title" = "Sort entries when reloading user phrases and excluded phrases list";
/* Class = "NSTabViewItem"; label = "General"; ObjectID = "QUQ-oY-4Hc"; */
"QUQ-oY-4Hc.label" = "General";
@ -188,9 +185,6 @@
/* Class = "NSComboBoxCell"; jQC-12-UuK.ibShadowedObjectValues[2] = "Item 3"; ObjectID = "jQC-12-UuK"; */
"jQC-12-UuK.ibShadowedObjectValues[2]" = "Item 3";
/* Class = "NSButtonCell"; title = "Sort entries when reloading the phrase replacement map"; ObjectID = "o60-vW-i1B"; */
"o60-vW-i1B.title" = "Sort entries when reloading the phrase replacement map";
/* Class = "NSMenuItem"; title = "Japanese"; ObjectID = "rVQ-Hx-cGi"; */
"rVQ-Hx-cGi.title" = "Japanese";

View File

@ -134,9 +134,6 @@
/* Class = "NSMenuItem"; title = "Auto-Select"; ObjectID = "GlJ-Ns-9eE"; */
"GlJ-Ns-9eE.title" = "システム設定に準ずる";
/* Class = "NSButtonCell"; title = "Sort entries when reloading user phrases and excluded phrases list"; ObjectID = "Li3-Yg-SOC"; */
"Li3-Yg-SOC.title" = "ユーザー辞書と条目排除表を読み込むときに、内容の順番を整う";
/* Class = "NSTabViewItem"; label = "General"; ObjectID = "QUQ-oY-4Hc"; */
"QUQ-oY-4Hc.label" = "全般";
@ -188,9 +185,6 @@
/* Class = "NSComboBoxCell"; jQC-12-UuK.ibShadowedObjectValues[2] = "Item 3"; ObjectID = "jQC-12-UuK"; */
"jQC-12-UuK.ibShadowedObjectValues[2]" = "Item 3";
/* Class = "NSButtonCell"; title = "Sort entries when reloading the phrase replacement map"; ObjectID = "o60-vW-i1B"; */
"o60-vW-i1B.title" = "言葉置換表を読み込むときに、内容の順番を整う";
/* Class = "NSMenuItem"; title = "Japanese"; ObjectID = "rVQ-Hx-cGi"; */
"rVQ-Hx-cGi.title" = "和語";

View File

@ -134,9 +134,6 @@
/* Class = "NSMenuItem"; title = "Auto-Select"; ObjectID = "GlJ-Ns-9eE"; */
"GlJ-Ns-9eE.title" = "自动选择";
/* Class = "NSButtonCell"; title = "Sort entries when reloading user phrases and excluded phrases list"; ObjectID = "Li3-Yg-SOC"; */
"Li3-Yg-SOC.title" = "在重新加载自订语汇与滤除语汇时,统整档案内容排序";
/* Class = "NSTabViewItem"; label = "General"; ObjectID = "QUQ-oY-4Hc"; */
"QUQ-oY-4Hc.label" = "一般";
@ -188,9 +185,6 @@
/* Class = "NSComboBoxCell"; jQC-12-UuK.ibShadowedObjectValues[2] = "Item 3"; ObjectID = "jQC-12-UuK"; */
"jQC-12-UuK.ibShadowedObjectValues[2]" = "Item 3";
/* Class = "NSButtonCell"; title = "Sort entries when reloading the phrase replacement map"; ObjectID = "o60-vW-i1B"; */
"o60-vW-i1B.title" = "在重新加载语汇滤除表时,统整档案内容排序";
/* Class = "NSMenuItem"; title = "Japanese"; ObjectID = "rVQ-Hx-cGi"; */
"rVQ-Hx-cGi.title" = "和语";

View File

@ -134,9 +134,6 @@
/* Class = "NSMenuItem"; title = "Auto-Select"; ObjectID = "GlJ-Ns-9eE"; */
"GlJ-Ns-9eE.title" = "自動選擇";
/* Class = "NSButtonCell"; title = "Sort entries when reloading user phrases and excluded phrases list"; ObjectID = "Li3-Yg-SOC"; */
"Li3-Yg-SOC.title" = "在重新載入自訂語彙與濾除語彙時,統整檔案內容排序";
/* Class = "NSTabViewItem"; label = "General"; ObjectID = "QUQ-oY-4Hc"; */
"QUQ-oY-4Hc.label" = "一般";
@ -188,9 +185,6 @@
/* Class = "NSComboBoxCell"; jQC-12-UuK.ibShadowedObjectValues[2] = "Item 3"; ObjectID = "jQC-12-UuK"; */
"jQC-12-UuK.ibShadowedObjectValues[2]" = "Item 3";
/* Class = "NSButtonCell"; title = "Sort entries when reloading the phrase replacement map"; ObjectID = "o60-vW-i1B"; */
"o60-vW-i1B.title" = "在重新載入語彙濾除表時,統整檔案內容排序";
/* Class = "NSMenuItem"; title = "Japanese"; ObjectID = "rVQ-Hx-cGi"; */
"rVQ-Hx-cGi.title" = "和語";