LMCassette // Supply generated %quick results when needed.
* Partial results are only supplied if the line `%flag_disp_partial_match` presents in the cassette.
This commit is contained in:
parent
e19aa9e83a
commit
480b362bf4
|
@ -38,6 +38,7 @@ public extension vChewingLM {
|
||||||
public private(set) var octagramDividedMap: [String: (Int, String)] = [:]
|
public private(set) var octagramDividedMap: [String: (Int, String)] = [:]
|
||||||
public private(set) var areCandidateKeysShiftHeld: Bool = false
|
public private(set) var areCandidateKeysShiftHeld: Bool = false
|
||||||
public private(set) var supplyQuickResults: Bool = false
|
public private(set) var supplyQuickResults: Bool = false
|
||||||
|
public private(set) var supplyPartiallyMatchedResults: Bool = false
|
||||||
|
|
||||||
/// 計算頻率時要用到的東西
|
/// 計算頻率時要用到的東西
|
||||||
private static let fscale = 2.7
|
private static let fscale = 2.7
|
||||||
|
@ -96,9 +97,14 @@ public extension vChewingLM {
|
||||||
if !loadingKeys, strLine.contains("begin") { loadingKeys = true }
|
if !loadingKeys, strLine.contains("begin") { loadingKeys = true }
|
||||||
if loadingKeys, strLine.contains("end") { loadingKeys = false }
|
if loadingKeys, strLine.contains("end") { loadingKeys = false }
|
||||||
}
|
}
|
||||||
|
// %flag_disp_partial_match
|
||||||
|
if strLine == "%flag_disp_partial_match" {
|
||||||
|
supplyPartiallyMatchedResults = true
|
||||||
|
supplyQuickResults = true
|
||||||
|
}
|
||||||
// %quick
|
// %quick
|
||||||
if strLine.starts(with: "%quick") {
|
if strLine.starts(with: "%quick") {
|
||||||
if strLine == "%quick", !supplyQuickResults { supplyQuickResults = true }
|
supplyQuickResults = true
|
||||||
if !loadingQuickSets, strLine.contains("begin") {
|
if !loadingQuickSets, strLine.contains("begin") {
|
||||||
loadingQuickSets = true
|
loadingQuickSets = true
|
||||||
}
|
}
|
||||||
|
@ -202,9 +208,6 @@ public extension vChewingLM {
|
||||||
if wildcardKey.isEmpty, strLine.starts(with: "%wildcardkey ") {
|
if wildcardKey.isEmpty, strLine.starts(with: "%wildcardkey ") {
|
||||||
wildcardKey = cells[1].first?.description ?? ""
|
wildcardKey = cells[1].first?.description ?? ""
|
||||||
}
|
}
|
||||||
if strLine == "%flag_disp_partial_match", !supplyQuickResults {
|
|
||||||
supplyQuickResults = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Post process.
|
// Post process.
|
||||||
if CandidateKey.validate(keys: selectionKeys) != nil { selectionKeys = "1234567890" }
|
if CandidateKey.validate(keys: selectionKeys) != nil { selectionKeys = "1234567890" }
|
||||||
|
@ -252,15 +255,20 @@ public extension vChewingLM {
|
||||||
if let specifiedResult = quickDefMap[key], !specifiedResult.isEmpty {
|
if let specifiedResult = quickDefMap[key], !specifiedResult.isEmpty {
|
||||||
result.append(contentsOf: specifiedResult.map(\.description))
|
result.append(contentsOf: specifiedResult.map(\.description))
|
||||||
}
|
}
|
||||||
if supplyQuickResults, quickDefMap.isEmpty {
|
if supplyQuickResults, result.isEmpty {
|
||||||
let fetched = charDefMap.compactMap {
|
if supplyPartiallyMatchedResults {
|
||||||
$0.key.starts(with: key) ? $0 : nil
|
let fetched = charDefMap.compactMap {
|
||||||
}.stableSort {
|
$0.key.starts(with: key) ? $0 : nil
|
||||||
$0.key.count < $1.key.count
|
}.stableSort {
|
||||||
}.flatMap(\.value).filter {
|
$0.key.count < $1.key.count
|
||||||
$0.count == 1
|
}.flatMap(\.value).filter {
|
||||||
|
$0.count == 1
|
||||||
|
}
|
||||||
|
result.append(contentsOf: fetched.deduplicated.prefix(selectionKeys.count * 6))
|
||||||
|
} else {
|
||||||
|
let fetched = (charDefMap[key] ?? [String]()).filter { $0.count == 1 }
|
||||||
|
result.append(contentsOf: fetched.deduplicated.prefix(selectionKeys.count * 6))
|
||||||
}
|
}
|
||||||
result.append(contentsOf: fetched.deduplicated.prefix(selectionKeys.count * 6))
|
|
||||||
}
|
}
|
||||||
return result.isEmpty ? nil : result.joined(separator: "\t")
|
return result.isEmpty ? nil : result.joined(separator: "\t")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue