LMInstantiator // Add cassetteSymbolDataFor().

This commit is contained in:
ShikiSuen 2023-06-19 22:06:34 +08:00
parent 7a76cc89d2
commit cfdd6fdc1b
1 changed files with 17 additions and 8 deletions

View File

@ -11,13 +11,13 @@ import Megrez
import Shared import Shared
public extension vChewingLM.LMInstantiator { public extension vChewingLM.LMInstantiator {
/// ///
var cassetteWildcardKey: String { Self.lmCassette.wildcardKey } var cassetteWildcardKey: String { Self.lmCassette.wildcardKey }
/// ///
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 }
/// ///
var cassetteSelectionKey: String? { var cassetteSelectionKey: String? {
let result = Self.lmCassette.selectionKeys let result = Self.lmCassette.selectionKeys
return result.isEmpty ? nil : result return result.isEmpty ? nil : result
@ -30,28 +30,37 @@ public extension vChewingLM.LMInstantiator {
Self.lmCassette.quickSetsFor(key: key) Self.lmCassette.quickSetsFor(key: key)
} }
/// /// 調 `%symboldata`
/// - Parameter key:
/// - Returns:
func cassetteSymbolDataFor(key: String) -> [String]? {
guard let fetched = Self.lmCassette.symbolDefMap[key] else { return nil }
guard !fetched.joined().isEmpty else { return nil }
return fetched
}
///
/// - Parameter char: /// - Parameter char:
/// - Returns: /// - Returns:
func convertCassetteKeyToDisplay(char: String) -> String { func convertCassetteKeyToDisplay(char: String) -> String {
Self.lmCassette.convertKeyToDisplay(char: char) Self.lmCassette.convertKeyToDisplay(char: char)
} }
/// ///
/// - Parameter key: /// - Parameter key:
/// - Returns: /// - Returns:
func isThisCassetteKeyAllowed(key: String) -> Bool { func isThisCassetteKeyAllowed(key: String) -> Bool {
Self.lmCassette.allowedKeys.contains(key) Self.lmCassette.allowedKeys.contains(key)
} }
/// ///
/// - Parameter key: /// - Parameter key:
/// - Returns: /// - Returns:
func hasCassetteWildcardResultsFor(key: String) -> Bool { func hasCassetteWildcardResultsFor(key: String) -> Bool {
Self.lmCassette.hasUnigramsFor(key: key + Self.lmCassette.wildcard) Self.lmCassette.hasUnigramsFor(key: key + Self.lmCassette.wildcard)
} }
/// ///
/// - Parameter value: /// - Parameter value:
/// - Returns: /// - Returns:
func cassetteReverseLookup(for value: String) -> [String] { func cassetteReverseLookup(for value: String) -> [String] {