From 0f2ad53481dfa837ee0a0e368068352219e6f4c5 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 7 Sep 2023 01:37:19 +0800 Subject: [PATCH] LMInstantiator & UserPhrase // New method to check isFiltered(). --- .../Sources/LangModelAssembly/LMInstantiator.swift | 5 ++--- .../Sources/MainAssembly/LMMgr_UserPhraseStructure.swift | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator.swift b/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator.swift index 598ced86..3eb773fe 100644 --- a/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator.swift +++ b/Packages/vChewing_LangModelAssembly/Sources/LangModelAssembly/LMInstantiator.swift @@ -238,9 +238,8 @@ 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 + public func isPairFiltered(pair: Megrez.KeyValuePaired) -> Bool { + lmFiltered.unigramsFor(key: pair.joinedKey()).map(\.value).contains(pair.value) } /// 插入臨時資料。 diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/LMMgr_UserPhraseStructure.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/LMMgr_UserPhraseStructure.swift index 6b2937f7..b53ff9f1 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/LMMgr_UserPhraseStructure.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/LMMgr_UserPhraseStructure.swift @@ -62,8 +62,7 @@ public extension LMMgr { } public var isAlreadyFiltered: Bool { - let results = LMMgr.getLM(mode: inputMode).queryFilteredValue(key: joinedKey) ?? [] - return results.contains(value) + LMMgr.getLM(mode: inputMode).isPairFiltered(pair: .init(keyArray: keyArray, value: value)) } public func write(toFilter: Bool) -> Bool {