LMs // Use LMInstantiator to print loading statistics.

This commit is contained in:
ShikiSuen 2022-05-04 13:36:29 +08:00
parent 3bd8fa1ea7
commit 3260101b2f
5 changed files with 59 additions and 9 deletions

View File

@ -109,6 +109,10 @@ extension vChewing {
if FileManager.default.isReadableFile(atPath: path) { if FileManager.default.isReadableFile(atPath: path) {
lmCore.close() lmCore.close()
lmCore.open(path) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmCNS.close() lmCNS.close()
lmCNS.open(path) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmMisc.close() lmMisc.close()
lmMisc.open(path) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmSymbols.close() lmSymbols.close()
lmSymbols.open(path) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmUserPhrases.close() lmUserPhrases.close()
lmUserPhrases.open(path) 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) { if FileManager.default.isReadableFile(atPath: filterPath) {
lmFiltered.close() lmFiltered.close()
lmFiltered.open(filterPath) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmUserSymbols.close() lmUserSymbols.close()
lmUserSymbols.open(path) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmAssociates.close() lmAssociates.close()
lmAssociates.open(path) 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) { if FileManager.default.isReadableFile(atPath: path) {
lmReplacements.close() lmReplacements.close()
lmReplacements.open(path) lmReplacements.open(path)
IME.prtDebugIntel("lmReplacements: \(lmReplacements.count) entries of data loaded from: \(path)")
if path.contains("vChewing/") {
lmReplacements.dump()
}
} }
} }

View File

@ -81,7 +81,6 @@ extension vChewing {
keyValueMap[currentKV.key, default: []].append(currentKV) keyValueMap[currentKV.key, default: []].append(currentKV)
} }
} }
IME.prtDebugIntel("\(count) entries of data loaded from: \(path)")
return true 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]? { public func valuesFor(key: String) -> [String]? {
var v: [String] = [] var v: [String] = []
if let matched = keyValueMap[key] { if let matched = keyValueMap[key] {

View File

@ -115,7 +115,6 @@ extension vChewing {
keyValueScoreMap[key, default: []].append(currentUnigram) keyValueScoreMap[key, default: []].append(currentUnigram)
} }
} }
IME.prtDebugIntel("\(count) entries of data loaded from: \(path)")
return true return true
} }
@ -130,7 +129,7 @@ extension vChewing {
public func dump() { public func dump() {
var strDump = "" var strDump = ""
for entry in keyValueScoreMap { for entry in keyValueScoreMap {
let rows: [Megrez.Unigram] = entry.1 let rows: [Megrez.Unigram] = entry.value
for row in rows { for row in rows {
let addline = row.keyValue.key + " " + row.keyValue.value + " " + String(row.score) + "\n" let addline = row.keyValue.key + " " + row.keyValue.value + " " + String(row.score) + "\n"
strDump += addline strDump += addline

View File

@ -46,6 +46,7 @@ extension vChewing {
@discardableResult public mutating func open(_ path: String) -> Bool { @discardableResult public mutating func open(_ path: String) -> Bool {
if isLoaded() { if isLoaded() {
IME.prtDebugIntel("Not loading this one due to isLoaded result of true: \(path)")
return false return false
} }
@ -85,10 +86,6 @@ extension vChewing {
keyValueMap[currentKV.key, default: []].append(currentKV) keyValueMap[currentKV.key, default: []].append(currentKV)
} }
} }
IME.prtDebugIntel("\(count) entries of data loaded from: \(path)")
if path.contains("vChewing/") {
dump()
}
return true return true
} }
@ -101,7 +98,7 @@ extension vChewing {
public func dump() { public func dump() {
var strDump = "" var strDump = ""
for entry in keyValueMap { for entry in keyValueMap {
let rows: [Megrez.KeyValuePair] = entry.1 let rows: [Megrez.KeyValuePair] = entry.value
for row in rows { for row in rows {
let addline = row.key + " " + row.value + "\n" let addline = row.key + " " + row.value + "\n"
strDump += addline strDump += addline

View File

@ -82,7 +82,6 @@ extension vChewing {
keyValueMap[currentKV.key] = currentKV.value keyValueMap[currentKV.key] = currentKV.value
} }
} }
IME.prtDebugIntel("\(count) entries of data loaded from: \(path)")
return true 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 { public func valuesFor(key: String) -> String {
keyValueMap[key] ?? "" keyValueMap[key] ?? ""
} }