Files
AzooKeyKanaKanjiConverter/Sources/KanaKanjiConverterModule/Converter/ConvertRequestOptions.swift

192 lines
11 KiB
Swift

//
// ConvertRequestOptions.swift
// Keyboard
//
// Created by ensan on 2022/12/20.
// Copyright © 2022 ensan. All rights reserved.
//
import Foundation
public struct ConvertRequestOptions: Sendable {
///
///
/// - parameters:
/// - N_best: `N`
/// - requireJapanesePrediction: `false`
/// - requireEnglishPrediction: `false``false`
/// - keyboardLanguage:
/// - typographyLetterCandidate: `true``KanaKanjiConverter.typographicalCandidates(_:)`
/// - unicodeCandidate: `true``U+xxxx`Unicode`KanaKanjiConverter.unicodeCandidates(_:)``
/// - englishCandidateInRoman2KanaInput: `true``false`
/// - fullWidthRomanCandidate: `true`
/// - halfWidthKanaCandidate: `true`
/// - learningType: `LearningType`
/// - maxMemoryCount: `0``learningType``nothing`
/// - shouldResetMemory: `true`
/// - dictionaryResourceURL:
/// - memoryDirectoryURL:
/// - sharedContainerURL:
/// - textReplacer:
/// - metadata: `ConvertRequestOptions.Metadata`
public init(N_best: Int = 10, requireJapanesePrediction: Bool, requireEnglishPrediction: Bool, keyboardLanguage: KeyboardLanguage, typographyLetterCandidate: Bool = false, unicodeCandidate: Bool = true, englishCandidateInRoman2KanaInput: Bool = false, fullWidthRomanCandidate: Bool = false, halfWidthKanaCandidate: Bool = false, learningType: LearningType, maxMemoryCount: Int = 65536, shouldResetMemory: Bool = false, dictionaryResourceURL: URL, memoryDirectoryURL: URL, sharedContainerURL: URL, textReplacer: TextReplacer = TextReplacer(), zenzaiMode: ZenzaiMode = .off, metadata: ConvertRequestOptions.Metadata?) {
self.N_best = N_best
self.requireJapanesePrediction = requireJapanesePrediction
self.requireEnglishPrediction = requireEnglishPrediction
self.keyboardLanguage = keyboardLanguage
self.typographyLetterCandidate = typographyLetterCandidate
self.unicodeCandidate = unicodeCandidate
self.englishCandidateInRoman2KanaInput = englishCandidateInRoman2KanaInput
self.fullWidthRomanCandidate = fullWidthRomanCandidate
self.halfWidthKanaCandidate = halfWidthKanaCandidate
self.learningType = learningType
self.maxMemoryCount = maxMemoryCount
self.shouldResetMemory = shouldResetMemory
self.memoryDirectoryURL = memoryDirectoryURL
self.sharedContainerURL = sharedContainerURL
self.metadata = metadata
self.textReplacer = textReplacer
self.zenzaiMode = zenzaiMode
self.dictionaryResourceURL = dictionaryResourceURL
}
package init(N_best: Int = 10, requireJapanesePrediction: Bool, requireEnglishPrediction: Bool, keyboardLanguage: KeyboardLanguage, typographyLetterCandidate: Bool = false, unicodeCandidate: Bool = true, englishCandidateInRoman2KanaInput: Bool = false, fullWidthRomanCandidate: Bool = false, halfWidthKanaCandidate: Bool = false, learningType: LearningType, maxMemoryCount: Int = 65536, shouldResetMemory: Bool = false, dictionaryResourceURL: URL, memoryDirectoryURL: URL, sharedContainerURL: URL, textReplacer: TextReplacer = TextReplacer(), zenzaiMode: ZenzaiMode = .off, metadata: ConvertRequestOptions.Metadata?, requestQuery: RequestQuery) {
self.N_best = N_best
self.requireJapanesePrediction = requireJapanesePrediction
self.requireEnglishPrediction = requireEnglishPrediction
self.keyboardLanguage = keyboardLanguage
self.typographyLetterCandidate = typographyLetterCandidate
self.unicodeCandidate = unicodeCandidate
self.englishCandidateInRoman2KanaInput = englishCandidateInRoman2KanaInput
self.fullWidthRomanCandidate = fullWidthRomanCandidate
self.halfWidthKanaCandidate = halfWidthKanaCandidate
self.learningType = learningType
self.maxMemoryCount = maxMemoryCount
self.shouldResetMemory = shouldResetMemory
self.memoryDirectoryURL = memoryDirectoryURL
self.sharedContainerURL = sharedContainerURL
self.metadata = metadata
self.textReplacer = textReplacer
self.zenzaiMode = zenzaiMode
self.dictionaryResourceURL = dictionaryResourceURL
}
public var N_best: Int
public var requireJapanesePrediction: Bool
public var requireEnglishPrediction: Bool
public var keyboardLanguage: KeyboardLanguage
// KeyboardSettinginjection
public var typographyLetterCandidate: Bool
public var unicodeCandidate: Bool
public var englishCandidateInRoman2KanaInput: Bool
public var fullWidthRomanCandidate: Bool
public var halfWidthKanaCandidate: Bool
public var learningType: LearningType
public var maxMemoryCount: Int
public var shouldResetMemory: Bool
///
public var textReplacer: TextReplacer
//
public var memoryDirectoryURL: URL
public var sharedContainerURL: URL
public var dictionaryResourceURL: URL
public var zenzaiMode: ZenzaiMode
//
public var metadata: Metadata?
// MARK: API
package var requestQuery: RequestQuery = .default
static var `default`: Self {
Self(
N_best: 10,
requireJapanesePrediction: true,
requireEnglishPrediction: true,
keyboardLanguage: .ja_JP,
typographyLetterCandidate: false,
unicodeCandidate: true,
englishCandidateInRoman2KanaInput: true,
fullWidthRomanCandidate: true,
halfWidthKanaCandidate: false,
learningType: .inputAndOutput,
maxMemoryCount: 65536,
shouldResetMemory: false,
// dummy data, won't work
dictionaryResourceURL: Bundle.main.bundleURL,
// dummy data, won't work
memoryDirectoryURL: (try? FileManager.default.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false)) ?? Bundle.main.bundleURL,
// dummy data, won't work
sharedContainerURL: Bundle.main.bundleURL,
metadata: nil
)
}
public struct Metadata: Sendable {
/// - parameters:
/// - appVersionString: `KanaKanjiCovnerter.toVersionCandidate(_:)`
@available(*, deprecated, renamed: "init(versionString:)", message: "it be removed in AzooKeyKanaKanjiConverter v1.0")
public init(appVersionString: String) {
self.versionString = "azooKey Version " + appVersionString
}
/// - parameters:
/// - versionString: `"MyIME Version 0.7.1"``KanaKanjiCovnerter.toVersionCandidate(_:)`
public init(versionString: String = "Powererd by AzooKeyKanaKanjiConverter") {
self.versionString = versionString
}
var versionString: String
}
package enum RequestQuery: Sendable {
case `default`
case
}
public struct ZenzaiV2DependentMode: Sendable, Equatable, Hashable {
public init(profile: String? = nil, leftSideContext: String? = nil) {
self.profile = profile
self.leftSideContext = leftSideContext
}
/// 1020
public var profile: String?
///
public var leftSideContext: String?
}
public enum ZenzVersion: Sendable, Equatable, Hashable {
case v1
case v2
}
public enum ZenzaiVersionDependentMode: Sendable, Equatable, Hashable {
case v1
case v2(ZenzaiV2DependentMode)
public var version: ZenzVersion {
switch self {
case .v1:
return .v1
case .v2(_):
return .v2
}
}
}
public struct ZenzaiMode: Sendable, Equatable {
public static let off = ZenzaiMode(enabled: false, weightURL: URL(fileURLWithPath: ""), inferenceLimit: 10, versionDependentMode: .v2(.init()))
/// activate *Zenzai* - Neural Kana-Kanji Conversiion Engine
/// - Parameters:
/// - weight: path for model weight (gguf)
/// - inferenceLimit: applying inference count limitation. Smaller limit makes conversion faster but quality will be worse. (Default: 10)
public static func on(weight: URL, inferenceLimit: Int = 10, versionDependentMode: ZenzaiVersionDependentMode = .v2(.init())) -> Self {
ZenzaiMode(enabled: true, weightURL: weight, inferenceLimit: inferenceLimit, versionDependentMode: versionDependentMode)
}
var enabled: Bool
var weightURL: URL
var inferenceLimit: Int
var versionDependentMode: ZenzaiVersionDependentMode
}
}