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
|
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 給出對應的經過處理的單元圖陣列。
|
/// 給定讀音字串,讓 LMI 給出對應的經過處理的單元圖陣列。
|
||||||
/// - Parameter key: 給定的讀音字串。
|
/// - Parameter key: 給定的讀音字串。
|
||||||
/// - Returns: 對應的經過處理的單元圖陣列。
|
/// - Returns: 對應的經過處理的單元圖陣列。
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import BookmarkManager
|
import BookmarkManager
|
||||||
import LangModelAssembly
|
import LangModelAssembly
|
||||||
import Megrez
|
|
||||||
import NotifierUI
|
import NotifierUI
|
||||||
import Shared
|
import Shared
|
||||||
|
|
||||||
|
@ -245,15 +244,11 @@ public enum LMMgr {
|
||||||
mode: Shared.InputMode,
|
mode: Shared.InputMode,
|
||||||
key unigramKey: String
|
key unigramKey: String
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let unigrams: [Megrez.Unigram] =
|
switch mode {
|
||||||
(mode == .imeModeCHT)
|
case .imeModeCHS: return lmCHS.hasKeyValuePairFor(key: unigramKey, value: userPhrase)
|
||||||
? Self.lmCHT.unigramsFor(key: unigramKey) : Self.lmCHS.unigramsFor(key: unigramKey)
|
case .imeModeCHT: return lmCHT.hasKeyValuePairFor(key: unigramKey, value: userPhrase)
|
||||||
for unigram in unigrams {
|
case .imeModeNULL: return false
|
||||||
if unigram.value == userPhrase {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func setPhraseReplacementEnabled(_ state: Bool) {
|
public static func setPhraseReplacementEnabled(_ state: Bool) {
|
||||||
|
|
Loading…
Reference in New Issue