Tekkon // Nomenclature updates for future purposes.

This commit is contained in:
ShikiSuen 2022-12-07 11:58:10 +08:00
parent 2664509276
commit ea725ed329
9 changed files with 35 additions and 34 deletions

View File

@ -32,7 +32,7 @@ extension vChewingLM {
let arrTarget = target.dropLast().dropFirst().split(separator: ",") let arrTarget = target.dropLast().dropFirst().split(separator: ",")
guard arrTarget.count == 2 else { return target } guard arrTarget.count == 2 else { return target }
var arrTarget0 = String(arrTarget[0]).lowercased() var arrTarget0 = String(arrTarget[0]).lowercased()
arrTarget0.converToPhonabets() arrTarget0.convertToPhonabets()
return "(\(arrTarget0),\(arrTarget[1]))" return "(\(arrTarget0),\(arrTarget[1]))"
} }

View File

@ -103,7 +103,7 @@ extension vChewingLM {
if !neta[0].isEmpty, !neta[1].isEmpty { if !neta[0].isEmpty, !neta[1].isEmpty {
var theKey = shouldReverse ? String(neta[1]) : String(neta[0]) var theKey = shouldReverse ? String(neta[1]) : String(neta[0])
let theValue = $0 let theValue = $0
theKey.converToPhonabets() theKey.convertToPhonabets()
rangeMap[theKey, default: []].append(theValue) rangeMap[theKey, default: []].append(theValue)
} }
} }

View File

@ -9,7 +9,7 @@
import Cocoa import Cocoa
extension String { extension String {
public mutating func converToPhonabets(newToneOne: String = "") { public mutating func convertToPhonabets(newToneOne: String = "") {
if isEmpty || contains("_") || !isNotPureAlphanumerical { return } if isEmpty || contains("_") || !isNotPureAlphanumerical { return }
for key in arrHanyuPinyinToPhonabets { for key in arrHanyuPinyinToPhonabets {
self = replacingOccurrences(of: key.0, with: key.1) self = replacingOccurrences(of: key.0, with: key.1)

View File

@ -55,10 +55,10 @@ extension Tekkon {
switch isHanyuPinyin { switch isHanyuPinyin {
case false: // case false: //
let valReturnZhuyin = value.replacingOccurrences(of: " ", with: "") let valReturnZhuyin = value.replacingOccurrences(of: " ", with: "")
return isTextBookStyle ? cnvZhuyinChainToTextbookReading(target: valReturnZhuyin) : valReturnZhuyin return isTextBookStyle ? cnvZhuyinChainToTextbookReading(targetJoined: valReturnZhuyin) : valReturnZhuyin
case true: // case true: //
let valReturnPinyin = Tekkon.cnvPhonaToHanyuPinyin(target: value) let valReturnPinyin = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: value)
return isTextBookStyle ? Tekkon.cnvHanyuPinyinToTextbookStyle(target: valReturnPinyin) : valReturnPinyin return isTextBookStyle ? Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: valReturnPinyin) : valReturnPinyin
} }
} }
@ -160,7 +160,7 @@ extension Tekkon {
/// ///
mutating func updateRomajiBuffer() { mutating func updateRomajiBuffer() {
romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(target: consonant.value + semivowel.value + vowel.value) romajiBuffer = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: consonant.value + semivowel.value + vowel.value)
} }
/// String /// String

View File

@ -14,8 +14,8 @@ extension Tekkon {
/// ///
/// - Parameters: /// - Parameters:
/// - target: String /// - target: String
public static func cnvPhonaToHanyuPinyin(target: String) -> String { public static func cnvPhonaToHanyuPinyin(targetJoined: String) -> String {
var targetConverted = target var targetConverted = targetJoined
for pair in arrPhonaToHanyuPinyin { for pair in arrPhonaToHanyuPinyin {
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1]) targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
} }
@ -25,8 +25,8 @@ extension Tekkon {
/// 調 1 /// 調 1
/// - Parameters: /// - Parameters:
/// - target: String /// - target: String
public static func cnvHanyuPinyinToTextbookStyle(target: String) -> String { public static func cnvHanyuPinyinToTextbookStyle(targetJoined: String) -> String {
var targetConverted = target var targetConverted = targetJoined
for pair in arrHanyuPinyinTextbookStyleConversionTable { for pair in arrHanyuPinyinTextbookStyleConversionTable {
targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1]) targetConverted = targetConverted.replacingOccurrences(of: pair[0], with: pair[1])
} }
@ -38,9 +38,9 @@ extension Tekkon {
/// - target: /// - target:
/// - newSeparator: /// - newSeparator:
/// - Returns: /// - Returns:
public static func cnvZhuyinChainToTextbookReading(target: String, newSeparator: String = "-") -> String { public static func cnvZhuyinChainToTextbookReading(targetJoined: String, newSeparator: String = "-") -> String {
var arrReturn: [String] = [] var arrReturn: [String] = []
for neta in target.split(separator: "-") { for neta in targetJoined.split(separator: "-") {
var newString = String(neta) var newString = String(neta)
if String(neta.reversed()[0]) == "˙" { if String(neta.reversed()[0]) == "˙" {
newString = String(neta.dropLast()) newString = String(neta.dropLast())
@ -56,9 +56,9 @@ extension Tekkon {
/// - target: /// - target:
/// - newSeparator: /// - newSeparator:
/// - Returns: /// - Returns:
public static func restoreToneOneInZhuyinKey(target: String, newSeparator: String = "-") -> String { public static func restoreToneOneInZhuyinKey(targetJoined: String, newSeparator: String = "-") -> String {
var arrReturn: [String] = [] var arrReturn: [String] = []
for neta in target.split(separator: "-") { for neta in targetJoined.split(separator: "-") {
var newNeta = String(neta) var newNeta = String(neta)
if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") { if !"ˊˇˋ˙".contains(String(neta.reversed()[0])), !neta.contains("_") {
newNeta += "1" newNeta += "1"
@ -73,10 +73,10 @@ extension Tekkon {
/// - target: 12345 調 /// - target: 12345 調
/// - newToneOne: /// - newToneOne:
/// - Returns: /// - Returns:
public static func cnvHanyuPinyinToPhona(target: String, newToneOne: String = "") -> String { public static func cnvHanyuPinyinToPhona(targetJoined: String, newToneOne: String = "") -> String {
/// ///
if target.contains("_") || !target.isNotPureAlphanumerical { return target } if targetJoined.contains("_") || !targetJoined.isNotPureAlphanumerical { return targetJoined }
var result = target var result = targetJoined
for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) { for key in Tekkon.mapHanyuPinyin.keys.sorted(by: { $0.count > $1.count }) {
guard let value = Tekkon.mapHanyuPinyin[key] else { continue } guard let value = Tekkon.mapHanyuPinyin[key] else { continue }
result = result.replacingOccurrences(of: key, with: value) result = result.replacingOccurrences(of: key, with: value)

View File

@ -167,11 +167,11 @@ final class TekkonTestsBasic: XCTestCase {
XCTAssertEqual(composer.getComposition(), "ㄩㄝ") XCTAssertEqual(composer.getComposition(), "ㄩㄝ")
// Testing tool functions // Testing tool functions
XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(target: "ㄉㄧㄠ"), "ㄉㄧㄠ1") XCTAssertEqual(Tekkon.restoreToneOneInZhuyinKey(targetJoined: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(target: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ") XCTAssertEqual(Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: "ㄊㄧㄥ-ㄓㄜ˙"), "ㄊㄧㄥ-˙ㄓㄜ")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ") XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
// //
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(target: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ") XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ")
} }
} }

View File

@ -192,11 +192,11 @@ extension IMEStateData {
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
{ {
// ->->調 // ->->調
neta = Tekkon.restoreToneOneInZhuyinKey(target: neta) neta = Tekkon.restoreToneOneInZhuyinKey(targetJoined: neta)
neta = Tekkon.cnvPhonaToHanyuPinyin(target: neta) neta = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: neta)
neta = Tekkon.cnvHanyuPinyinToTextbookStyle(target: neta) neta = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: neta)
} else { } else {
neta = Tekkon.cnvZhuyinChainToTextbookReading(target: neta) neta = Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: neta)
} }
} }
arrOutput.append(neta) arrOutput.append(neta)

View File

@ -308,9 +308,9 @@ extension InputHandler {
if !prefs.cassetteEnabled { if !prefs.cassetteEnabled {
if prefs.inlineDumpPinyinInLieuOfZhuyin { if prefs.inlineDumpPinyinInLieuOfZhuyin {
if !compositor.isEmpty { if !compositor.isEmpty {
displayedText = Tekkon.restoreToneOneInZhuyinKey(target: displayedText) // displayedText = Tekkon.restoreToneOneInZhuyinKey(targetJoined: displayedText) //
} }
displayedText = Tekkon.cnvPhonaToHanyuPinyin(target: displayedText) // displayedText = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: displayedText) //
} }
if prefs.showHanyuPinyinInCompositionBuffer { if prefs.showHanyuPinyinInCompositionBuffer {
if compositor.isEmpty { if compositor.isEmpty {
@ -340,12 +340,12 @@ extension InputHandler {
var key = node.keyArray.joined(separator: "\t") var key = node.keyArray.joined(separator: "\t")
if !prefs.cassetteEnabled { if !prefs.cassetteEnabled {
if prefs.inlineDumpPinyinInLieuOfZhuyin { if prefs.inlineDumpPinyinInLieuOfZhuyin {
key = Tekkon.restoreToneOneInZhuyinKey(target: key) // key = Tekkon.restoreToneOneInZhuyinKey(targetJoined: key) //
key = Tekkon.cnvPhonaToHanyuPinyin(target: key) // key = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: key) //
key = Tekkon.cnvHanyuPinyinToTextbookStyle(target: key) // 調 key = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: key) // 調
key = key.replacingOccurrences(of: "\t", with: " ") key = key.replacingOccurrences(of: "\t", with: " ")
} else { } else {
key = Tekkon.cnvZhuyinChainToTextbookReading(target: key, newSeparator: " ") key = Tekkon.cnvZhuyinChainToTextbookReading(targetJoined: key, newSeparator: " ")
} }
} }

View File

@ -32,7 +32,8 @@ extension SessionCtl {
? theCandidate.0.joined(separator: separator) ? theCandidate.0.joined(separator: separator)
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer : (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
? Tekkon.cnvPhonaToHanyuPinyin( ? Tekkon.cnvPhonaToHanyuPinyin(
target: Tekkon.restoreToneOneInZhuyinKey(target: theCandidate.0.joined(separator: separator))) targetJoined: Tekkon.restoreToneOneInZhuyinKey(
targetJoined: theCandidate.0.joined(separator: separator)))
: theCandidate.0.joined(separator: separator)) : theCandidate.0.joined(separator: separator))
result = "\(result)\u{17}(\(reading))" result = "\(result)\u{17}(\(reading))"
} }
@ -94,7 +95,7 @@ extension SessionCtl {
? neta.0.joined(separator: separator) ? neta.0.joined(separator: separator)
: (PrefMgr.shared.showHanyuPinyinInCompositionBuffer : (PrefMgr.shared.showHanyuPinyinInCompositionBuffer
? Tekkon.cnvPhonaToHanyuPinyin( ? Tekkon.cnvPhonaToHanyuPinyin(
target: Tekkon.restoreToneOneInZhuyinKey(target: neta.0.joined(separator: separator))) targetJoined: Tekkon.restoreToneOneInZhuyinKey(targetJoined: neta.0.joined(separator: separator)))
: neta.0.joined(separator: separator)) : neta.0.joined(separator: separator))
let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))" let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))"
if candidateString == prefix + netaShownWithPronunciation { if candidateString == prefix + netaShownWithPronunciation {