From 3260101b2fde189ae44d1e5e144db26e7ea06ffd Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 4 May 2022 13:36:29 +0800 Subject: [PATCH] LMs // Use LMInstantiator to print loading statistics. --- .../LangModelRelated/LMInstantiator.swift | 36 +++++++++++++++++++ .../SubLMs/lmAssociates.swift | 13 ++++++- .../LangModelRelated/SubLMs/lmCore.swift | 3 +- .../LangModelRelated/SubLMs/lmLite.swift | 7 ++-- .../SubLMs/lmReplacements.swift | 9 ++++- 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/Source/Modules/LangModelRelated/LMInstantiator.swift b/Source/Modules/LangModelRelated/LMInstantiator.swift index 0cd908cd..f0f241c1 100644 --- a/Source/Modules/LangModelRelated/LMInstantiator.swift +++ b/Source/Modules/LangModelRelated/LMInstantiator.swift @@ -109,6 +109,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmCore.close() lmCore.open(path) + IME.prtDebugIntel("lmCore: \(lmCore.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmCore.dump() + } } } @@ -117,6 +121,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmCNS.close() lmCNS.open(path) + IME.prtDebugIntel("lmCNS: \(lmCNS.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmCNS.dump() + } } } @@ -125,6 +133,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmMisc.close() lmMisc.open(path) + IME.prtDebugIntel("lmMisc: \(lmMisc.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmMisc.dump() + } } } @@ -133,6 +145,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmSymbols.close() lmSymbols.open(path) + IME.prtDebugIntel("lmSymbol: \(lmSymbols.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmSymbols.dump() + } } } @@ -140,10 +156,18 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmUserPhrases.close() lmUserPhrases.open(path) + IME.prtDebugIntel("lmUserPhrases: \(lmUserPhrases.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmUserPhrases.dump() + } } if FileManager.default.isReadableFile(atPath: filterPath) { lmFiltered.close() lmFiltered.open(filterPath) + IME.prtDebugIntel("lmFiltered: \(lmFiltered.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmFiltered.dump() + } } } @@ -151,6 +175,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmUserSymbols.close() lmUserSymbols.open(path) + IME.prtDebugIntel("lmUserSymbol: \(lmUserSymbols.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmUserSymbols.dump() + } } } @@ -158,6 +186,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmAssociates.close() lmAssociates.open(path) + IME.prtDebugIntel("lmAssociates: \(lmAssociates.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmAssociates.dump() + } } } @@ -165,6 +197,10 @@ extension vChewing { if FileManager.default.isReadableFile(atPath: path) { lmReplacements.close() lmReplacements.open(path) + IME.prtDebugIntel("lmReplacements: \(lmReplacements.count) entries of data loaded from: \(path)") + if path.contains("vChewing/") { + lmReplacements.dump() + } } } diff --git a/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift b/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift index 676cb7af..676907b0 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift @@ -81,7 +81,6 @@ extension vChewing { keyValueMap[currentKV.key, default: []].append(currentKV) } } - IME.prtDebugIntel("\(count) entries of data loaded from: \(path)") return true } @@ -91,6 +90,18 @@ extension vChewing { } } + public func dump() { + var strDump = "" + for entry in keyValueMap { + let rows: [Megrez.KeyValuePair] = entry.value + for row in rows { + let addline = row.key + " " + row.value + "\n" + strDump += addline + } + } + IME.prtDebugIntel(strDump) + } + public func valuesFor(key: String) -> [String]? { var v: [String] = [] if let matched = keyValueMap[key] { diff --git a/Source/Modules/LangModelRelated/SubLMs/lmCore.swift b/Source/Modules/LangModelRelated/SubLMs/lmCore.swift index 2d45bd92..158fd3ef 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmCore.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmCore.swift @@ -115,7 +115,6 @@ extension vChewing { keyValueScoreMap[key, default: []].append(currentUnigram) } } - IME.prtDebugIntel("\(count) entries of data loaded from: \(path)") return true } @@ -130,7 +129,7 @@ extension vChewing { public func dump() { var strDump = "" for entry in keyValueScoreMap { - let rows: [Megrez.Unigram] = entry.1 + let rows: [Megrez.Unigram] = entry.value for row in rows { let addline = row.keyValue.key + " " + row.keyValue.value + " " + String(row.score) + "\n" strDump += addline diff --git a/Source/Modules/LangModelRelated/SubLMs/lmLite.swift b/Source/Modules/LangModelRelated/SubLMs/lmLite.swift index eddd4dda..4a44b080 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmLite.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmLite.swift @@ -46,6 +46,7 @@ extension vChewing { @discardableResult public mutating func open(_ path: String) -> Bool { if isLoaded() { + IME.prtDebugIntel("Not loading this one due to isLoaded result of true: \(path)") return false } @@ -85,10 +86,6 @@ extension vChewing { keyValueMap[currentKV.key, default: []].append(currentKV) } } - IME.prtDebugIntel("\(count) entries of data loaded from: \(path)") - if path.contains("vChewing/") { - dump() - } return true } @@ -101,7 +98,7 @@ extension vChewing { public func dump() { var strDump = "" for entry in keyValueMap { - let rows: [Megrez.KeyValuePair] = entry.1 + let rows: [Megrez.KeyValuePair] = entry.value for row in rows { let addline = row.key + " " + row.value + "\n" strDump += addline diff --git a/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift b/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift index 5379fcb6..15793cd3 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift @@ -82,7 +82,6 @@ extension vChewing { keyValueMap[currentKV.key] = currentKV.value } } - IME.prtDebugIntel("\(count) entries of data loaded from: \(path)") return true } @@ -92,6 +91,14 @@ extension vChewing { } } + public func dump() { + var strDump = "" + for entry in keyValueMap { + strDump += entry.key + " " + entry.value + "\n" + } + IME.prtDebugIntel(strDump) + } + public func valuesFor(key: String) -> String { keyValueMap[key] ?? "" }