LMInstantiator // Fix and simplify hasUnigramsFor().

This commit is contained in:
ShikiSuen 2022-10-24 17:35:22 +08:00
parent b8de232c3f
commit 8098ae8239
1 changed files with 1 additions and 14 deletions

View File

@ -231,20 +231,7 @@ extension vChewingLM {
/// - Parameter key:
/// - Returns:
public func hasUnigramsFor(key: String) -> Bool {
if key == " " || key.isEmpty { return true }
let isPeripheralKey: Bool = key.charComponents[0] == "_"
if !isCassetteEnabled || isPeripheralKey {
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
}
key == " " || (!unigramsFor(key: key).isEmpty && !key.isEmpty)
}
///