LMAssembly & LMMgr // Add countPhrasePairs(), etc.
This commit is contained in:
parent
6a2a2de195
commit
78a950e355
|
@ -305,6 +305,17 @@ public extension vChewingLM {
|
||||||
: unigramsFor(keyArray: keyArray).map(\.value).contains(value)
|
: unigramsFor(keyArray: keyArray).map(\.value).contains(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 根據給定的索引鍵,確認有多少筆資料值在庫。
|
||||||
|
/// - Parameters:
|
||||||
|
/// - keyArray: 索引鍵陣列。
|
||||||
|
/// - factoryDictionaryOnly: 是否僅統計原廠辭典。
|
||||||
|
/// - Returns: 是否在庫。
|
||||||
|
public func countKeyValuePairs(keyArray: [String], factoryDictionaryOnly: Bool = false) -> Int {
|
||||||
|
factoryDictionaryOnly
|
||||||
|
? lmCore.unigramsFor(key: keyArray.joined(separator: "-")).count
|
||||||
|
: unigramsFor(keyArray: keyArray).count
|
||||||
|
}
|
||||||
|
|
||||||
/// 給定讀音字串,讓 LMI 給出對應的經過處理的單元圖陣列。
|
/// 給定讀音字串,讓 LMI 給出對應的經過處理的單元圖陣列。
|
||||||
/// - Parameter key: 給定的讀音字串。
|
/// - Parameter key: 給定的讀音字串。
|
||||||
/// - Returns: 對應的經過處理的單元圖陣列。
|
/// - Returns: 對應的經過處理的單元圖陣列。
|
||||||
|
|
|
@ -15,7 +15,7 @@ public protocol PhraseEditorDelegate {
|
||||||
func retrieveData(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType) -> String
|
func retrieveData(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType) -> String
|
||||||
@discardableResult func saveData(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, data: String)
|
@discardableResult func saveData(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, data: String)
|
||||||
-> String
|
-> String
|
||||||
func checkIfUserPhraseExist(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool
|
func checkIfPhrasePairExists(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool
|
||||||
func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool)
|
func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool)
|
||||||
func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String)
|
func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String)
|
||||||
func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode)
|
func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode)
|
||||||
|
|
|
@ -140,7 +140,7 @@ public struct VwrPhraseEditorUI: View {
|
||||||
}
|
}
|
||||||
if !txtAddPhraseField4.isEmpty { arrResult.append("#" + txtAddPhraseField4) }
|
if !txtAddPhraseField4.isEmpty { arrResult.append("#" + txtAddPhraseField4) }
|
||||||
if let delegate = delegate,
|
if let delegate = delegate,
|
||||||
delegate.checkIfUserPhraseExist(
|
delegate.checkIfPhrasePairExists(
|
||||||
userPhrase: txtAddPhraseField1, mode: selInputMode, key: txtAddPhraseField2
|
userPhrase: txtAddPhraseField1, mode: selInputMode, key: txtAddPhraseField2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ public struct IMEStateData: IMEStateDataProtocol {
|
||||||
|
|
||||||
public var markedTargetExists: Bool {
|
public var markedTargetExists: Bool {
|
||||||
let pair = userPhraseKVPair
|
let pair = userPhraseKVPair
|
||||||
return LMMgr.checkIfUserPhraseExist(
|
return LMMgr.checkIfPhrasePairExists(
|
||||||
userPhrase: pair.value, mode: IMEApp.currentInputMode, keyArray: pair.keyArray
|
userPhrase: pair.value, mode: IMEApp.currentInputMode, keyArray: pair.keyArray
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ public class LMMgr {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func checkIfUserPhraseExist(
|
public static func checkIfPhrasePairExists(
|
||||||
userPhrase: String,
|
userPhrase: String,
|
||||||
mode: Shared.InputMode,
|
mode: Shared.InputMode,
|
||||||
keyArray: [String],
|
keyArray: [String],
|
||||||
|
@ -293,6 +293,24 @@ public class LMMgr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func countPhrasePairs(
|
||||||
|
keyArray: [String],
|
||||||
|
mode: Shared.InputMode,
|
||||||
|
factoryDictionaryOnly: Bool = false
|
||||||
|
) -> Int {
|
||||||
|
switch mode {
|
||||||
|
case .imeModeCHS:
|
||||||
|
return lmCHS.countKeyValuePairs(
|
||||||
|
keyArray: keyArray, factoryDictionaryOnly: factoryDictionaryOnly
|
||||||
|
)
|
||||||
|
case .imeModeCHT:
|
||||||
|
return lmCHT.countKeyValuePairs(
|
||||||
|
keyArray: keyArray, factoryDictionaryOnly: factoryDictionaryOnly
|
||||||
|
)
|
||||||
|
case .imeModeNULL: return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static func setPhraseReplacementEnabled(_ state: Bool) {
|
public static func setPhraseReplacementEnabled(_ state: Bool) {
|
||||||
Self.lmCHT.isPhraseReplacementEnabled = state
|
Self.lmCHT.isPhraseReplacementEnabled = state
|
||||||
Self.lmCHS.isPhraseReplacementEnabled = state
|
Self.lmCHS.isPhraseReplacementEnabled = state
|
||||||
|
|
|
@ -25,8 +25,8 @@ extension LMMgr: PhraseEditorDelegate {
|
||||||
vChewingLM.LMConsolidator.consolidate(text: &strProcessed, pragma: shouldCheckPragma)
|
vChewingLM.LMConsolidator.consolidate(text: &strProcessed, pragma: shouldCheckPragma)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func checkIfUserPhraseExist(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool {
|
public func checkIfPhrasePairExists(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool {
|
||||||
Self.checkIfUserPhraseExist(userPhrase: userPhrase, mode: mode, keyArray: [unigramKey])
|
Self.checkIfPhrasePairExists(userPhrase: userPhrase, mode: mode, keyArray: [unigramKey])
|
||||||
}
|
}
|
||||||
|
|
||||||
public func retrieveData(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType) -> String {
|
public func retrieveData(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType) -> String {
|
||||||
|
@ -95,7 +95,7 @@ extension LMMgr: PhraseEditorDelegate {
|
||||||
for currentLine in strProcessed.split(separator: "\n") {
|
for currentLine in strProcessed.split(separator: "\n") {
|
||||||
let arr = currentLine.split(separator: " ")
|
let arr = currentLine.split(separator: " ")
|
||||||
guard arr.count >= 2 else { continue }
|
guard arr.count >= 2 else { continue }
|
||||||
let exists = Self.checkIfUserPhraseExist(
|
let exists = Self.checkIfPhrasePairExists(
|
||||||
userPhrase: arr[0].description, mode: mode,
|
userPhrase: arr[0].description, mode: mode,
|
||||||
keyArray: arr[1].split(separator: "-").map(\.description),
|
keyArray: arr[1].split(separator: "-").map(\.description),
|
||||||
factoryDictionaryOnly: true
|
factoryDictionaryOnly: true
|
||||||
|
|
|
@ -21,7 +21,7 @@ public extension LMMgr {
|
||||||
public var weight: Double?
|
public var weight: Double?
|
||||||
|
|
||||||
private var isDuplicated: Bool {
|
private var isDuplicated: Bool {
|
||||||
LMMgr.checkIfUserPhraseExist(userPhrase: value, mode: inputMode, keyArray: keyArray)
|
LMMgr.checkIfPhrasePairExists(userPhrase: value, mode: inputMode, keyArray: keyArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
|
|
|
@ -214,7 +214,7 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate {
|
||||||
arrResult.append(weightVal.description)
|
arrResult.append(weightVal.description)
|
||||||
}
|
}
|
||||||
if !txtPECommentField.stringValue.isEmpty { arrResult.append("#" + txtPECommentField.stringValue) }
|
if !txtPECommentField.stringValue.isEmpty { arrResult.append("#" + txtPECommentField.stringValue) }
|
||||||
if LMMgr.shared.checkIfUserPhraseExist(
|
if LMMgr.shared.checkIfPhrasePairExists(
|
||||||
userPhrase: txtPEField1.stringValue, mode: selInputMode, key: txtPEField2.stringValue
|
userPhrase: txtPEField1.stringValue, mode: selInputMode, key: txtPEField2.stringValue
|
||||||
) {
|
) {
|
||||||
arrResult.append(" #𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎")
|
arrResult.append(" #𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎")
|
||||||
|
|
Loading…
Reference in New Issue