Repo // Implement UserPhrase.isAlreadyFiltered().

This commit is contained in:
ShikiSuen 2023-09-06 10:44:53 +08:00
parent 9c81700e98
commit 1cc2929d95
3 changed files with 36 additions and 6 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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 }
/// ///
/// 使 /// 使