LMI // Introducing hasKeyValuePairFor(), using it in LMMgr.

This commit is contained in:
ShikiSuen 2022-09-24 09:28:14 +08:00
parent 45f595920a
commit 7c3d90dc80
2 changed files with 13 additions and 9 deletions

View File

@ -221,6 +221,15 @@ extension vChewingLM {
return !unigramsFor(key: key).isEmpty
}
///
/// - Parameters:
/// - key:
/// - value:
/// - Returns:
public func hasKeyValuePairFor(key: String, value: String) -> Bool {
unigramsFor(key: key).map(\.value).contains(value)
}
/// LMI
/// - Parameter key:
/// - Returns:

View File

@ -8,7 +8,6 @@
import BookmarkManager
import LangModelAssembly
import Megrez
import NotifierUI
import Shared
@ -245,15 +244,11 @@ public enum LMMgr {
mode: Shared.InputMode,
key unigramKey: String
) -> Bool {
let unigrams: [Megrez.Unigram] =
(mode == .imeModeCHT)
? Self.lmCHT.unigramsFor(key: unigramKey) : Self.lmCHS.unigramsFor(key: unigramKey)
for unigram in unigrams {
if unigram.value == userPhrase {
return true
}
switch mode {
case .imeModeCHS: return lmCHS.hasKeyValuePairFor(key: unigramKey, value: userPhrase)
case .imeModeCHT: return lmCHT.hasKeyValuePairFor(key: unigramKey, value: userPhrase)
case .imeModeNULL: return false
}
return false
}
public static func setPhraseReplacementEnabled(_ state: Bool) {