feat: MetadataのAPIをより柔軟にした (#89)

This commit is contained in:
Miwa / Ensan
2024-05-04 11:56:09 +09:00
committed by GitHub
parent c211bc36cd
commit 861ac7a026
11 changed files with 24 additions and 19 deletions

View File

@ -70,7 +70,7 @@ let options = ConvertRequestOptions.withDefaultDictionary(
// ユーザ辞書データのあるディレクトリのURL書類フォルダを指定
sharedContainerURL: .documentsDirectory,
// メタデータ
metadata: .init(appVersionString: "Version X")
metadata: .init(versionString: "You App Version X")
)
```
@ -131,7 +131,7 @@ let options = ConvertRequestOptions(
// ユーザ辞書データのあるディレクトリのURL書類フォルダを指定
sharedContainerURL: .documentsDirectory,
// メタデータ
metadata: .init(appVersionString: "Version X")
metadata: .init(versionString: "You App Version X")
)
```

View File

@ -116,7 +116,7 @@ extension Subcommands.Dict {
dictionaryResourceURL: URL(fileURLWithPath: self.dictionaryDirectory),
memoryDirectoryURL: URL(fileURLWithPath: self.dictionaryDirectory),
sharedContainerURL: URL(fileURLWithPath: self.dictionaryDirectory),
metadata: .init(appVersionString: "anco")
metadata: .init(versionString: "anco for debugging")
)
}
}

View File

@ -65,7 +65,7 @@ extension Subcommands {
shouldResetMemory: false,
memoryDirectoryURL: URL(fileURLWithPath: ""),
sharedContainerURL: URL(fileURLWithPath: ""),
metadata: .init(appVersionString: "anco")
metadata: .init(versionString: "anco for debugging")
)
if self.onlyWholeConversion {
option.requestQuery = .

View File

@ -29,7 +29,7 @@ public struct ConvertRequestOptions: Sendable {
/// - 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(), 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(), metadata: ConvertRequestOptions.Metadata?) {
self.N_best = N_best
self.requireJapanesePrediction = requireJapanesePrediction
self.requireEnglishPrediction = requireEnglishPrediction
@ -49,7 +49,7 @@ public struct ConvertRequestOptions: Sendable {
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(), metadata: ConvertRequestOptions.Metadata, requestQuery: RequestQuery) {
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(), metadata: ConvertRequestOptions.Metadata?, requestQuery: RequestQuery) {
self.N_best = N_best
self.requireJapanesePrediction = requireJapanesePrediction
self.requireEnglishPrediction = requireEnglishPrediction
@ -89,7 +89,7 @@ public struct ConvertRequestOptions: Sendable {
public var sharedContainerURL: URL
public var dictionaryResourceURL: URL
//
public var metadata: Metadata
public var metadata: Metadata?
// MARK: API
package var requestQuery: RequestQuery = .default
@ -114,17 +114,24 @@ public struct ConvertRequestOptions: Sendable {
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: Metadata(appVersionString: "Unknown")
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.appVersionString = appVersionString
self.versionString = "azooKey Version " + appVersionString
}
var appVersionString: String
/// - 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 {

View File

@ -15,9 +15,7 @@ extension KanaKanjiConverter {
/// - parameters:
/// - inputData:
func toVersionCandidate(_ inputData: ComposingText, options: ConvertRequestOptions) -> [Candidate] {
if inputData.convertTarget.toKatakana() == "バージョン" {
let versionString = "azooKey Version \(options.metadata.appVersionString)"
if inputData.convertTarget.toKatakana() == "バージョン", let versionString = options.metadata?.versionString {
return [Candidate(
text: versionString,
value: -30,

View File

@ -18,7 +18,7 @@ public extension ConvertRequestOptions {
memoryDirectoryURL: URL,
sharedContainerURL: URL,
textReplacer: TextReplacer = TextReplacer(),
metadata: ConvertRequestOptions.Metadata
metadata: ConvertRequestOptions.Metadata?
) -> Self {
#if os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
let dictionaryDirectory = Bundle.module.bundleURL.appendingPathComponent("Dictionary", isDirectory: true)

View File

@ -26,7 +26,7 @@ final class ConverterTests: XCTestCase {
dictionaryResourceURL: Bundle(for: type(of: self)).bundleURL.appendingPathComponent("DictionaryMock", isDirectory: true),
memoryDirectoryURL: URL(fileURLWithPath: ""),
sharedContainerURL: URL(fileURLWithPath: ""),
metadata: .init(appVersionString: "Tests")
metadata: nil
)
}

View File

@ -33,7 +33,7 @@ final class ConverterTests: XCTestCase {
shouldResetMemory: false,
memoryDirectoryURL: URL(fileURLWithPath: ""),
sharedContainerURL: URL(fileURLWithPath: ""),
metadata: .init(appVersionString: "Tests")
metadata: nil
)
}

View File

@ -32,7 +32,7 @@ final class DicdataStoreTests: XCTestCase {
shouldResetMemory: false,
memoryDirectoryURL: URL(fileURLWithPath: ""),
sharedContainerURL: URL(fileURLWithPath: ""),
metadata: .init(appVersionString: "Tests")
metadata: nil
)
}

View File

@ -11,7 +11,7 @@ import Foundation
final class LookupGraphTests: XCTestCase {
func requestOptions() -> ConvertRequestOptions {
.withDefaultDictionary(requireJapanesePrediction: false, requireEnglishPrediction: false, keyboardLanguage: .ja_JP, learningType: .nothing, memoryDirectoryURL: URL(fileURLWithPath: ""), sharedContainerURL: URL(fileURLWithPath: ""), metadata: .init(appVersionString: "Test"))
.withDefaultDictionary(requireJapanesePrediction: false, requireEnglishPrediction: false, keyboardLanguage: .ja_JP, learningType: .nothing, memoryDirectoryURL: URL(fileURLWithPath: ""), sharedContainerURL: URL(fileURLWithPath: ""), metadata: nil)
}
func setup() -> (dicdataStore: DicdataStore, character2CharId: (Character) -> UInt8) {

View File

@ -90,7 +90,7 @@ private extension ConvertGraph.LatticeNode {
final class ExperimentalConversionTests: XCTestCase {
func requestOptions() -> ConvertRequestOptions {
.withDefaultDictionary(requireJapanesePrediction: false, requireEnglishPrediction: false, keyboardLanguage: .ja_JP, learningType: .nothing, memoryDirectoryURL: URL(fileURLWithPath: ""), sharedContainerURL: URL(fileURLWithPath: ""), metadata: .init(appVersionString: "Test"))
.withDefaultDictionary(requireJapanesePrediction: false, requireEnglishPrediction: false, keyboardLanguage: .ja_JP, learningType: .nothing, memoryDirectoryURL: URL(fileURLWithPath: ""), sharedContainerURL: URL(fileURLWithPath: ""), metadata: nil)
}
func testBuildConvertGraph_たいかく() throws {