LMI // Stop reading factory plist dictionaries when using cassette mode.

This commit is contained in:
ShikiSuen 2022-10-19 21:23:17 +08:00
parent 234819030c
commit 3df9e692a7
1 changed files with 22 additions and 12 deletions

View File

@ -231,12 +231,20 @@ extension vChewingLM {
/// - Parameter key: /// - Parameter key:
/// - Returns: /// - Returns:
public func hasUnigramsFor(key: String) -> Bool { public func hasUnigramsFor(key: String) -> Bool {
if key == " " { return true } if key == " " || key.isEmpty { return true }
if !lmFiltered.hasUnigramsFor(key: key) { let isPeripheralKey: Bool = key.charComponents[0] == "_"
return lmUserPhrases.hasUnigramsFor(key: key) || lmCore.hasUnigramsFor(key: key) if !isCassetteEnabled || isPeripheralKey {
|| Self.lmCassette.hasUnigramsFor(key: key) || (Self.lmCNS.hasUnigramsFor(key: key) && isCNSEnabled) if !lmFiltered.hasUnigramsFor(key: key) {
return lmUserPhrases.hasUnigramsFor(key: key) || lmCore.hasUnigramsFor(key: key)
|| Self.lmCassette.hasUnigramsFor(key: key) || (Self.lmCNS.hasUnigramsFor(key: key) && isCNSEnabled)
}
return !unigramsFor(key: key).isEmpty
} else {
if !lmFiltered.hasUnigramsFor(key: key) {
return lmUserPhrases.hasUnigramsFor(key: key) || Self.lmCassette.hasUnigramsFor(key: key)
}
return !unigramsFor(key: key).isEmpty
} }
return !unigramsFor(key: key).isEmpty
} }
/// ///
@ -252,6 +260,7 @@ extension vChewingLM {
/// - Parameter key: /// - Parameter key:
/// - Returns: /// - Returns:
public func unigramsFor(key: String) -> [Megrez.Unigram] { public func unigramsFor(key: String) -> [Megrez.Unigram] {
guard !key.isEmpty else { return [] }
/// ///
if key == " " { return [.init(value: " ")] } if key == " " { return [.init(value: " ")] }
@ -270,17 +279,18 @@ extension vChewingLM {
// rawUserUnigrams // rawUserUnigrams
rawAllUnigrams += lmUserPhrases.unigramsFor(key: key).reversed() rawAllUnigrams += lmUserPhrases.unigramsFor(key: key).reversed()
// LMMisc LMCore score (-10.0, 0.0) if !isCassetteEnabled || isCassetteEnabled && key.charComponents[0] == "_" {
rawAllUnigrams += lmMisc.unigramsFor(key: key) // LMMisc LMCore score (-10.0, 0.0)
rawAllUnigrams += lmCore.unigramsFor(key: key) rawAllUnigrams += lmMisc.unigramsFor(key: key)
rawAllUnigrams += lmCore.unigramsFor(key: key)
if isCNSEnabled { if isCNSEnabled { rawAllUnigrams += Self.lmCNS.unigramsFor(key: key) }
rawAllUnigrams += Self.lmCNS.unigramsFor(key: key)
} }
if isSymbolEnabled { if isSymbolEnabled {
rawAllUnigrams += lmUserSymbols.unigramsFor(key: key) rawAllUnigrams += lmUserSymbols.unigramsFor(key: key)
rawAllUnigrams += Self.lmSymbols.unigramsFor(key: key) if !isCassetteEnabled {
rawAllUnigrams += Self.lmSymbols.unigramsFor(key: key)
}
} }
// //