LMI // Introducing hasKeyValuePairFor(), using it in LMMgr.
This commit is contained in:
parent
45f595920a
commit
7c3d90dc80
|
@ -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: 對應的經過處理的單元圖陣列。
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue