mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
Merge pull request #206 from azooKey/feat/enable_upcoming_features
feat(breaking): enable upcoming features for future compatibility
This commit is contained in:
@ -6,6 +6,8 @@ import Foundation
|
||||
|
||||
let swiftSettings: [SwiftSetting] = [
|
||||
.enableUpcomingFeature("ExistentialAny"),
|
||||
.enableUpcomingFeature("MemberImportVisibility"),
|
||||
.enableUpcomingFeature("InternalImportsByDefault"),
|
||||
.interoperabilityMode(.Cxx, .when(traits: ["Zenzai"]))
|
||||
]
|
||||
|
||||
|
@ -2,8 +2,8 @@ import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
|
||||
@main
|
||||
public struct Anco: AsyncParsableCommand {
|
||||
public static let configuration = CommandConfiguration(
|
||||
struct Anco: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
abstract: "Anco is A(zooKey) Kana-Ka(n)ji (co)nverter",
|
||||
subcommands: [
|
||||
Subcommands.Run.self,
|
||||
@ -17,5 +17,5 @@ public struct Anco: AsyncParsableCommand {
|
||||
defaultSubcommand: Subcommands.Run.self
|
||||
)
|
||||
|
||||
public init() {}
|
||||
init() {}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension Subcommands {
|
||||
struct Evaluate: AsyncParsableCommand {
|
||||
@ -73,9 +74,9 @@ extension Subcommands {
|
||||
if stable {
|
||||
result.execution_time = 0
|
||||
result.timestamp = 0
|
||||
result.items.mutatingForeach {
|
||||
result.items.mutatingForEach {
|
||||
$0.entropy = Double(Int($0.entropy * 10)) / 10
|
||||
$0.outputs.mutatingForeach {
|
||||
$0.outputs.mutatingForEach {
|
||||
$0.score = Double(Int($0.score))
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import Algorithms
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
@ -1,6 +1,7 @@
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension Subcommands {
|
||||
struct Run: AsyncParsableCommand {
|
||||
|
@ -1,6 +1,9 @@
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import Algorithms
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import SwiftUtils
|
||||
import Tokenizers
|
||||
|
||||
extension Subcommands {
|
||||
struct Session: AsyncParsableCommand {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension Subcommands {
|
||||
struct ZenzEvaluate: AsyncParsableCommand {
|
||||
@ -68,8 +69,8 @@ extension Subcommands {
|
||||
if stable {
|
||||
result.execution_time = 0
|
||||
result.timestamp = 0
|
||||
result.items.mutatingForeach {
|
||||
$0.outputs.mutatingForeach {
|
||||
result.items.mutatingForEach {
|
||||
$0.outputs.mutatingForEach {
|
||||
$0.score = Double(Int($0.score))
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
// Copyright © 2022 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
/// ユーザ入力、変換対象文字列、ディスプレイされる文字列、の3つを同時にハンドルするための構造体
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension KanaKanjiConverter {
|
||||
/// 西暦に変換した結果を返す関数。
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension KanaKanjiConverter {
|
||||
func commaSeparatedNumberCandidates(_ inputData: ComposingText) -> [Candidate] {
|
||||
@ -18,7 +19,7 @@ extension KanaKanjiConverter {
|
||||
let integerPart = parts[0]
|
||||
guard integerPart.count > 3 else { return [] }
|
||||
|
||||
var reversed = Array(integerPart.reversed())
|
||||
let reversed = Array(integerPart.reversed())
|
||||
var formatted = ""
|
||||
for (i, ch) in reversed.enumerated() {
|
||||
if i > 0 && i % 3 == 0 {
|
||||
|
@ -6,7 +6,7 @@
|
||||
// Copyright © 2022 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
public import Foundation
|
||||
|
||||
public struct ConvertRequestOptions: Sendable {
|
||||
/// 変換リクエストに必要な設定データ
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension KanaKanjiConverter {
|
||||
private static let domains = [
|
||||
|
@ -6,7 +6,8 @@
|
||||
// Copyright © 2020 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Algorithms
|
||||
package import Foundation
|
||||
import SwiftUtils
|
||||
import EfficientNGram
|
||||
|
||||
@ -18,7 +19,7 @@ import EfficientNGram
|
||||
}
|
||||
|
||||
private var converter = Kana2Kanji()
|
||||
nonisolated(unsafe) public static let defaultSpecialCandidateProviders: [any SpecialCandidateProvider] = [
|
||||
nonisolated public static let defaultSpecialCandidateProviders: [any SpecialCandidateProvider] = [
|
||||
CalendarSpecialCandidateProvider(),
|
||||
EmailAddressSpecialCandidateProvider(),
|
||||
UnicodeSpecialCandidateProvider(),
|
||||
@ -581,7 +582,7 @@ import EfficientNGram
|
||||
result.append(contentsOf: clause_candidates)
|
||||
result.append(contentsOf: word_candidates)
|
||||
|
||||
result.mutatingForeach { item in
|
||||
result.mutatingForEach { item in
|
||||
item.withActions(self.getAppropriateActions(item))
|
||||
item.parseTemplate()
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
private extension UnicodeScalar {
|
||||
/// ローマ字の大文字かどうか
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension KanaKanjiConverter {
|
||||
/// unicode文字列`"uxxxx, Uxxxx, u+xxxx, U+xxxx"`を対応する記号に変換する関数
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension KanaKanjiConverter {
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
// Copyright © 2020 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Algorithms
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
@ -124,7 +125,7 @@ public final class DicdataStore {
|
||||
self.closeKeyboard()
|
||||
case .importOSUserDict(let dicdata), .importDynamicUserDict(let dicdata):
|
||||
self.dynamicUserDict = dicdata
|
||||
self.dynamicUserDict.mutatingForeach {
|
||||
self.dynamicUserDict.mutatingForEach {
|
||||
$0.metadata = .isFromUserDictionary
|
||||
}
|
||||
case let .forgetMemory(candidate):
|
||||
@ -257,12 +258,12 @@ public final class DicdataStore {
|
||||
data.append(contentsOf: LOUDS.getDataForLoudstxt3(identifier + "\(key)", indices: value.map {$0 & 2047}, cache: self.loudstxts[identifier + "\(key)"], option: self.requestOptions))
|
||||
}
|
||||
if identifier == "memory" {
|
||||
data.mutatingForeach {
|
||||
data.mutatingForEach {
|
||||
$0.metadata = .isLearned
|
||||
}
|
||||
}
|
||||
if identifier == "user" {
|
||||
data.mutatingForeach {
|
||||
data.mutatingForEach {
|
||||
$0.metadata = .isFromUserDictionary
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import Algorithms
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
import EfficientNGram
|
||||
|
@ -6,7 +6,7 @@
|
||||
// Copyright © 2020 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
package import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
extension LOUDS {
|
||||
|
@ -6,7 +6,7 @@
|
||||
// Copyright © 2023 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
public import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
/// `TextReplacer`は前後の文脈に基づいて、現在のカーソル位置の語の置き換えを提案するためのモジュールである。
|
||||
|
@ -7,6 +7,8 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
enum Roman2Kana {
|
||||
static let katakanaChanges: [String: String] = Dictionary(uniqueKeysWithValues: hiraganaChanges.map { (String($0.key), String($0.value).toKatakana()) })
|
||||
static let hiraganaChanges: [[Character]: [Character]] = Dictionary(uniqueKeysWithValues: [
|
||||
|
@ -6,7 +6,7 @@
|
||||
// Copyright © 2020 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
public import Foundation
|
||||
import SwiftUtils
|
||||
|
||||
public struct TemplateData: Codable, Sendable {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Foundation
|
||||
package import Foundation
|
||||
import SwiftUtils
|
||||
import EfficientNGram
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
@_exported import KanaKanjiConverterModule
|
||||
import Foundation
|
||||
@_exported public import KanaKanjiConverterModule
|
||||
public import Foundation
|
||||
|
||||
public extension ConvertRequestOptions {
|
||||
static func withDefaultDictionary(
|
||||
|
@ -5,15 +5,15 @@
|
||||
// Created by ensan on 2023/04/30.
|
||||
//
|
||||
|
||||
import Algorithms
|
||||
package import Algorithms
|
||||
import Foundation
|
||||
|
||||
public extension Sequence {
|
||||
package extension Sequence {
|
||||
/// Returns a sequence that contains the elements of this sequence followed by the elements of the given sequence.
|
||||
/// - Parameters:
|
||||
/// - sequence: A sequence of elements to chain.
|
||||
/// - Returns: A sequence that contains the elements of this sequence followed by the elements of the given sequence.
|
||||
@inlinable func chained<S: Sequence<Element>>(_ sequence: S) -> Chain2Sequence<Self, S> {
|
||||
func chained<S: Sequence<Element>>(_ sequence: S) -> Chain2Sequence<Self, S> {
|
||||
chain(self, sequence)
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,7 @@ public extension MutableCollection {
|
||||
/// Calls the given closure with a pointer to the array's mutable contiguous storage.
|
||||
/// - Parameter
|
||||
/// - transform: A closure that takes a pointer to the array's mutable contiguous storage.
|
||||
@inlinable mutating func mutatingForeach(transform closure: (inout Element) throws -> Void) rethrows {
|
||||
@inlinable mutating func mutatingForEach(transform closure: (inout Element) throws -> Void) rethrows {
|
||||
for index in self.indices {
|
||||
try closure(&self[index])
|
||||
}
|
||||
|
@ -6,14 +6,14 @@
|
||||
// Copyright © 2022 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
package import Foundation
|
||||
|
||||
extension Data {
|
||||
package extension Data {
|
||||
/// Converts this data to an array of the given type.
|
||||
/// - Parameter:
|
||||
/// - type: The type to convert this data to.
|
||||
/// - Returns: An array of the given type.
|
||||
@inlinable public func toArray<T>(of type: T.Type) -> [T] {
|
||||
func toArray<T>(of type: T.Type) -> [T] {
|
||||
self.withUnsafeBytes {pointer -> [T] in
|
||||
Array(
|
||||
UnsafeBufferPointer(
|
||||
|
@ -6,26 +6,26 @@
|
||||
// Copyright © 2020 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
public import Foundation
|
||||
|
||||
public extension StringProtocol {
|
||||
extension StringProtocol {
|
||||
/// ローマ字と数字のみかどうか
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
@inlinable
|
||||
var onlyRomanAlphabetOrNumber: Bool {
|
||||
package var onlyRomanAlphabetOrNumber: Bool {
|
||||
!isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil
|
||||
}
|
||||
/// ローマ字のみかどうか
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
@inlinable
|
||||
var onlyRomanAlphabet: Bool {
|
||||
package var onlyRomanAlphabet: Bool {
|
||||
!isEmpty && range(of: "[^a-zA-Z]", options: .regularExpression) == nil
|
||||
}
|
||||
/// ローマ字を含むかどうか
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
/// 以前は正規表現ベースで実装していたが、パフォーマンス上良くなかったので以下のような実装にしたところ40倍程度高速化した。
|
||||
@inlinable
|
||||
var containsRomanAlphabet: Bool {
|
||||
package var containsRomanAlphabet: Bool {
|
||||
for value in self.utf8 {
|
||||
if (UInt8(ascii: "a") <= value && value <= UInt8(ascii: "z")) || (UInt8(ascii: "A") <= value && value <= UInt8(ascii: "Z")) {
|
||||
return true
|
||||
@ -36,19 +36,20 @@ public extension StringProtocol {
|
||||
/// 英語として許容可能な文字のみで構成されているか。
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
@inlinable
|
||||
var isEnglishSentence: Bool {
|
||||
public var isEnglishSentence: Bool {
|
||||
!isEmpty && range(of: "[^0-9a-zA-Z\n !'_<>\\[\\]{}*@`\\^|~=\"#$%&\\+\\(\\),\\-\\./:;?’\\\\]", options: .regularExpression) == nil
|
||||
}
|
||||
|
||||
/// 仮名か
|
||||
@inlinable
|
||||
var isKana: Bool {
|
||||
public var isKana: Bool {
|
||||
!isEmpty && range(of: "[^ぁ-ゖァ-ヶ]", options: .regularExpression) == nil
|
||||
}
|
||||
|
||||
/// Returns a String value in which Hiraganas are all converted to Katakana.
|
||||
/// - Returns: A String value in which Hiraganas are all converted to Katakana.
|
||||
@inlinable func toKatakana() -> String {
|
||||
@inlinable
|
||||
public func toKatakana() -> String {
|
||||
// カタカナはutf16で常に2バイトなので、utf16単位で処理して良い
|
||||
let result = self.utf16.map { scalar -> UInt16 in
|
||||
if 0x3041 <= scalar && scalar <= 0x3096 {
|
||||
@ -62,7 +63,8 @@ public extension StringProtocol {
|
||||
|
||||
/// Returns a String value in which Katakana are all converted to Hiragana.
|
||||
/// - Returns: A String value in which Katakana are all converted to Hiragana.
|
||||
@inlinable func toHiragana() -> String {
|
||||
@inlinable
|
||||
public func toHiragana() -> String {
|
||||
// ひらがなはutf16で常に2バイトなので、utf16単位で処理して良い
|
||||
let result = self.utf16.map { scalar -> UInt16 in
|
||||
if 0x30A1 <= scalar && scalar <= 0x30F6 {
|
||||
@ -85,7 +87,7 @@ public extension StringProtocol {
|
||||
" -> \d
|
||||
*/
|
||||
// please use these letters in order to avoid user-inputting text crash
|
||||
func templateDataSpecificEscaped() -> String {
|
||||
package func templateDataSpecificEscaped() -> String {
|
||||
var result = self.replacingOccurrences(of: "\\", with: "\\b")
|
||||
result = result.replacingOccurrences(of: "\0", with: "\\0")
|
||||
result = result.replacingOccurrences(of: "\n", with: "\\n")
|
||||
@ -96,7 +98,7 @@ public extension StringProtocol {
|
||||
return result
|
||||
}
|
||||
|
||||
func templateDataSpecificUnescaped() -> String {
|
||||
package func templateDataSpecificUnescaped() -> String {
|
||||
var result = self.replacingOccurrences(of: "\\d", with: "\"")
|
||||
result = result.replacingOccurrences(of: "\\s", with: " ")
|
||||
result = result.replacingOccurrences(of: "\\c", with: ",")
|
||||
|
Reference in New Issue
Block a user