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
}
public func queryFilteredValue(key: String) -> [String]? {
let result = lmFiltered.unigramsFor(key: key).map(\.value)
return result.isEmpty ? nil : result
}
///
/// - Parameters:
/// - key:

View File

@ -22,7 +22,15 @@ public class LMMgr {
dataURL: LMMgr.userOverrideModelDataURL(.imeModeCHT))
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:
return Self.lmCHS
case .imeModeCHT:
@ -32,8 +40,8 @@ public class LMMgr {
}
}
public static var currentUOM: vChewingLM.LMUserOverride {
switch IMEApp.currentInputMode {
public static func getUOM(mode: Shared.InputMode) -> vChewingLM.LMUserOverride {
switch mode {
case .imeModeCHS:
return Self.uomCHS
case .imeModeCHT:

View File

@ -24,10 +24,22 @@ public extension LMMgr {
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 {
descriptionCells.joined(separator: " ")
}
public var descriptionCells: [String] {
var result = [String]()
result.append(value)
result.append(keyArray.joined(separator: "-"))
result.append(joinedKey)
if let weight = weight {
result.append(weight.description)
}
@ -37,7 +49,7 @@ public extension LMMgr {
if isConverted {
result.append("#𝙃𝙪𝙢𝙖𝙣𝘾𝙝𝙚𝙘𝙠𝙍𝙚𝙦𝙪𝙞𝙧𝙚𝙙")
}
return result.joined(separator: " ")
return result
}
public var crossConverted: UserPhrase {
@ -49,8 +61,13 @@ public extension LMMgr {
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 {
guard LMMgr.chkUserLMFilesExist(inputMode) else { return false }
guard isValid, LMMgr.chkUserLMFilesExist(inputMode) else { return false }
///
/// 使