LMI // Stop reading factory plist dictionaries when using cassette mode.
This commit is contained in:
parent
234819030c
commit
3df9e692a7
|
@ -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 }
|
||||||
|
let isPeripheralKey: Bool = key.charComponents[0] == "_"
|
||||||
|
if !isCassetteEnabled || isPeripheralKey {
|
||||||
if !lmFiltered.hasUnigramsFor(key: key) {
|
if !lmFiltered.hasUnigramsFor(key: key) {
|
||||||
return lmUserPhrases.hasUnigramsFor(key: key) || lmCore.hasUnigramsFor(key: key)
|
return lmUserPhrases.hasUnigramsFor(key: key) || lmCore.hasUnigramsFor(key: key)
|
||||||
|| Self.lmCassette.hasUnigramsFor(key: key) || (Self.lmCNS.hasUnigramsFor(key: key) && isCNSEnabled)
|
|| Self.lmCassette.hasUnigramsFor(key: key) || (Self.lmCNS.hasUnigramsFor(key: key) && isCNSEnabled)
|
||||||
}
|
}
|
||||||
return !unigramsFor(key: key).isEmpty
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 根據給定的索引鍵和資料值,確認是否有該具體的資料值在庫。
|
/// 根據給定的索引鍵和資料值,確認是否有該具體的資料值在庫。
|
||||||
|
@ -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,18 +279,19 @@ extension vChewingLM {
|
||||||
// 將兩句差分也是為了讓 rawUserUnigrams 的類型不受可能的影響。
|
// 將兩句差分也是為了讓 rawUserUnigrams 的類型不受可能的影響。
|
||||||
rawAllUnigrams += lmUserPhrases.unigramsFor(key: key).reversed()
|
rawAllUnigrams += lmUserPhrases.unigramsFor(key: key).reversed()
|
||||||
|
|
||||||
|
if !isCassetteEnabled || isCassetteEnabled && key.charComponents[0] == "_" {
|
||||||
// LMMisc 與 LMCore 的 score 在 (-10.0, 0.0) 這個區間內。
|
// LMMisc 與 LMCore 的 score 在 (-10.0, 0.0) 這個區間內。
|
||||||
rawAllUnigrams += lmMisc.unigramsFor(key: key)
|
rawAllUnigrams += lmMisc.unigramsFor(key: key)
|
||||||
rawAllUnigrams += lmCore.unigramsFor(key: key)
|
rawAllUnigrams += lmCore.unigramsFor(key: key)
|
||||||
|
if isCNSEnabled { rawAllUnigrams += Self.lmCNS.unigramsFor(key: key) }
|
||||||
if isCNSEnabled {
|
|
||||||
rawAllUnigrams += Self.lmCNS.unigramsFor(key: key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isSymbolEnabled {
|
if isSymbolEnabled {
|
||||||
rawAllUnigrams += lmUserSymbols.unigramsFor(key: key)
|
rawAllUnigrams += lmUserSymbols.unigramsFor(key: key)
|
||||||
|
if !isCassetteEnabled {
|
||||||
rawAllUnigrams += Self.lmSymbols.unigramsFor(key: key)
|
rawAllUnigrams += Self.lmSymbols.unigramsFor(key: key)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 新增與日期、時間、星期有關的單元圖資料
|
// 新增與日期、時間、星期有關的單元圖資料
|
||||||
rawAllUnigrams.append(contentsOf: queryDateTimeUnigrams(with: key))
|
rawAllUnigrams.append(contentsOf: queryDateTimeUnigrams(with: key))
|
||||||
|
|
Loading…
Reference in New Issue