From 651a8704402657a33795c159d0bc859f4f32756e Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 29 Mar 2022 10:31:38 +0800 Subject: [PATCH] LMs // Bind Syslog prints with debug conditions. --- Source/Modules/FileHandlers/LMConsolidator.mm | 29 ++++++++++--------- .../SubLanguageModels/AssociatedPhrases.mm | 2 +- .../SubLanguageModels/CoreLM.mm | 25 ++++++++-------- .../SubLanguageModels/PhraseReplacementMap.mm | 2 +- .../SubLanguageModels/UserPhrasesLM.mm | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Source/Modules/FileHandlers/LMConsolidator.mm b/Source/Modules/FileHandlers/LMConsolidator.mm index 0c26866d..8a9a7b4a 100644 --- a/Source/Modules/FileHandlers/LMConsolidator.mm +++ b/Source/Modules/FileHandlers/LMConsolidator.mm @@ -17,6 +17,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH */ #include "LMConsolidator.h" +#include "vChewing-Swift.h" namespace vChewing { @@ -31,13 +32,13 @@ bool LMConsolidator::CheckPragma(const char *path) { string firstLine; getline(zfdCheckPragma, firstLine); - syslog(LOG_CONS, "HEADER SEEN ||%s", firstLine.c_str()); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "HEADER SEEN ||%s", firstLine.c_str()); if (firstLine != FORMATTED_PRAGMA_HEADER) { - syslog(LOG_CONS, "HEADER VERIFICATION FAILED. START IN-PLACE CONSOLIDATING PROCESS."); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "HEADER VERIFICATION FAILED. START IN-PLACE CONSOLIDATING PROCESS."); return false; } } - syslog(LOG_CONS, "HEADER VERIFICATION SUCCESSFUL."); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "HEADER VERIFICATION SUCCESSFUL."); return true; } @@ -49,22 +50,22 @@ bool LMConsolidator::FixEOF(const char *path) char z; zfdEOFFixerIncomingStream.get(z); if(z!='\n'){ - syslog(LOG_CONS, "// REPORT: Data File not ended with a new line.\n"); - syslog(LOG_CONS, "// DATA FILE: %s", path); - syslog(LOG_CONS, "// PROCEDURE: Trying to insert a new line as EOF before per-line check process.\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Data File not ended with a new line.\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// PROCEDURE: Trying to insert a new line as EOF before per-line check process.\n"); std::ofstream zfdEOFFixerOutput(path, std::ios_base::app); zfdEOFFixerOutput << std::endl; zfdEOFFixerOutput.close(); if (zfdEOFFixerOutput.fail()) { - syslog(LOG_CONS, "// REPORT: Failed to append a newline to the data file. Insufficient Privileges?\n"); - syslog(LOG_CONS, "// DATA FILE: %s", path); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to append a newline to the data file. Insufficient Privileges?\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path); return false; } } zfdEOFFixerIncomingStream.close(); if (zfdEOFFixerIncomingStream.fail()) { - syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for EOF check. Insufficient Privileges?\n"); - syslog(LOG_CONS, "// DATA FILE: %s", path); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for EOF check. Insufficient Privileges?\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path); return false; } return true; @@ -118,14 +119,14 @@ bool LMConsolidator::ConsolidateContent(const char *path, bool shouldCheckPragma } zfdContentConsolidatorOutput.close(); if (zfdContentConsolidatorOutput.fail()) { - syslog(LOG_CONS, "// REPORT: Failed to write content-consolidated data to the file. Insufficient Privileges?\n"); - syslog(LOG_CONS, "// DATA FILE: %s", path); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to write content-consolidated data to the file. Insufficient Privileges?\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path); return false; } zfdContentConsolidatorIncomingStream.close(); if (zfdContentConsolidatorIncomingStream.fail()) { - syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for content-consolidation. Insufficient Privileges?\n"); - syslog(LOG_CONS, "// DATA FILE: %s", path); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for content-consolidation. Insufficient Privileges?\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path); return false; } return true; diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/AssociatedPhrases.mm b/Source/Modules/LangModelRelated/SubLanguageModels/AssociatedPhrases.mm index 1af8c9d0..430df6e7 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/AssociatedPhrases.mm +++ b/Source/Modules/LangModelRelated/SubLanguageModels/AssociatedPhrases.mm @@ -90,7 +90,7 @@ bool AssociatedPhrases::open(const char *path) // 下面這一段或許可以做成開關、來詢問是否對使用者語彙採取寬鬆策略(哪怕有行內容寫錯也會放行) if (state == KeyValueBlobReader::State::ERROR) { // close(); - syslog(LOG_CONS, "AssociatedPhrases: Failed at Open Step 5. On Error Resume Next.\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "AssociatedPhrases: Failed at Open Step 5. On Error Resume Next.\n"); // return false; } return true; diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm b/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm index 2f84c4c3..b9fae8fd 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm +++ b/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm @@ -24,6 +24,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include #include +#include "vChewing-Swift.h" using namespace Gramambular; @@ -123,7 +124,7 @@ start: c = *head; // \s -> error if (c == ' ') { - syslog(LOG_CONS, "vChewingDebug: CoreLM // Start: \\s -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // Start: \\s -> error"); goto error; } // \n -> start @@ -140,14 +141,14 @@ start: state1: // EOF -> error if (head == end) { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: EOF -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: EOF -> error"); goto error; } c = *head; // \n -> error if (c == '\n') { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: \\n -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: \\n -> error"); goto error; } // \s -> state2 + zero out ending + record column start @@ -165,14 +166,14 @@ state1: state2: // eof -> error if (head == end) { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: EOF -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: EOF -> error"); goto error; } c = *head; // \n, \s -> error if (c == '\n' || c == ' ') { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: \\n \\s -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: \\n \\s -> error"); goto error; } @@ -184,7 +185,7 @@ state2: state3: // eof -> error if (head == end) { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: EOF -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: EOF -> error"); goto error; } @@ -192,7 +193,7 @@ state3: // \n -> error if (c == '\n') { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: \\n -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: \\n -> error"); goto error; } // \s -> state4 + zero out ending + record column start @@ -210,14 +211,14 @@ state3: state4: // eof -> error if (head == end) { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: EOF -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: EOF -> error"); goto error; } c = *head; // \n, \s -> error if (c == '\n' || c == ' ') { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: \\n \\s -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: \\n \\s -> error"); goto error; } @@ -230,14 +231,14 @@ state4: state5: // eof -> error if (head == end) { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: EOF -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: EOF -> error"); goto error; } c = *head; // \s -> error if (c == ' ') { - syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: \\s -> error"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: \\s -> error"); goto error; } // \n -> start @@ -264,7 +265,7 @@ end: emptyRow.value = space; emptyRow.logProbability = zero; keyRowMap[space].push_back(emptyRow); - syslog(LOG_CONS, "vChewingDebug: CoreLM // File Load Complete."); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // File Load Complete."); return true; } diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/PhraseReplacementMap.mm b/Source/Modules/LangModelRelated/SubLanguageModels/PhraseReplacementMap.mm index 835c24b6..b3a10e49 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/PhraseReplacementMap.mm +++ b/Source/Modules/LangModelRelated/SubLanguageModels/PhraseReplacementMap.mm @@ -85,7 +85,7 @@ bool PhraseReplacementMap::open(const char *path) // 下面這一段或許可以做成開關、來詢問是否對使用者語彙採取寬鬆策略(哪怕有行內容寫錯也會放行) if (state == KeyValueBlobReader::State::ERROR) { // close(); - syslog(LOG_CONS, "PhraseReplacementMap: Failed at Open Step 5. On Error Resume Next.\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "PhraseReplacementMap: Failed at Open Step 5. On Error Resume Next.\n"); // return false; } return true; diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm b/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm index f530f21f..b62db2db 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm +++ b/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm @@ -94,7 +94,7 @@ bool UserPhrasesLM::open(const char *path) // 下面這一段或許可以做成開關、來詢問是否對使用者語彙採取寬鬆策略(哪怕有行內容寫錯也會放行) if (state == KeyValueBlobReader::State::ERROR) { // close(); - syslog(LOG_CONS, "UserPhrasesLM: Failed at Open Step 5. On Error Resume Next.\n"); + if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "UserPhrasesLM: Failed at Open Step 5. On Error Resume Next.\n"); // return false; } return true;