Repo // Implement UserPhrase.isAlreadyFiltered().
This commit is contained in:
parent
9c81700e98
commit
1cc2929d95
|
@ -238,6 +238,11 @@ public extension vChewingLM {
|
||||||
return result.isEmpty ? nil : result
|
return result.isEmpty ? nil : result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func queryFilteredValue(key: String) -> [String]? {
|
||||||
|
let result = lmFiltered.unigramsFor(key: key).map(\.value)
|
||||||
|
return result.isEmpty ? nil : result
|
||||||
|
}
|
||||||
|
|
||||||
/// 插入臨時資料。
|
/// 插入臨時資料。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - key: 索引鍵陣列。
|
/// - key: 索引鍵陣列。
|
||||||
|
|
|
@ -22,7 +22,15 @@ public class LMMgr {
|
||||||
dataURL: LMMgr.userOverrideModelDataURL(.imeModeCHT))
|
dataURL: LMMgr.userOverrideModelDataURL(.imeModeCHT))
|
||||||
|
|
||||||
public static var currentLM: vChewingLM.LMInstantiator {
|
public static var currentLM: vChewingLM.LMInstantiator {
|
||||||
switch IMEApp.currentInputMode {
|
Self.getLM(mode: IMEApp.currentInputMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var currentUOM: vChewingLM.LMUserOverride {
|
||||||
|
Self.getUOM(mode: IMEApp.currentInputMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func getLM(mode: Shared.InputMode) -> vChewingLM.LMInstantiator {
|
||||||
|
switch mode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
return Self.lmCHS
|
return Self.lmCHS
|
||||||
case .imeModeCHT:
|
case .imeModeCHT:
|
||||||
|
@ -32,8 +40,8 @@ public class LMMgr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var currentUOM: vChewingLM.LMUserOverride {
|
public static func getUOM(mode: Shared.InputMode) -> vChewingLM.LMUserOverride {
|
||||||
switch IMEApp.currentInputMode {
|
switch mode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
return Self.uomCHS
|
return Self.uomCHS
|
||||||
case .imeModeCHT:
|
case .imeModeCHT:
|
||||||
|
|
|
@ -24,10 +24,22 @@ public extension LMMgr {
|
||||||
LMMgr.checkIfPhrasePairExists(userPhrase: value, mode: inputMode, keyArray: keyArray)
|
LMMgr.checkIfPhrasePairExists(userPhrase: value, mode: inputMode, keyArray: keyArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var joinedKey: String {
|
||||||
|
keyArray.joined(separator: "-")
|
||||||
|
}
|
||||||
|
|
||||||
|
public var isValid: Bool {
|
||||||
|
!keyArray.isEmpty && keyArray.filter(\.isEmpty).isEmpty && !value.isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
|
descriptionCells.joined(separator: " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
public var descriptionCells: [String] {
|
||||||
var result = [String]()
|
var result = [String]()
|
||||||
result.append(value)
|
result.append(value)
|
||||||
result.append(keyArray.joined(separator: "-"))
|
result.append(joinedKey)
|
||||||
if let weight = weight {
|
if let weight = weight {
|
||||||
result.append(weight.description)
|
result.append(weight.description)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +49,7 @@ public extension LMMgr {
|
||||||
if isConverted {
|
if isConverted {
|
||||||
result.append("#𝙃𝙪𝙢𝙖𝙣𝘾𝙝𝙚𝙘𝙠𝙍𝙚𝙦𝙪𝙞𝙧𝙚𝙙")
|
result.append("#𝙃𝙪𝙢𝙖𝙣𝘾𝙝𝙚𝙘𝙠𝙍𝙚𝙦𝙪𝙞𝙧𝙚𝙙")
|
||||||
}
|
}
|
||||||
return result.joined(separator: " ")
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public var crossConverted: UserPhrase {
|
public var crossConverted: UserPhrase {
|
||||||
|
@ -49,8 +61,13 @@ public extension LMMgr {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var isAlreadyFiltered: Bool {
|
||||||
|
let results = LMMgr.getLM(mode: inputMode).queryFilteredValue(key: joinedKey) ?? []
|
||||||
|
return results.contains(value)
|
||||||
|
}
|
||||||
|
|
||||||
public func write(toFilter: Bool) -> Bool {
|
public func write(toFilter: Bool) -> Bool {
|
||||||
guard LMMgr.chkUserLMFilesExist(inputMode) else { return false }
|
guard isValid, LMMgr.chkUserLMFilesExist(inputMode) else { return false }
|
||||||
|
|
||||||
/// 施工筆記:
|
/// 施工筆記:
|
||||||
/// 有些使用者的語彙檔案已經過於龐大了(超過一千行),
|
/// 有些使用者的語彙檔案已經過於龐大了(超過一千行),
|
||||||
|
|
Loading…
Reference in New Issue