LMCassette // Add areCandidateKeysShiftPressed(), etc.
This commit is contained in:
parent
7d899b4af1
commit
fa0e98ca4a
|
@ -17,6 +17,8 @@ public extension vChewingLM.LMInstantiator {
|
||||||
var maxCassetteKeyLength: Int { Self.lmCassette.maxKeyLength }
|
var maxCassetteKeyLength: Int { Self.lmCassette.maxKeyLength }
|
||||||
/// 磁帶模式專用:指定 `%quick` 快速候選結果當中要過濾掉的無效候選字符號。
|
/// 磁帶模式專用:指定 `%quick` 快速候選結果當中要過濾掉的無效候選字符號。
|
||||||
var nullCandidateInCassette: String { Self.lmCassette.nullCandidate }
|
var nullCandidateInCassette: String { Self.lmCassette.nullCandidate }
|
||||||
|
/// 磁帶模式專用:選字鍵是否需要敲 Shift 才會生效。
|
||||||
|
var areCassetteCandidateKeysShiftPressed: Bool { Self.lmCassette.areCandidateKeysShiftPressed }
|
||||||
/// 磁帶模式專用:選字鍵,在威注音輸入法當中僅優先用於快速模式。
|
/// 磁帶模式專用:選字鍵,在威注音輸入法當中僅優先用於快速模式。
|
||||||
var cassetteSelectionKey: String? {
|
var cassetteSelectionKey: String? {
|
||||||
let result = Self.lmCassette.selectionKeys
|
let result = Self.lmCassette.selectionKeys
|
||||||
|
|
|
@ -36,6 +36,7 @@ public extension vChewingLM {
|
||||||
public private(set) var octagramMap: [String: Int] = [:]
|
public private(set) var octagramMap: [String: Int] = [:]
|
||||||
/// 音韻輸入法專用八股文:[字詞:(頻次, 讀音)]。
|
/// 音韻輸入法專用八股文:[字詞:(頻次, 讀音)]。
|
||||||
public private(set) var octagramDividedMap: [String: (Int, String)] = [:]
|
public private(set) var octagramDividedMap: [String: (Int, String)] = [:]
|
||||||
|
public private(set) var areCandidateKeysShiftPressed: Bool = false
|
||||||
|
|
||||||
/// 計算頻率時要用到的東西
|
/// 計算頻率時要用到的東西
|
||||||
private static let fscale = 2.7
|
private static let fscale = 2.7
|
||||||
|
@ -88,6 +89,7 @@ public extension vChewingLM {
|
||||||
var loadingCharDefinitions = false
|
var loadingCharDefinitions = false
|
||||||
var loadingSymbolDefinitions = false
|
var loadingSymbolDefinitions = false
|
||||||
var loadingOctagramData = false
|
var loadingOctagramData = false
|
||||||
|
var keysUsedInCharDef: Set<String> = .init()
|
||||||
for strLine in lineReader {
|
for strLine in lineReader {
|
||||||
if !loadingKeys, strLine.contains("%keyname"), strLine.contains("begin") { loadingKeys = true }
|
if !loadingKeys, strLine.contains("%keyname"), strLine.contains("begin") { loadingKeys = true }
|
||||||
if loadingKeys, strLine.contains("%keyname"), strLine.contains("end") { loadingKeys = false }
|
if loadingKeys, strLine.contains("%keyname"), strLine.contains("end") { loadingKeys = false }
|
||||||
|
@ -138,6 +140,11 @@ public extension vChewingLM {
|
||||||
{
|
{
|
||||||
theMaxKeyLength = max(theMaxKeyLength, cells[0].count)
|
theMaxKeyLength = max(theMaxKeyLength, cells[0].count)
|
||||||
charDefMap[strFirstCell, default: []].append(strSecondCell)
|
charDefMap[strFirstCell, default: []].append(strSecondCell)
|
||||||
|
if strFirstCell.count > 1 {
|
||||||
|
strFirstCell.map(\.description).forEach { keyChar in
|
||||||
|
keysUsedInCharDef.insert(keyChar.description)
|
||||||
|
}
|
||||||
|
}
|
||||||
reverseLookupMap[strSecondCell, default: []].append(strFirstCell)
|
reverseLookupMap[strSecondCell, default: []].append(strFirstCell)
|
||||||
var keyComps = strFirstCell.map(\.description)
|
var keyComps = strFirstCell.map(\.description)
|
||||||
while !keyComps.isEmpty {
|
while !keyComps.isEmpty {
|
||||||
|
@ -175,7 +182,7 @@ public extension vChewingLM {
|
||||||
if nameShort.isEmpty, strLine.contains("%sname ") { nameShort = strSecondCell }
|
if nameShort.isEmpty, strLine.contains("%sname ") { nameShort = strSecondCell }
|
||||||
if nullCandidate.isEmpty, strLine.contains("%nullcandidate ") { nullCandidate = strSecondCell }
|
if nullCandidate.isEmpty, strLine.contains("%nullcandidate ") { nullCandidate = strSecondCell }
|
||||||
if selectionKeys.isEmpty, strLine.contains("%selkey ") {
|
if selectionKeys.isEmpty, strLine.contains("%selkey ") {
|
||||||
selectionKeys = cells[1].description
|
selectionKeys = cells[1].map(\.description).deduplicated.joined()
|
||||||
}
|
}
|
||||||
if endKeys.isEmpty, strLine.contains("%endkey ") {
|
if endKeys.isEmpty, strLine.contains("%endkey ") {
|
||||||
endKeys = cells[1].map(\.description).deduplicated
|
endKeys = cells[1].map(\.description).deduplicated
|
||||||
|
@ -184,6 +191,11 @@ public extension vChewingLM {
|
||||||
wildcardKey = cells[1].first?.description ?? ""
|
wildcardKey = cells[1].first?.description ?? ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Post process.
|
||||||
|
if CandidateKey.validate(keys: selectionKeys) != nil { selectionKeys = "1234567890" }
|
||||||
|
if !keysUsedInCharDef.intersection(selectionKeys.map(\.description)).isEmpty {
|
||||||
|
areCandidateKeysShiftPressed = true
|
||||||
|
}
|
||||||
maxKeyLength = theMaxKeyLength
|
maxKeyLength = theMaxKeyLength
|
||||||
keyNameMap[wildcardKey] = keyNameMap[wildcardKey] ?? "?"
|
keyNameMap[wildcardKey] = keyNameMap[wildcardKey] ?? "?"
|
||||||
filePath = path
|
filePath = path
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class LMCassetteTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCassetteLoadArray30() throws {
|
func testCassetteLoadArray30() throws {
|
||||||
let pathCINFile = testDataPath + "array30.cin"
|
let pathCINFile = testDataPath + "array30.cin2"
|
||||||
var lmCassette = vChewingLM.LMCassette()
|
var lmCassette = vChewingLM.LMCassette()
|
||||||
NSLog("LMCassette: Start loading CIN.")
|
NSLog("LMCassette: Start loading CIN.")
|
||||||
lmCassette.open(pathCINFile)
|
lmCassette.open(pathCINFile)
|
||||||
|
@ -49,8 +49,8 @@ final class LMCassetteTests: XCTestCase {
|
||||||
XCTAssertFalse(lmCassette.quickDefMap.isEmpty)
|
XCTAssertFalse(lmCassette.quickDefMap.isEmpty)
|
||||||
print(lmCassette.quickSetsFor(key: ",.") ?? "")
|
print(lmCassette.quickSetsFor(key: ",.") ?? "")
|
||||||
XCTAssertEqual(lmCassette.keyNameMap.count, 41)
|
XCTAssertEqual(lmCassette.keyNameMap.count, 41)
|
||||||
XCTAssertEqual(lmCassette.charDefMap.count, 29537)
|
XCTAssertEqual(lmCassette.charDefMap.count, 29491)
|
||||||
XCTAssertEqual(lmCassette.charDefWildcardMap.count, 11973)
|
XCTAssertEqual(lmCassette.charDefWildcardMap.count, 11946)
|
||||||
XCTAssertEqual(lmCassette.octagramMap.count, 0)
|
XCTAssertEqual(lmCassette.octagramMap.count, 0)
|
||||||
XCTAssertEqual(lmCassette.octagramDividedMap.count, 0)
|
XCTAssertEqual(lmCassette.octagramDividedMap.count, 0)
|
||||||
XCTAssertEqual(lmCassette.nameShort, "AR30")
|
XCTAssertEqual(lmCassette.nameShort, "AR30")
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue